Cannot connect mysensors to Home Assistant



  • Edit 2017-10-06: Issue solved!
    @martinhjelmare said in Cannot connect mysensors to Home Assistant:

    @SquareKinematics

    Your mysensors home assistant config is missing the value for the device key. In your case it should be mqtt.

    I've set everything up to test a simple switch and read the state in home assistant, it seems like everything is working except for home assistant, home assistant seemingly ignores the MQTT messages and does not show any mysensors entities.

    This is my setup:

    Switch→Arduino Nano→RFM69→RFM69→RaspberryPi→MQTT→MQTT broker→home assistant

    The raspberry pi is only running the mysensors gateway, the MQTT broker and home assistant are running on a server.

    From what I can tell there is an issue between the MQTT broker and home assistant because everything else works up to that point. Home Assistant simply does not display any my sensors entities, it is as if it is ignoring the MQTT messages. Any advice to get the mysensors entities showing would be much appreciated. Configuration and debug follows.

    This is the arduino code, using the 2.2 mysensors library, and arduino IDE 1.8.3

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_RFM69
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_FREQUENCY RFM69_915MHZ 
    #define MY_IS_RFM69HW
    #define MY_NODE_ID 10
    
    #define MY_RFM69_NETWORKID 100
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    
    }
    
    void presentation() {
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      sendSketchInfo("testing", "2.0");
      present(CHILD_ID, S_DOOR);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
    }
    

    These are my pi configuration options, also running version 2.2

    sudo ./configure --my-mqtt-client-id=rfm --my-mqtt-user=hass --my-mqtt-password=notarealpassword --my-mqtt-publish-topic-prefix=rfm-out --my-mqtt-subscribe-topic-prefix=rfm-in --my-transport=rfm69 --my-rfm69-frequency=915 --my-controller-ip-address=192.168.0.20 --my-gateway=mqtt --my-port=1883
    

    This is my home assistant configuration

    mysensors:
      gateways:
        - device:
          persistence_file: '/home/hass/.homeassistant/mysensors.json'
          topic_in_prefix: 'rfm-out'
          topic_out_prefix: 'rfm-in'
      optimistic: false
      persistence: true
      retain: true
      version: '2.0'
    mqtt:
      broker: 192.168.0.20
      port: 1883
      client_id: home-assistant-1
      keepalive: 60
      username: hass
      password: !secret mqtt_password
    

    Sample arduino serial monitor output

     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.2.0-beta
    
    17 MCO:BGN:INIT NODE,CP=RPNNA---,VER=2.2.0-beta
    26 TSM:INIT
    27 TSF:WUR:MS=0
    29 TSM:INIT:TSP OK
    31 TSM:INIT:STATID=10
    33 TSF:SID:OK,ID=10
    34 TSM:FPAR
    39 TSF:MSG:SEND,10-10-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    784 TSF:MSG:READ,0-0-10,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    789 TSF:MSG:FPAR OK,ID=0,D=1
    2048 TSM:FPAR:OK
    2049 TSM:ID
    2050 TSM:ID:OK
    2052 TSM:UPL
    2060 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2069 TSF:MSG:READ,0-0-10,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2074 TSF:MSG:PONG RECV,HP=1
    2076 TSM:UPL:OK
    2078 TSM:READY:ID=10,PAR=0,DIS=1
    2092 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2101 TSF:MSG:READ,0-0-10,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2114 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=17,pt=0,l=10,sg=0,ft=0,st=OK:2.2.0-beta
    2138 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    4160 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=11,pt=0,l=7,sg=0,ft=0,st=OK:testing
    4184 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
    4197 TSF:MSG:SEND,10-10-0-0,s=3,c=0,t=0,pt=0,l=0,sg=0,ft=0,st=OK:
    4203 MCO:REG:REQ
    4220 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    4230 TSF:MSG:READ,0-0-10,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    4235 MCO:PIM:NODE REG=1
    4237 MCO:BGN:STP
    4238 MCO:BGN:INIT OK,TSP=1
    4252 TSF:MSG:SEND,10-10-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    10210 TSF:MSG:SEND,10-10-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    10233 TSF:MSG:SEND,10-10-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    

    Sample gateway debug

    mysgw: Starting gateway...
    mysgw: Protocol version - 2.2.0-beta
    mysgw: MCO:BGN:INIT GW,CP=RPNGL---,VER=2.2.0-beta
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    mysgw: Attempting MQTT connection...
    mysgw: connected to 192.168.0.20
    mysgw: MQTT connected
    mysgw: Sending message on topic: rfm-out/0/255/0/0/18
    mysgw: TSF:MSG:READ,10-10-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    mysgw: TSF:MSG:BC
    mysgw: TSF:MSG:FPAR REQ,ID=10
    mysgw: TSF:PNG:SEND,TO=0
    mysgw: TSF:CKU:OK
    mysgw: TSF:MSG:GWL OK
    mysgw: TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    mysgw: TSF:MSG:PINGED,ID=10,HP=1
    mysgw: TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    mysgw: TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=0,t=17,pt=0,l=10,sg=0:2.2.0-beta
    mysgw: Sending message on topic: rfm-out/10/255/0/0/17
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
    mysgw: Sending message on topic: rfm-out/10/255/3/0/6
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=11,pt=0,l=7,sg=0:testing
    mysgw: Sending message on topic: rfm-out/10/255/3/0/11
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=12,pt=0,l=3,sg=0:2.0
    mysgw: Sending message on topic: rfm-out/10/255/3/0/12
    mysgw: TSF:MSG:READ,10-10-0,s=3,c=0,t=0,pt=0,l=0,sg=0:
    mysgw: Sending message on topic: rfm-out/10/3/0/0/0
    mysgw: TSF:MSG:READ,10-10-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    mysgw: TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    mysgw: TSF:MSG:READ,10-10-0,s=3,c=1,t=16,pt=2,l=2,sg=0:1
    mysgw: Sending message on topic: rfm-out/10/3/1/0/16
    mysgw: TSF:MSG:READ,10-10-0,s=3,c=1,t=16,pt=2,l=2,sg=0:0
    mysgw: Sending message on topic: rfm-out/10/3/1/0/16
    mysgw: TSF:MSG:READ,10-10-0,s=3,c=1,t=16,pt=2,l=2,sg=0:0
    mysgw: Sending message on topic: rfm-out/10/3/1/0/16
    mysgw: TSF:MSG:READ,10-10-0,s=3,c=1,t=16,pt=2,l=2,sg=0:1
    mysgw: Sending message on topic: rfm-out/10/3/1/0/16
    

    Sample MQTT monitoring (when switch is toggled)

    Client mosqsub/22910-E31230v5 sending CONNECT
    Client mosqsub/22910-E31230v5 received CONNACK
    Client mosqsub/22910-E31230v5 sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
    Client mosqsub/22910-E31230v5 received SUBACK
    Subscribed (mid: 1): 0
    Client mosqsub/22910-E31230v5 received PUBLISH (d0, q0, r0, m0, 'rfm-out/10/3/1/0/16', ... (1 bytes))
    rfm-out/10/3/1/0/16 0
    Client mosqsub/22910-E31230v5 received PUBLISH (d0, q0, r0, m0, 'rfm-out/10/3/1/0/16', ... (1 bytes))
    rfm-out/10/3/1/0/16 0
    Client mosqsub/22910-E31230v5 received PUBLISH (d0, q0, r0, m0, 'rfm-out/10/3/1/0/16', ... (1 bytes))
    rfm-out/10/3/1/0/16 1
    

  • Mod

    My-controller-ip isn't necessary since the gateway only talks to mqtt broker



  • How else will it get the IP of my broker then? That's the only field I put in my server IP hosting home assistant the the MQTT broker.


  • Mod

    As I said, the mqtt broker is the only way they will talk to each other and the only IP they need is the mqtt broker address.



  • The messages are being published to the broker, that part is working. The last bit in my post shows what the broker is sending/receiving.

    Edit: From the manual

        --my-controller-ip-address=<IP> Controller or MQTT broker ip.
    

    In this case it represents my MQTT broker IP. I believe I have the usage correct.


  • Mod

    Sorry about that, I usually put all parameters is myconfig.h file because it's more straightforward



  • @gohan Oh I didn't know I could put them there, I will do that!


  • Mod

    @SquareKinematics if you do that, you'll need to take care every time you update mysensors. Otherwise your settings might be lost.


  • Mod

    I use the file because I can copy it to wherever I need it in order to have every time all my setting the same when I compile :)


  • Plugin Developer

    @SquareKinematics

    Your mysensors home assistant config is missing the value for the device key. In your case it should be mqtt.



  • @martinhjelmare Good eye! I can't believe I missed this. Thank you. This solved my problem.

    I look forward to using this in my home automation setup :)


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.