Ethernet Gateway + Home Assitant



  • So who would have thought this home automation stuff would have such a steel learning curve.
    I've come from absolutely no coding knowledge to be able to get home assistant some what running, and I'm loving it.

    Now I'm trying to add a few sensors around the house.

    I've been reading and trying different things for the last 2 days, but cant seam to figure it out.

    I've got a arduino r3 loaded with the default Ethernet gateway sketch.
    and through the serial monitor it is outputting

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    
    

    Which to my untrained eye seems right.

    The sensor node is a arduino nano and for the moment has a light sensor connected to it.
    with this 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 measue light level using a LM393 photo-resistor
     * http://www.mysensors.org/build/light
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <MySensors.h>
    
    #define CHILD_ID_LIGHT 0
    #define LIGHT_SENSOR_ANALOG_PIN 4
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Light Sensor", "1.0");
    
    	// Register all sensors to gateway (they will be created as child devices)
    	present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
    }
    
    void loop()
    {
    	int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
    	Serial.println(lightLevel);
    	if (lightLevel != lastLightLevel) {
    		send(msg.set(lightLevel));
    		lastLightLevel = lightLevel;
    	}
    	sleep(SLEEP_TIME);
    }
    
    
    

    The output of the serial monitor

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSF:SID:OK,ID=4
    15 TSM:FPAR
    51 TSF:MSG:SEND,4-4-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    819 TSF:MSG:READ,0-0-4,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    824 TSF:MSG:FPAR OK,ID=0,D=1
    2058 TSM:FPAR:OK
    2059 TSM:ID
    2060 TSM:ID:OK
    2062 TSM:UPL
    2065 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2074 TSF:MSG:READ,0-0-4,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2079 TSF:MSG:PONG RECV,HP=1
    2082 TSM:UPL:OK
    2083 TSM:READY:ID=4,PAR=0,DIS=1
    2088 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2095 TSF:MSG:READ,0-0-4,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2103 TSF:MSG:SEND,4-4-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    2111 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    4121 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=11,pt=0,l=12,sg=0,ft=0,st=OK:Light Sensor
    4130 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    4148 TSF:MSG:SEND,4-4-0-0,s=0,c=0,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
    4153 MCO:REG:REQ
    4157 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    6166 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    6173 TSF:MSG:READ,0-0-4,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    6178 MCO:PIM:NODE REG=1
    6180 MCO:BGN:INIT OK,TSP=1
    49
    6184 TSF:MSG:SEND,4-4-0-0,s=0,c=1,t=23,pt=2,l=2,sg=0,ft=0,st=OK:49
    6192 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    6197 MCO:SLP:TPD
    

    Which I dont see anything wrong with.

    So from this point everything seems to be working properly.

    Then I move to home assistant, for the life of me I cannot get anything to show.
    my config.yaml is:

    mysensors:
      gateways:
        - device: '192.168.2.50'
          tcp_port: 5003
    

    and the only out of the ordanry thing in the log is.

    Feb 22 04:33:46 hassbian hass[3097]: 17-02-22 04:33:46 WARNING (Thread-6) [mysensors.mysensors] File does not exist or is not readable: /home/homeassistant/.homeassistant/mysensors1.pickle
    Feb 22 04:33:46 hassbian hass[3097]: 17-02-22 04:33:46 WARNING (Thread-6) [mysensors.mysensors] Trying backup file: /home/homeassistant/.homeassistant/mysensors1.pickle.bak
    Feb 22 04:33:46 hassbian hass[3097]: 17-02-22 04:33:46 WARNING (Thread-6) [mysensors.mysensors] File does not exist or is not readable: /home/homeassistant/.homeassistant/mysensors1.pickle.bak
    Feb 22 04:33:46 hassbian hass[3097]: 17-02-22 04:33:46 WARNING (Thread-6) [mysensors.mysensors] Failed to load sensors from file: /home/homeassistant/.homeassistant/mysensors1.pickle
    

    Which I've read is normal till home assistant discovers a sensor.

    So this leads me to believe my problems have something to do with the persistence..
    which I have no knowledge about, I'm having a stab in the dark and amusing that there is something missing out of my sketch files but I just don't know where to look or what to do.

    Any help or direction would be much appreciate, I'm ripping my hair out and the misses is going to cut my throat if I spend to many more afternoons swearing at the computer.



  • @tubby did you ever find resolution to this? I'm having exact same issue, and its about to drive me nuts haha!!


  • Mod

    Have you guys checked on the HA forum?



  • Just a suspect:
    This may not be related to HA but to the gateway rebooting from time to time.
    The rebooting problem happened with (Serial and Ethernet) Gateway sketches compiled with the arduino IDE and AVR board definition versions from 1.6.12 to 1.6.17(?). Seems this bug is fixed in the latest version (1.6.18+), but in case you still see this behavior downgrading to <=1.6.11 may also be an option. Use the IDE's Board Manager for this.



  • Alright I got this figured out, atleast my version of it. I wanted to document it here incase anyone else runs into Similar.

    I’m using ethernet gateway also(ESP8266) so my first thought was there was something wrong with that, even though it had just been working with Domitcz and OpenHAB days before.

    I connected to the gateway to view the serial output which returned following when being reset:

    dhcp client start...
    ...ip:192.168.1.172,mask:255.255.255.0,gw:192.168.1.1
    .IP: 192.168.1.172
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    

    I was able to ping, so it appeared to be connecting to my network fine.

    I then restarted HomeAssistant and received:

    0;255;3;0;9;Client 0 connected
    

    and when restarting again

    0;255;3;0;9;Client 0 disconnected
    

    So after that It seemed as though my configuration.yaml was correct and HA actually was connecting despite nothing showing up on the GUI.

    I turned my attention to my “Sensor”(window Opener) Node. The sketch I had used had worked just fine for Domoticz and OpenHAB, and I had assumed the gateway would appear in HA like it had in other controllers I’d used.

    Fixed/added a few things from the Sketch and WHALA problems solved.

    Things I fixed/Added using example sketch here as [https://home-assistant.io/components/mysensors/reference](link url):

    • I noticed in void presentation function I was presenting as S_STATUS rather than S_BINARY
      present(CHILD_ID, S_BINARY);

    • Added Following lines to in void loop function send Initial Status to controller

    if (!initialValueSent) { //initialValueSent is Global Variable Defined Above
        Serial.println("Sending initial value");
        send(msg.set(<function to get current state>);
        Serial.println("Requesting initial value from controller");
        request(CHILD_ID, V_STATUS);
        wait(2000, C_SET, V_STATUS);
      }
    
    • added corresponding lines in void receive to change initialValueSent to false. This wasn’t really part of the fix just wanted to note another change I made
    if (!initialValueSent) {
          Serial.println("Receiving initial value from controller");
          initialValueSent = true;
         }
    

    So to sum it up, I believe the main issue was presenting as wrong type, and not sending initial status in my nodes sketch. It wasn’t straight forward to track down since I my gateway/node worked fine in Domoticz and OpenHAB. I also assumed the HA log would show gateway as connected. In the end, I should have just followed/verified the rest of the HA mysensors Instructions ([https://home-assistant.io/components/mysensors/reference](link url)).

    Hopefully this helps anyone else out with same issue. @tubby after reading over your problem again, It looks like you did the presentation and initial send correctly. I wonder if your Gateway is not actually connecting to your network correctly. It seems as though its connected to your sensor.

    Are you able to ping your EthernetGateway?


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts