Presentation of local sensor on ethernet gateway

What is the best way to present a local sensor attached to the ethernet gateway?
i cannot see the sensor show up in Home-Assistant.
Mycontroller sees the sensor and it works fine…

using 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 <[email protected]>
 * 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 <[email protected]>
 * Contribution by Tomas Hozza <[email protected]>
 *
 *
 * 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 WITH_LEDS_BLINKING in MyConfig.h
 * - 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,178,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

// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300

// 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

// 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  // the PCB, on board LED

#include <SPI.h>

#if defined(MY_USE_UDP)
#include <EthernetUdp.h>
#endif
#include <Ethernet.h>
#include <MySensors.h>

unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
#define CHILD_ID 1   // Id of the sensor child
bool lasttripped = 0;

// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);

void setup()
{
  pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Motion Sensor", "1.0");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID, S_MOTION);
}

void loop() {
  // Read digital motion value
  boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;

  if (tripped != lasttripped) {
    send(msg.set(tripped ? "1" : "0")); // Send tripped value to gw
    Serial.println(tripped);
    lasttripped = tripped;
  }

}

the ha log file i see this:

16-08-30 16:45:54 mysensors.mysensors: Child 1 is unknown

I guess this is due to the presentation not working correct?

Yes, the child has to be presented.

There are a couple of bugs regarding presentation of local sensors in mysensors 2.0.0, which have been fixed in the mysensors dev branch. In your case, since you have defined a radio for the gateway and you’re using the ethernet gateway, not the MQTT gateway, I don’t think you’re affected by the bugs.

In HA version 0.27 you should have automatic request of new presentation of a node and children if HA gets a message from an unknown node/child. What version of HA are you on? Do you see log messages about a new presentation being requested?

I’d like to see the log with mysensors related lines after start of HA until the gateway has started up.

I think your sketch looks ok. You could add a check if the initial value has been received by the controller and if not send that again. See:


for an example.

i’m running 0.27
telnet output on the gateway doesnt seem to mention any re-presentation requests when the sensors sends a new value.

http://pastebin.com/raw/6Nks9Qby

I can’t find any warning messages about unknown children in the pastebin log. Do you still have a problem with missing children?

i’m not sure…
the persistence file show this:

{
  "0": {
    "battery_level": 0,
    "children": {
      "1": {
        "description": "",
        "type": 1,
        "id": 1,
        "values": {
          "16": "0"
        }
      },
      "100": {
        "description": "",
        "type": 1,
        "id": 100,
        "values": {
          "16": "1"
        }
      }
    },
    "sensor_id": 0,
    "protocol_version": "2.0.0",
    "sketch_name": "Motion Sensor",
    "sketch_version": "1.0",
    "type": 18
  },

children 1 and 100 are motion sensors.
The values are updated when there is motion/no motion.
but i can’t find them in the ‘States’ section of HA.

When I copy your posted part of the json persistence file and test to load that in hass, everything seems to work as it should regarding those children:

16-09-03 09:16:08 INFO (MainThread) [homeassistant.core] Starting Home Assistant (18 threads)
16-09-03 09:16:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_start[L]>
16-09-03 09:16:08 INFO (Timer) [homeassistant.core] Timer:starting
16-09-03 09:16:08 INFO (Thread-2) [mysensors.mysensors] Trying to connect to ('127.0.0.1', 5003)
16-09-03 09:16:08 DEBUG (ThreadPool Worker 1) [homeassistant.components.mysensors] Update persistence: node 0
16-09-03 09:16:08 ERROR (Thread-2) [mysensors.mysensors] Failed to connect to socket at ('127.0.0.1', 5003).
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.components.mysensors] Adding new devices: <Entity Motion Sensor 0 1: off>
16-09-03 09:16:08 INFO (Thread-2) [mysensors.mysensors] Waiting 10 secs before trying to connect again.
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state binary_sensor.motion_sensor_0_1=unavailable; friendly_name=Motion Sensor 0 1 @ 2016-09-03T09:16:08.119589+02:00>, entity_id=binary_sensor.motion_sensor_0_1>
16-09-03 09:16:08 DEBUG (ThreadPool Worker 1) [homeassistant.components.mysensors] Motion Sensor 0 1: value_type 16, value = 0
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state binary_sensor.motion_sensor_0_1=unavailable; friendly_name=Motion Sensor 0 1 @ 2016-09-03T09:16:08.119589+02:00>, new_state=<state binary_sensor.motion_sensor_0_1=off; device=127.0.0.1, description=, sensor_class=motion, friendly_name=Motion Sensor 0 1, battery_level=0, child_id=1, node_id=0, V_TRIPPED=off @ 2016-09-03T09:16:08.132081+02:00>, entity_id=binary_sensor.motion_sensor_0_1>
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.components.mysensors] Adding new devices: <Entity Motion Sensor 0 100: off>
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state binary_sensor.motion_sensor_0_100=unavailable; friendly_name=Motion Sensor 0 100 @ 2016-09-03T09:16:08.142650+02:00>, entity_id=binary_sensor.motion_sensor_0_100>
16-09-03 09:16:08 DEBUG (ThreadPool Worker 1) [homeassistant.components.mysensors] Motion Sensor 0 100: value_type 16, value = 1
16-09-03 09:16:08 INFO (ThreadPool Worker 1) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state binary_sensor.motion_sensor_0_100=unavailable; friendly_name=Motion Sensor 0 100 @ 2016-09-03T09:16:08.142650+02:00>, new_state=<state binary_sensor.motion_sensor_0_100=on; device=127.0.0.1, description=, sensor_class=motion, friendly_name=Motion Sensor 0 100, battery_level=0, child_id=100, node_id=0, V_TRIPPED=on @ 2016-09-03T09:16:08.143412+02:00>, entity_id=binary_sensor.motion_sensor_0_100>
16-09-03 09:16:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=stop, domain=homeassistant>
16-09-03 09:16:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=restart, domain=homeassistant>

Note that I haven’t connected an ethernet gateway, so I get a connection error. But that doesn’t affect the parts of interest here.

Edit:
Can you post the mysensors part of your home assistant config?

Do you have any other binary sensor types as children in mysensors? What does node 4 contain? That node also doesn’t seem to load its children, looking at your log.

i’m not sure what happened , but after restarting HASS a couple of times the binary sensors have appeared in the fronted…
changed topic title to solved

1 Like

Edit: You can mark the thread as solved by accepting an answer as solution. Don’t need to change title.

I suggest marking your own previous post as solution.