Need a refresher on presentation and HA



  • Hi,

    I took a bit of a hiatus from this site/Arduino and now can't for the life of me debug a presentation on a node with two LED lights.

    Here is the errors I am getting during presentation:

    Starting repeater (RNNRA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=24)
    TSM:FPAR
    TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 4-4-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    TSP:MSG:FPAR RES (ID=4, dist=1)
    TSP:MSG:PAR OK (ID=4, dist=2)
    TSP:MSG:READ 0-0-24 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSP:MSG:READ 2-2-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    TSP:MSG:FPAR RES (ID=2, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=24)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 24-24-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-24 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:READ 0-0-24 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Holiday Desk Light
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
    TSP:MSG:SEND 24-24-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    !TSP:MSG:SEND 24-24-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=fail:
    NODE:!REG
    NODE:!REG
    Request registration...
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=ok:2
    TSP:MSG:READ 0-0-24 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=24, parent=0, distance=1, registration=1
    

    and here is my sketch

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Example sketch showing how to control physical relays. 
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */ 
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define LIGHTS_MULTI 3
    #define LIGHTS_WHITE 5
    
    #define CHILD_ID_MULTI 1
    #define CHILD_ID_WHITE 2
    
    #define LIGHTS_MULTI_ON 1  // GPIO value to write to turn on attached relay
    #define LIGHTS_MULTI_OFF 0 // GPIO value to write to turn off attached relay
    
    #define LIGHTS_WHITE_ON 1  // GPIO value to write to turn on attached relay
    #define LIGHTS_WHITE_OFF 0 // GPIO value to write to turn off attached relay
    
    MyMessage msgMULTI(CHILD_ID_MULTI, V_LIGHT);
    MyMessage msgWHITE(CHILD_ID_WHITE, V_LIGHT);
    
    void before() { 
         // Then set relay pins in output mode
        pinMode(LIGHTS_MULTI, OUTPUT);   
        pinMode(LIGHTS_WHITE, OUTPUT);  
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(LIGHTS_MULTI, loadState(1)?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF);
        digitalWrite(LIGHTS_WHITE, loadState(2)?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF);
      }
    
    
    void setup() {
    // present(255, 18);
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Holiday Desk Light", "1.0");
    
          present(CHILD_ID_MULTI, S_LIGHT);
          present(CHILD_ID_WHITE, S_LIGHT);
          send(msgMULTI.set(1));
          send(msgWHITE.set(1));
          
      }
     
    void loop() 
    {
      
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT && message.sensor == CHILD_ID_MULTI) {
         // Change relay state
         digitalWrite(LIGHTS_MULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    
         if (message.type==V_LIGHT && message.sensor == CHILD_ID_WHITE) {
         // Change relay state
         digitalWrite(LIGHTS_WHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       }
    }
    

    Anyone help a born-again newb? :{

    Thanks


  • Plugin Developer

    • Add a short wait between presentations of child 1 and 2 in presentation. Presentation of second child failed to be received.
    • Send initial values for both children in loop.
    • Send feedback of state change to gateway/controller in receive.


  • hi @martinhjelmare

    I added a wait into the presentation, and that got rid of the fail message. Now I am trying to send the initial value (so that HA will register it) and it does not seem to be working. I also added the sending of the status in the receive message, here is an updated sketch and my debug log. What could I be missing?

    Thanks again!

    Starting repeater (RNNRA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=24)
    TSM:FPAR
    TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 4-4-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    TSP:MSG:FPAR RES (ID=4, dist=1)
    TSP:MSG:PAR OK (ID=4, dist=2)
    TSP:MSG:READ 0-0-24 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSP:MSG:READ 2-2-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    TSP:MSG:FPAR RES (ID=2, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=24)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 24-24-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-24 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:READ 0-0-24 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Holiday Desk Light
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
    TSP:MSG:SEND 24-24-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 24-24-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    NODE:!REG
    NODE:!REG
    Request registration...
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-24 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=24, parent=0, distance=1, registration=1
    TSP:SANCHK:OK
    TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    TSP:MSG:BC
    TSP:MSG:FPAR REQ (sender=1)
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSP:MSG:GWL OK
    TSP:MSG:SEND 24-24-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:SANCHK:OK
    

    sketch

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Example sketch showing how to control physical relays. 
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */ 
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define LIGHTS_MULTI 3
    #define LIGHTS_WHITE 5
    
    #define CHILD_ID_MULTI 1
    #define CHILD_ID_WHITE 2
    
    #define LIGHTS_MULTI_ON 1  // GPIO value to write to turn on attached relay
    #define LIGHTS_MULTI_OFF 0 // GPIO value to write to turn off attached relay
    
    #define LIGHTS_WHITE_ON 1  // GPIO value to write to turn on attached relay
    #define LIGHTS_WHITE_OFF 0 // GPIO value to write to turn off attached relay
    
    MyMessage msgMULTI(CHILD_ID_MULTI, V_LIGHT);
    MyMessage msgWHITE(CHILD_ID_WHITE, V_LIGHT);
    
    void before() { 
         // Then set relay pins in output mode
        pinMode(LIGHTS_MULTI, OUTPUT);   
        pinMode(LIGHTS_WHITE, OUTPUT);  
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(LIGHTS_MULTI, loadState(CHILD_ID_MULTI)?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF);
        digitalWrite(LIGHTS_WHITE, loadState(CHILD_ID_WHITE)?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF);
      }
    
    
    void setup() {
    // present(255, 18);
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Holiday Desk Light", "1.0");
    
          present(CHILD_ID_MULTI, S_LIGHT);
          wait(150);
          present(CHILD_ID_WHITE, S_LIGHT);
          wait(150);
          send(msgMULTI.set(1));
          wait(150);
          send(msgWHITE.set(1));  
      }
     
    void loop() 
    {
      
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT && message.sensor == CHILD_ID_MULTI) {
         // Change relay state
         digitalWrite(LIGHTS_MULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF);
         send(msgMULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    
         if (message.type==V_LIGHT && message.sensor == CHILD_ID_WHITE) {
         // Change relay state
         digitalWrite(LIGHTS_WHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF);
         send(msgWHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       }
    }
    

  • Plugin Developer

    Send initial values in loop. No set/req messages are allowed until after the node is registered at the gateway. This happens after presentation in mysensors 2.0.

    See example sketch here:
    https://home-assistant.io/components/mysensors/#presentation



  • @martinhjelmare

    Thanks, i finally got it. I went to the example you have on home-assistant.io and removed the button and added a second actuator. Works like it should now. You are the king!

    Final code for anyone whom it may help/want it.

    /*
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * http://www.mysensors.org/build/relay
     * 
     * 
     *Holiday LED Lights MySensors Module, for MySensors v2.0 
     * Nothing fancy, just a two actuator (on/off) virtual switch for small
     * low powred LED strings that normally run from a battery pack. 
     * 
     * 
      */
      
      
    
    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 24 // or comment out for auto
    #include <SPI.h>
    #include <MySensors.h>
    
    #define MULTI_PIN  3 // Pin that Multi-Coloured LED string is connected to
    #define WHITE_PIN 5  // Pin that White LED string is connected to
    #define CHILD_ID_MULTI 1 // Child ID for Multi-Coloured LED String
    #define CHILD_ID_WHITE 2 // Child ID for White LED String
    #define MULTI_ON 1
    #define MULTI_OFF 0
    #define WHITE_ON 1
    #define WHITE_OFF 0
    
    
    bool stateMULTI = false; // Place holders for the loop function to register nodes in Home-Assistant
    bool initialValueSentMULTI = false;
    bool stateWHITE = false;
    bool initialValueSentWHITE = false;
    
    MyMessage msgMULTI(CHILD_ID_MULTI, V_STATUS); //Presentation of Switch for Multi-Coloured LEDS
    MyMessage msgWHITE(CHILD_ID_WHITE, V_STATUS); //Presentation of Switch for White LEDS
    
    void setup()
    {
      // Make sure relays are off when starting up
      digitalWrite(MULTI_PIN, MULTI_OFF);
      pinMode(MULTI_PIN, OUTPUT);
      digitalWrite(WHITE_PIN, WHITE_OFF);
      pinMode(WHITE_PIN, OUTPUT);
    }
    
    void presentation()  {
      sendSketchInfo("HolidayDeskLights", "1.0");
      present(CHILD_ID_MULTI, S_LIGHT);
      present(CHILD_ID_WHITE, S_LIGHT);
    }
    
    void loop()
    {
      if (!initialValueSentMULTI) {
        Serial.println("Sending initial value");
        send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF));
        Serial.println("Requesting initial value from controller");
        request(CHILD_ID_MULTI, V_STATUS);
        wait(2000, C_SET, V_STATUS);
      }
    
        if (!initialValueSentWHITE) {
        Serial.println("Sending initial value");
        send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF));
        Serial.println("Requesting initial value from controller");
        request(CHILD_ID_WHITE, V_STATUS);
        wait(2000, C_SET, V_STATUS);
      }
    
    }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_STATUS && message.sensor == CHILD_ID_MULTI) {
        if (!initialValueSentMULTI) {
          Serial.println("Receiving initial value from controller");
          initialValueSentMULTI = true;
        }
        // Change relay state
        stateMULTI = (bool)message.getInt();
        digitalWrite(MULTI_PIN, stateMULTI?MULTI_ON:MULTI_OFF);
        send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF));
      }
    
      if (message.type == V_STATUS && message.sensor == CHILD_ID_WHITE) {
        if (!initialValueSentWHITE) {
          Serial.println("Receiving initial value from controller");
          initialValueSentWHITE = true;
        }
        // Change relay state
        stateWHITE = (bool)message.getInt();
        digitalWrite(WHITE_PIN, stateWHITE?WHITE_ON:WHITE_OFF);
        send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF));
      }
      
    }
    

Log in to reply
 

Suggested Topics

  • 1
  • 8
  • 3
  • 1
  • 2
  • 3

63
Online

11.4k
Users

11.1k
Topics

112.7k
Posts