My first relay. connected to GW 2.1.0



  • My first relay....
    I am about to update my gateway to 2.1.0.
    While i am doing this i want to add a light sensor and a relay to it.
    I know i have a lot to learn about arduino and MySensors and now i am stuck.

    /**
     * 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
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    #define CHILD_ID_LIGHT 0
    #define LIGHT_SENSOR_ANALOG_PIN 4
    #define SN "Ljus Uppe"
    #define SV "1.0"
    
    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    bool initialValueSent = false;
    unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
    
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    void before()
    {
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    
    void setup()
    {
    
         if (!initialValueSent) {
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        MyMessage msg2(sensor, V_STATUS);
        Serial.println("Sending initial value");
        send(msg2.set(0));
        wait(1000);
        }
      initialValueSent = true;
      }
    
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
    
    
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    
    }
    
    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;
      }
      wait(WAIT_TIME);
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_STATUS) {
        // Change relay state
        digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_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());
      }
    }
    
    

    The lightsensor seems to work.
    I can't get the relay working. It is not showing in hass.
    Anyone want to check my sketch and gice me any tips.


  • Plugin Developer

    Hi!

    Your sketch looks ok. I recommend to always feedback state changes though, ie when receiving a message from the controller to change state of a relay also send a message with the new state back to the controller. You can remove the boolean initialValueSent, since you send the initial value in setup, which will only execute once.

    Can you capture a debug log from home assistant?



  • In hass i get this during startup.

    mysensors.mysensors: child_id 0 already exists in children of node 0, cannot add child
    17-01-15 20:48:49 mysensors.mysensors: child_id 1 already exists in children of node 0, cannot add child

    I'm not sure child 1 is in my mysensors.json

    {"0": {"sensor_id": 0, "battery_level": 0, "type": 18, "sketch_name": "Ljus Uppe", "children": {"0": {"values": {"23": "3"}, "type": 16, "id": 0, "description": ""}, "sketch_version": "1.0", "protocol_version": "2.1.0"}
    

    I think this is all for node 0


  • Plugin Developer

    No, it doesn't look like child 1 is in the posted JSON. If you can capture a debug log after start of hass I think it could help to resolve this. Use this logger config and activate debug for mysensors config:

    logger:
      default: info
      logs:
        mysensors: debug
        homeassistant.components.mysensors: debug
    
    mysensors:
      debug: true
    ...
    


  • I do not have access to my GW right now so i haven't removed

    bool initialValueSent = false;
    

    But i guess this won't cause this problem?

    Here is my log after restartof hass

    https://hastebin.com/enutahepac.php

    I can't find anything, but i am a noob 😄


  • Plugin Developer

    I think the problem is that the setup and presentation functions in the gateway sketch have already run before home assistant connects to the gateway. I'll double check the logic flow of the ethernet gateway, to see if this can be the case.

    What you can do is request the value of each child from home assistant and send in the child values in the loop until you get a reply with the value after the request. You'd use the boolean initialValueSent to turn this behavior off.

    There's an example of this logic in the docs for mysensors on home-assistant.io under presentation header.

    https://home-assistant.io/components/mysensors/#presentation



  • Thank you for your answears.
    I will try to modify the sketch when i have the time.
    Can i just add

        request(CHILD_ID, V_STATUS);
        wait(2000, C_SET, V_STATUS);
    

    In the loop?

    Isn't it possible to add a WAIT in the setup?
    My hass is at the moment running on an Raspberry Pi Zero so startup is pretty slow.


  • Plugin Developer

    I've checked the code of the ethernet gateway at mysensors github and presentation will be called whenever a client connects, but setup will not be called again. I don't think you should use setup to send initial values. I don't think the current implementation is designed to do that.

    I suggest you follow the example on how to send initial values and request them, to make sure home assistant has received them, that I linked to.

    Send an initial value.
    Request the same initial value.
    Wait for the corresponding reply from home assistant.

    Do this in the loop within an if statement checking a boolean variable, that you can set to false when you have received all initial values. You check for received messages in the receive function, so that's where you should turn off the boolean. The example has all needed logic.



  • Now i think i did as you said.
    I did some copy, paste and got it working. I hope i did, hadn't had the time to physical add the relay yet but now it's showing i hass and i can change the state..

    /**
     * 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
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    #define CHILD_ID_LIGHT 0
    #define CHILD_ID_RELAY 1
    #define LIGHT_SENSOR_ANALOG_PIN 4
    #define SN "Gateway"
    #define SV "1.0"
    #define RELAY_PIN 3
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    bool state = false;
    bool initialValueSent = false;
    
    unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
    
    MyMessage msg2(CHILD_ID_RELAY, V_STATUS);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    void setup()
    {
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      present(CHILD_ID_RELAY, S_BINARY);
    }
    
    void loop()
    {
    
      if (!initialValueSent) {
    //    Serial.println("Sending initial value");
        send(msg2.set(state?RELAY_ON:RELAY_OFF));
    //    Serial.println("Requesting initial value from controller");
        request(CHILD_ID_RELAY, V_STATUS);
        wait(2000, C_SET, V_STATUS);
        send(msg2.set(state?RELAY_ON:RELAY_OFF), true);
      }  
    
      int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
    //  Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
        send(msg.set(lightLevel));
        lastLightLevel = lightLevel;
      }
      wait(WAIT_TIME);
    }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
    //     Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_STATUS) {
        if (!initialValueSent) {
    //      Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
        // Change relay state
        state = (bool)message.getInt();
        digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
        send(msg2.set(state?RELAY_ON:RELAY_OFF));
      }
    }
    

    Is the sketch OK?
    Anything i could remove or should add?


  • Plugin Developer

    @xydix said in My first relay. connected to GW 2.1.0:

    send(msg2.set(state?RELAY_ON:RELAY_OFF), true);

    You can remove this line in the loop after the call to wait.

    if (message.isAck()) {
    // Serial.println("This is an ack from gateway");
    }

    This is not needed in the receive function either.

    Otherwise the sketch looks good.



  • Hi, again.
    I did the changes you suggested and it seem to work ok when i flip the switch.
    But now i have a strange thing happening.

    I have a MySensors dimmer node (Node 2).
    If i turn on my relay in the GW on.
    And then, i change the state of the dimmer (turn on or off)
    it will turn my relay in the GW off.

    In this log i turn my relay on, turn my dimmer on or off.
    and my relay get turned off.
    I repeat these steps a couple of times.

    17-01-22 23:30:51 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
    17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-11, service=turn_on>
    17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-12, service=turn_on>
    17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-12>
    17-01-22 23:30:51 mysensors.mysensors: Sending 2;0;1;0;2;1
    
    17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-11>
    17-01-22 23:30:53 mysensors.mysensors: Received 2;0;1;0;2;1
    0;1;1;0;2;0
    2;0;1;0;3;100
    
    17-01-22 23:30:53 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>>
    17-01-22 23:30:53 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:30:53 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:53.836521+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:49.700881+01:00>>
    17-01-22 23:30:53 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
    17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:53.919363+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:49.765215+01:00>>
    17-01-22 23:30:54 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:30:54 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:54.040689+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>>
    17-01-22 23:30:54 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:54.126221+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:14.266930+01:00>>
    17-01-22 23:30:57 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=switch.gateway_0_1, service_call_id=3051336336-13, service=turn_on>
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event call_service[L]: domain=switch, service_data=entity_id=['switch.gateway_0_1'], service_call_id=3051336336-14, service=turn_on>
    17-01-22 23:30:57 mysensors.mysensors: Sending 0;1;1;0;2;1
    
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-14>
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-13>
    17-01-22 23:30:57 mysensors.mysensors: Received 0;1;1;0;2;1
    
    17-01-22 23:30:57 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:30:57 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:57.222167+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:53.836521+01:00>>
    17-01-22 23:30:57 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 1
    17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:57.303626+01:00>, old_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:53.919363+01:00>>
    17-01-22 23:30:59 homeassistant.components.http: Serving /api/services/homeassistant/turn_off to 192.168.1.8 (auth: True)
    17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-15, service=turn_off>
    17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-16, service=turn_off>
    17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-16>
    17-01-22 23:30:59 mysensors.mysensors: Sending 2;0;1;0;2;0
    
    17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-15>
    17-01-22 23:31:00 homeassistant.components.device_tracker.netgear: Scanning
    17-01-22 23:31:00 pynetgear: Get attached devices
    17-01-22 23:31:01 mysensors.mysensors: Received 2;0;1;0;2;0
    0;1;1;0;2;0
    2;0;1;0;3;0
    
    17-01-22 23:31:01 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:01 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:54.040689+01:00>>
    17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:02.060892+01:00>, old_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:54.126221+01:00>>
    17-01-22 23:31:02 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:31:02 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:02.205818+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:57.222167+01:00>>
    17-01-22 23:31:02 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
    17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:02.299902+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:57.303626+01:00>>
    17-01-22 23:31:02 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
    17-01-22 23:31:05 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=switch.gateway_0_1, service_call_id=3051336336-17, service=turn_on>
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event call_service[L]: domain=switch, service_data=entity_id=['switch.gateway_0_1'], service_call_id=3051336336-18, service=turn_on>
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-18>
    17-01-22 23:31:05 mysensors.mysensors: Sending 0;1;1;0;2;1
    
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-17>
    17-01-22 23:31:05 mysensors.mysensors: Received 0;1;1;0;2;1
    
    17-01-22 23:31:05 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:31:05 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:05.320905+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:02.205818+01:00>>
    17-01-22 23:31:05 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 1
    17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:05.384134+01:00>, old_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:02.299902+01:00>>
    17-01-22 23:31:07 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-19, service=turn_on>
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-20, service=turn_on>
    17-01-22 23:31:08 mysensors.mysensors: Sending 2;0;1;0;2;1
    
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-20>
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-19>
    17-01-22 23:31:10 mysensors.mysensors: Received 2;0;1;0;2;1
    0;1;1;0;2;0
    2;0;1;0;3;100
    
    17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
    17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:31:10 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.311148+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:05.320905+01:00>>
    17-01-22 23:31:10 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
    17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:10.407123+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:05.384134+01:00>>
    17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.508762+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
    17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:10.570169+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:02.060892+01:00>>
    17-01-22 23:31:12 homeassistant.components.device_tracker.netgear: Scanning
    17-01-22 23:31:12 pynetgear: Get attached devices
    17-01-22 23:31:13 homeassistant.components.http: Serving /api/services/homeassistant/turn_off to 192.168.1.8 (auth: True)
    17-01-22 23:31:13 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-21, service=turn_off>
    17-01-22 23:31:13 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-22, service=turn_off>
    17-01-22 23:31:14 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-22>
    17-01-22 23:31:14 mysensors.mysensors: Sending 2;0;1;0;2;0
    
    17-01-22 23:31:14 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-21>
    17-01-22 23:31:16 mysensors.mysensors: Received 2;0;1;0;2;0
    0;1;1;0;2;0
    2;0;1;0;3;0
    
    17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.508762+01:00>>
    17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:16.236923+01:00>, old_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:10.570169+01:00>>
    17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:31:16 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.321401+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.311148+01:00>>
    17-01-22 23:31:16 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
    17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
    17-01-22 23:31:18 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
    17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-23, service=turn_on>
    17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-24, service=turn_on>
    17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-24>
    17-01-22 23:31:18 mysensors.mysensors: Sending 2;0;1;0;2;1
    
    17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-23>
    17-01-22 23:31:20 mysensors.mysensors: Received 2;0;1;0;2;1
    0;1;1;0;2;0
    2;0;1;0;3;100
    
    17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
    17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 0
    17-01-22 23:31:20 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
    17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:20.335924+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.321401+01:00>>
    17-01-22 23:31:20 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
    17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 2
    17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:20.488962+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=Källarväggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
    17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:20.548609+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:16.236923+01:00>>
    17-01-22 23:31:24 homeassistant.components.http: Serving /api/error_log to 192.168.1.8 (auth: True)
    

  • Plugin Developer

    You have to filter out messages that are coming from other nodes to the gateway, but is meant for the controller. You can check Message.sender in receive. Messages from nodes will from Message.senderreturn the node id of the nodes, but from the controller it will be 0, ie the same as the node id of the gateway. So only respond to messages where Message.sender is 0 in the receive function of the gateway.



  • Okay. I Think i understand.
    Didn't find much about Message.sender
    But after searching the forum I found something I hope.

    Shall I change this ?

    if (message.type == V_STATUS) {
     
    

    To this?

      if (message.type == V_STATUS && Message.sender == 0) {
     
    

  • Plugin Developer

    if (message.type == V_STATUS && message.sender == 0) {
    

    should work.



  • Tried it.
    Now i can't change the state of the relay anymore.

    I am checking my log again (Post 11 i think.)
    I added an "arrow" in the log below. Is that right?

    17-01-22 23:31:08 mysensors.mysensors: Sending 2;0;1;0;2;1
    
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-20>
    17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-19>
    17-01-22 23:31:10 mysensors.mysensors: Received 2;0;1;0;2;1
    0;1;1;0;2;0   <<<--------- Is this right????? Where does it come from?
    2;0;1;0;3;100
    
    

  • Plugin Developer

    That message must come from the gateway, from the receive function. That's why we have to filter messages in the receive function. Please post you latest sketch, so I can have a look. I'm thinking there might be a bug in the message getter that you're using, since the gateway always sends a turn off message. If the getter would be working it should change the state of the payload according to the message received from node 2.



  • EDIT!!!!!!!!
    I am sorry. I had several sketches on my computer, trying different stuff.
    When i added && message.sender == 0) { I did this in a sketch where i tried to switch the ON / OFF

    #define RELAY_ON 0
    #define RELAY_OFF 1
    

    This is the error.
    The reason i did this is that I am controlling a wall outlet and want it to be ON even if I remove my GW or if it fails.
    I changed this and got it working now.
    The relay changes state and keep this even if i turn node 2 on or off.
    Sorry for this and thank you for all help.
    I read the serial protocol and the API in the MySensors site but couldn't find anything about message.sender stuff.

    ------ Original Post-------
    Hi.

    At first, the gateway switch was turning on when i tuned node 2 on, then off when i turned node 2 off.

    Then i updated node 2 to 2.1.1 as it was still on 2.0.0.
    I added MY_REPEATER_FEATURE to node2 as it was planned.
    After this i behaivs as i said in post 11.
    Before i did this gateway switch "followed" the state of node 2.
    Now it will only turn off if it is on.

    /**
     * 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
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    #define CHILD_ID_LIGHT 0
    #define CHILD_ID_RELAY 1
    #define LIGHT_SENSOR_ANALOG_PIN 4
    #define SN "Gateway"
    #define SV "1.0"
    #define RELAY_PIN 3
    #define RELAY_ON 0
    #define RELAY_OFF 1
    
    bool state = false;
    bool initialValueSent = false;
    
    unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
    
    MyMessage msg2(CHILD_ID_RELAY, V_STATUS);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    void setup()
    {
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      present(CHILD_ID_RELAY, S_BINARY);
    }
    
    void loop()
    {
    
      if (!initialValueSent) {
    //    Serial.println("Sending initial value");
        send(msg2.set(state?RELAY_ON:RELAY_OFF));
    //    Serial.println("Requesting initial value from controller");
        request(CHILD_ID_RELAY, V_STATUS);
        wait(2000, C_SET, V_STATUS);
    
      }  
    
      int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
    //  Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
        send(msg.set(lightLevel));
        lastLightLevel = lightLevel;
      }
      wait(WAIT_TIME);
    }
    
    void receive(const MyMessage &message) {
    
      if (message.type == V_STATUS && message.sender == 0) {
        if (!initialValueSent) {
    //      Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
        // Change relay state
        state = (bool)message.getInt();
        digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
        send(msg2.set(state?RELAY_ON:RELAY_OFF));
      }
    }
    

    This is my gateway sketchright now with

     if (message.type == V_STATUS && message.sender == 0) {
    

    With && message.sender == 0 I can't change the state of the relay at all


  • Plugin Developer

    @xydix

    Great that you got it working! I didn't follow exactly what you did or didn't do to get it working, though. 😄

    Unfortunately the API doesn't contain exactly everything about the message object. Maybe we can ask @hek to add this?

    message.sender
    message.destination
    message.last
    message.type
    message.sensor
    

    Should probably be added.



  • When i change

    #define RELAY_ON 1
    #define RELAY_OFF 0
    

    to

    #define RELAY_ON 0
    #define RELAY_OFF 1
    

    The relay stops working.
    Seems strange, but I tried this even before I discovered the problem with node 2.

    When I change it back, the relay works.

    If i want to present my relay as light,
    Should i use S_DIMMER and V_LIGHT?


  • Plugin Developer

    When you invert the defines for relay, you are not only inverting how the relay will react on digitalWrite, you are also inverting how the state of the relay is reported back to home assistant. This is where the problem gets introduced. As home assistant on turn on action always sends a 1 as payload to the device, the device will now send a 0 back as state feedback. This will tell home assistant that the state should be off, instead of on. So it will be impossible to turn the relay on from home assistant.

    If you do want to invert the high/low behavior of the relay, you need to decouple the high/low defines from the state reporting 1/0, ie use different defines.

    If you want the device to be shown as a light in home assistant you need to present the device as S_DIMMER and send both V_PERCENTAGE and V_STATUS, in mysensors version 2.*. S_BINARY and S_LIGHT will be shown as a switch.


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 8
  • 3
  • 1
  • 5

66
Online

11.4k
Users

11.1k
Topics

112.7k
Posts