HomeAssistant + SenseBender MQTT GW + MySensor Node - almost there I think

  • Hi,
    I have been running OpenHab, Mosquitto (MQTT broker) and some home brew gateways and RF nodes. I have seen the light and clearly the MySensors platform and Home Assistant as my controller are the way to go. I've had a good go at getting it to work and I feel I'm close, but now I need some help.

    I have a Moteino with RFM69W configured based on the sample code here https://home-assistant.io/components/mysensors/ and have put a switch (fixed not momentary type) on pin 8.

    I bought a SenseBender GW board and soldered on an RFM69 and plugged in a W5100 Eth module. I used a combination of running the Examples > MySensors > SensebenderGatewaySerial example and the Examples > MySensors > GatewayW5100 example to creat my MQTT GW code.

    I used the sample Home Assistant configuration.yaml code from here https://home-assistant.io/components/mysensors/ but customised to just use the "- device: mqtt" section.
    I also added an mqtt broker section to my configuration.yaml
    My Home Assistant is running on an RPi3.

    So whats the problem?
    Well, when I press the button on the end node, it successfully transmits what looks like the right info to the gateway and the gateway in turn shoots the right MQTT packet over to the MQTT Broker (mosquitto) and then Home Assistant seems to receive it.
    BUT unfortunately Home Assistant then instantly generates an error

    2017-06-29 18:06:56 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on GWPUB/55/11/1/0/2: 0
    2017-06-29 18:06:56 DEBUG (Thread-13) [homeassistant.components.mysensors] Update: node 55, child 11 sub_type 2
    2017-06-29 18:06:56 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
    Traceback (most recent call last):
      File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
        result = next(coro)
      File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
        "No entity id specified for entity {}".format(self.name))
    homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity Switch Sensor 55 11

    I will raise this in the Home Assistant forums as well, but I would like to know if anyone can assist here with checking the my MySensors stuff. Or provide some examples of known working configs?

    Here is my Node code

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_RFM69HW false
    #define MY_RFM69_NETWORKID 101
    #define MY_NODE_ID 55
    #include <MySensors.h>
    #include <Bounce2.h>
    #define CHILD_ID_SW 11
    #define CHILD_ID_REL 22
    #define SW_PIN 8
    #define REL_PIN 7
    #define SW_ON 1
    #define SW_OFF 0
    MyMessage msgSW(CHILD_ID_SW, V_STATUS); // 16
    //MyMessage msgREL(CHILD_ID_REL, V_LIGHT); //2
    byte StateREL=0;
    Bounce debouncer = Bounce(); 
    int oldValueSW=-1;
    int valueSW=0;
    const unsigned long tUpdate=60000; //update interval if input do not change
    unsigned long t0;
    bool state = false;
    bool initialValueSent = false;
    void presentation() {
      sendSketchInfo("Node_Test", "0.1");
      present(CHILD_ID_SW, S_BINARY);  
      //present(CHILD_ID_REL, S_LIGHT);
    void setup() {
      pinMode(REL_PIN, OUTPUT);
      digitalWrite(REL_PIN, StateREL);
      // get state of SW at powerup.
      state = debouncer.read();
    void loop() 
      // If this is the first time loop has run, send initial value to Home Assistant.
      if (initialValueSent == false) 
        Serial.println("Sending initial value");
        send(msgSW.set(state?SW_ON:SW_OFF), true); //and asking for an ACK
        initialValueSent = true;
        t0=millis();  // reset the interval timer so we don't send update until period expires.
      if (debouncer.update()) 
        if (debouncer.read()!= state) 
          state = !state;
          // Send new state and request ack back
          send(msgSW.set(state?SW_ON:SW_OFF), true);
          t0=millis();  // reset the interval timer so we don't send update until period expires.
      if ((millis()-t0) > tUpdate) 
        // Send new state and request ack back
        send(msgSW.set(state?SW_ON:SW_OFF), true);
        t0=millis();  // reset the interval timer so we don't send update until period expires.
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("Received an ack from gateway");
      else  {
         Serial.println("Received something but not an ack, from gateway");

    Here is what it's serial monitor looks like

    3 TSM:INIT
    4 TSF:WUR:MS=0
    10 TSF:SID:OK,ID=55
    11 TSM:FPAR
    142 TSF:MSG:SEND,55-55-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    621 TSF:MSG:READ,0-0-55,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    626 TSF:MSG:FPAR OK,ID=0,D=1
    2149 TSM:FPAR:OK
    2150 TSM:ID
    2151 TSM:ID:OK
    2153 TSM:UPL
    2160 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2190 TSF:MSG:READ,0-0-55,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2198 TSM:UPL:OK
    2199 TSM:READY:ID=55,PAR=0,DIS=1
    2208 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2225 TSF:MSG:READ,0-0-55,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2280 TSF:MSG:SEND,55-55-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    2336 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2403 TSF:MSG:READ,0-0-55,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2459 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=11,pt=0,l=9,sg=0,ft=0,st=OK:Node_Test
    2516 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:0.1
    2572 TSF:MSG:SEND,55-55-0-0,s=11,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    2578 MCO:REG:REQ
    2630 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2651 TSF:MSG:READ,0-0-55,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2656 MCO:PIM:NODE REG=1
    2658 MCO:BGN:STP
    2660 MCO:BGN:INIT OK,TSP=1
    Sending initial value
    2669 TSF:MSG:SEND,55-55-0-0,s=11,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:0
    2695 TSF:MSG:READ,0-0-55,s=11,c=1,t=2,pt=2,l=2,sg=0:0
    2700 TSF:MSG:ACK
    Received an ack from gateway
    13868 TSF:MSG:SEND,55-55-0-0,s=11,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
    13892 TSF:MSG:READ,0-0-55,s=11,c=1,t=2,pt=2,l=2,sg=0:1
    13897 TSF:MSG:ACK
    Received an ack from gateway
    18896 TSF:MSG:SEND,55-55-0-0,s=11,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:0
    18922 TSF:MSG:READ,0-0-55,s=11,c=1,t=2,pt=2,l=2,sg=0:0
    18927 TSF:MSG:ACK
    Received an ack from gateway

    Here is my SenseBender MQTT Eth w5100 Gateway code

    * 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.
    * The ArduinoGateway prints data received from sensors on the serial link.
    * The gateway accepts input on seral which will be sent out on radio network.
    * This GW code is designed for Sensebender GateWay / (Arduino Zero variant)
    * Wire connections (OPTIONAL):
    * - Inclusion button should be connected to SW2
    * LEDs on board (default assignments):
    * - Orange: USB RX/TX - Blink when receiving / transmitting on USB CDC device
    * - Yellow: RX  - Blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
    * - Green : TX  - Blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - Red   : ERR - Fast blink on error during transmission error or recieve crc error
    * - Blue  : free - (use with LED_BLUE macro)
    #define SKETCH_VERSION "0.2"
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_DEBUG_VERBOSE
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_RFM69HW false
    #define MY_RFM69_NETWORKID 101
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    //#define MY_RF24_PA_LEVEL RF24_PA_HIGH
    // Enable serial gateway
    //#define MY_GATEWAY_SERIAL
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    // Enable gateway ethernet module type
    //#define MY_GATEWAY_W5100
    // Enable gateway ethernet module type with MQTT
    // Set this node's subscribe and publish topic prefix
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-gw"    // this is used when this gw connects to the MQTT Broker.
    #define MY_GATEWAY_W5100
    // MQTT broker ip address or url. Define one or the other.
    //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 200, 251   // HOMER my Raspi running Home Assistant and Mosquitto
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 200, 241   // HABPI my Raspi running OpenHAB and Mosquitto
    // The MQTT broker port to to open
    #define MY_PORT 1883
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "pimqtt"           // as generated when I installed Mosquitto on my Home Assistant RasPi.
    //#define MY_MQTT_PASSWORD "lowsecpass"   // as generated when I installed Mosquitto on my Home Assistant RasPi.
    // 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
    // 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
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    // Enable to UDP
    //#define MY_USE_UDP
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,200,230   
    // 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    // ONLY for MY_GATEWAY_W5100 mode.
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,200,254
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    // Controller ip address. Enables client mode (default is "server" mode). // ONLY for MY_GATEWAY_W5100 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, 0x01, 0x01
    // Enable inclusion mode
    // Enable Inclusion mode button on gateway
    // Inverses behavior of inclusion button (if using external pullup)
    // Set inclusion mode duration (in seconds)
    // Digital pin used for inclusion mode button
    // Set blinking period
    // Inverses the behavior of leds on the Gateway
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #include <Ethernet.h>
    #include <MySensors.h>
    #include <SD.h>
    #include <drivers/ATSHA204/ATSHA204.cpp>
    Sd2Card card;
    static uint8_t num_of_leds = 5;
    static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};
    void setup()
    	// Setup locally attached sensors
    void presentation()
    	// Present locally attached sensors
    void loop()
    	// Send locally attached sensor data here
     //if (Serial) {
     //      Serial.println(F("In Loop() "));
    void preHwInit()
    	pinMode(MY_SWC1, INPUT_PULLUP);
    	pinMode(MY_SWC2, INPUT_PULLUP);
    	if (digitalRead(MY_SWC1) && digitalRead(MY_SWC2)) {
    	uint8_t tests = 0;
    	for (int i=0; i< num_of_leds; i++) {
    		pinMode(leds[i], OUTPUT);
    	uint8_t led_state = 0;
    	if (digitalRead(MY_SWC1)) {
    		while (!Serial) {
    			digitalWrite(LED_BLUE, led_state);
    			led_state ^= 0x01;
    		} // Wait for USB to be connected, before spewing out data.
    	digitalWrite(LED_BLUE, LOW);
    	if (Serial) {
    		Serial.println("Sensebender GateWay test routine");
    		Serial.print("Mysensors core version : ");
    		Serial.print("GateWay sketch version : ");
    	if (testSha204()) {
    		digitalWrite(LED_GREEN, HIGH);
    	if (testSDCard()) {
    		digitalWrite(LED_YELLOW, HIGH);
    	if (testEEProm()) {
    		digitalWrite(LED_ORANGE, HIGH);
    	if (testAnalog()) {
    		digitalWrite(LED_BLUE, HIGH);
    	if (tests == 4) {
    		while(1) {
    			for (int i=0; i<num_of_leds; i++) {
    				digitalWrite(leds[i], HIGH);
    				digitalWrite(leds[i], LOW);
    	} else {
    		while (1) {
    			digitalWrite(LED_RED, HIGH);
    			digitalWrite(LED_RED, LOW);
    bool testSha204()
    	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
    	uint8_t ret_code;
    	if (Serial) {
    		Serial.print("- > SHA204 ");
    	ret_code = atsha204_wakeup(rx_buffer);
    	if (ret_code == SHA204_SUCCESS) {
    		ret_code = atsha204_getSerialNumber(rx_buffer);
    		if (ret_code != SHA204_SUCCESS) {
    			if (Serial) {
    				Serial.println(F("Failed to obtain device serial number. Response: "));
    			Serial.println(ret_code, HEX);
    		} else {
    			if (Serial) {
    				Serial.print(F("Ok (serial : "));
    				for (int i=0; i<9; i++) {
    					if (rx_buffer[i] < 0x10) {
    						Serial.print('0'); // Because Serial.print does not 0-pad HEX
    					Serial.print(rx_buffer[i], HEX);
    			return true;
    	} else {
    		if (Serial) {
    			Serial.println(F("Failed to wakeup SHA204"));
    	return false;
    bool testSDCard()
    	if (Serial) {
    		Serial.print("- > SD CARD ");
    	if (!card.init(SPI_HALF_SPEED, MY_SDCARD_CS)) {
    		if (Serial) {
    			Serial.println("SD CARD did not initialize!");
    	} else {
    		if (Serial) {
    			Serial.print("SD Card initialized correct! - ");
    			Serial.print("type detected : ");
    			switch(card.type()) {
    			case SD_CARD_TYPE_SD1:
    			case SD_CARD_TYPE_SD2:
    			case SD_CARD_TYPE_SDHC:
    		return true;
    	return false;
    bool testEEProm()
    	uint8_t eeprom_d1, eeprom_d2;
    	SerialUSB.print(" -> EEPROM ");
    	eeprom_d1 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
    	eeprom_d1 = ~eeprom_d1; // invert the bits
    	i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
    	eeprom_d2 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
    	if (eeprom_d1 == eeprom_d2) {
    		i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1);
    		return true;
    	return false;
    bool testAnalog()
    	int bat_detect = analogRead(MY_BAT_DETECT);
    	Serial.print("-> analog : ");
    	if (bat_detect < 400 || bat_detect > 650) {
    		Serial.println(" Failed");
    		return false;
    	Serial.println(" Passed");
    	return true;

    And here are what I think are the relevant sections of my Home Assistant configuration.yaml

      default: info   #ignore any messages below this level. PJ - I often use 'info' here.
        homeassistant.components.mqtt: debug
        homeassistant.components.mysensors: debug
      broker: habpi     # my mosquitto based broker on my habpi box.
      port: 1883
      client_id: homer_home_assist
      keepalive: 60
      birth_message:                #this MQTT message gets sent every time Home Assistant starts up or is restarted.
        topic: 'home/hass/status'
        payload: 'online'
        topic: 'home/hass/status'
        payload: 'offline'
        - device: mqtt
          persistence_file: '/home/homeassistant/.homeassistant/mysensors.json'         
          topic_in_prefix: 'GWPUB'
          topic_out_prefix: 'GWSUB'
      optimistic: false
      persistence: true
      retain: true
      version: 2.0

  • Plugin Developer


    Hi! This is a known issue on the home assistant side. I have a fix in progress but it's not ready yet.

    You should be able to work around it by not sending values too frequently until the entity is added to home assistant, if you only have one value type.


Log in to reply

Suggested Topics

  • 6
  • 8
  • 2
  • 17
  • 3
  • 7
  • 1
  • 1