Mysensors works only for few seconds on startup

Hi,

I updated HA to 0.52 and noticed on the release notes that mysensors support have had some changes.

MySensors: Not a breaking change per se but users that have not been following the mysensors serial API could face dropped messages after this change. Messages are now validated according to the API before being passed along from/to devices.

The problem now is that Mysensor devices are not anymore discussing with Home Assistant.

The setup goes so that I have one NRF24 radio attached to a Raspberry. On there I’m running the mysensors gateway of which communicates with home assistant. The gateway receives all the messages sent by other arduino+NRF24 units but home assistant is not doing anything.

But the funny thing is that mysensors works good for a few seconds on home assistant booting up. Then, nothing… Could someone help me out to check if I have sketch error or some configuration mistake? I just cant get on top of this. I tried the debug mode introduced with the newest update but to my understanding it didnt have a word about mysensors.

HA config:

    homeassistant:
      # Name of the location where Home Assistant is running
      name: Home
      # Location required to calculate the time the sun rises and sets
      latitude: xx
      longitude: xx
      # Impacts weather/sunrise data (altitude above sea level in meters)
      elevation: 5
      # metric for Metric, imperial for Imperial
      unit_system: metric
      # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
      time_zone: Europe/Helsinki

      # Customize entities
      customize:
        switch.bedlights_106_1:
          friendly_name: "Juha's Nightlight"
        switch.bedlights_106_2:
          friendly_name: "Tiina's Nightlight"
        switch.bedlights_106_3:
          friendly_name: "Heart Nightlight"
        sensor.bedlights_106_4:
          hidden: true
        sensor.bedlights_106_4_2:
          hidden: true

        # Alarm clock sensors
        sensor.alarm_clock_hour:
          hidden: true
        sensor.alarm_clock_minute:
          hidden: true
        sensor.alarm_clock_time_long:
          hidden: true
        sensor.alarm_clock_time:
          friendly_name: 'Alarm Clock Setting'
          icon: mdi:alarm
        # Alarm clock inputs
        input_slider.alarm_clock_hour:
          friendly_name: 'Hour'
          icon: mdi:timer
        input_slider.alarm_clock_minute:
          friendly_name: 'Minute'
          icon: mdi:timer
        input_boolean.alarm_clock_status:
          friendly_name: 'Alarm Clock Status'
          icon: mdi:alarm-check

        # Time and Date
        sensor.time:
          friendly_name: 'Time'
          icon: mdi:clock
        sensor.date:
          friendly_name: 'Date'
          icon: mdi:calendar-today
        # Bedroom sensors
        sensor.bedroom_temperature:
          friendly_name: 'Temperature'
          icon: mdi:thermometer
        sensor.bedroom_humidity:
          friendly_name: 'Humidity'
          icon: mdi:water-percent
        # Shower sensors
        sensor.shower_temperature:
          friendly_name: 'Temperature'
          icon: mdi:thermometer
        sensor.shower_humidity:
          friendly_name: 'Humidity'
          icon: mdi:water-percent
        # Living Room sensors
        sensor.living_room_temperature:
          friendly_name: 'Temperature'
          icon: mdi:thermometer
        sensor.living_room_humidity:
          friendly_name: 'Humidity'
          icon: mdi:water-percent
        # Living room cabinet lights
        switch.towerdetector_107_1:
          friendly_name: 'Standalone lamp'
        switch.towerdetector_107_2:
          friendly_name: 'Decorative light'
        # Bathroom sensors
        sensor.bathroom_temperature:
          friendly_name: 'Temperature'
          icon: mdi:thermometer
        sensor.bathroom_humidity:
          friendly_name: 'Humidity'
          icon: mdi:water-percent
        sensor.bathroom_pressure:
          frindly_name: 'Pressure'
    # Show links to resources in log and frontend
    #introduction:

    # Enables the frontend
    frontend:

    # Enables configuration UI
    config:

    http:
      # Uncomment this to add a password (recommended!)
      api_password: xx
      # Uncomment this if you are using SSL or running in Docker etc
      # base_url: example.duckdns.org:8123

    # Checks for available updates
    # Note: This component will send some information about your system to
    # the developers to assist with development of Home Assistant.
    # For more information, please see:
    # https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
    updater:

    # Discover some devices automatically
    discovery:

    # Allows you to issue voice commands from the frontend in enabled browsers
    conversation:

    # Enables support for tracking state changes over time.
    history:

    # Recorder component to make the database. include and exclude will 
    # affect also to history component
    recorder:
      purge_days: 5
      include:
        domains:
          - sensor
          #- binary_sensor #for now blocked tower detector motion sensors
          - device_tracker
      exclude:
        entities:
          - sensor.date
          - sensor.time
          - sensor.alarm_clock_hour
          - sensor.alarm_clock_minute
          - sensor.alarm_clock_time
          - sensor.alarm_clock_time_long
          - sensor.yr_symbol

    # View all events in a logbook
    logbook:

    # Track the sun
    sun:

    # sensors
    sensor:
      - platform: yr
      - platform: dht
        sensor: DHT22
        pin: 17
        name: Living room
        monitored_conditions:
          - temperature
          - humidity
      - platform: mqtt
        state_topic: "bedroom/dht"
        name: 'Bedroom Temperature'
        unit_of_measurement: "°C"
        value_template: '{{ value_json.temperature }}'
      - platform: mqtt
        state_topic: "bedroom/dht"
        name: 'Bedroom Humidity'
        unit_of_measurement: "%"
        value_template: '{{ value_json.humidity }}'
      - platform: mqtt
        state_topic: "shower/dht"
        name: 'Shower temperature'
        unit_of_measurement: "°C"
        value_template: '{{ value_json.temperature }}'
      - platform: mqtt
        state_topic: "shower/dht"
        name: 'Shower Humidity'
        unit_of_measurement: "%"
        value_template: '{{ value_json.humidity }}'
      - platform: mqtt
        state_topic: "bathroom/dht"
        name: 'Bathroom temperature'
        unit_of_measurement: "°C"
        value_template: '{{ value_json.temperature }}'
      - platform: mqtt
        state_topic: "bathroom/dht"
        name: 'Bathroom Humidity'
        unit_of_measurement: "%"
        value_template: '{{ value_json.humidity }}'
      - platform: mqtt
        state_topic: "bathroom/pressure"
        name: 'Bathroom Pressure'
        unit_of_measurement: "Pa"
        value_template: '{{ value_json.pressure }}'
    # Alarm clock code start
      - platform: time_date
        display_options:
          - 'time'
          - 'date'
      - platform: template
        sensors:
          alarm_clock_hour:
            value_template: '{{ states.input_slider.alarm_clock_hour.state | int }}'
          alarm_clock_minute:
            value_template: '{{ states.input_slider.alarm_clock_minute.state | int }}'
          alarm_clock_time:
            value_template: >-
              {{ states.sensor.alarm_clock_hour.state }}:
              {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
                0
              {%- endif -%}
                {{ states.sensor.alarm_clock_minute.state }}
          alarm_clock_time_long:
            value_template: >-
              {% if states.sensor.alarm_clock_hour.state|length == 1 -%}
                0
              {%- endif -%}
                {{ states.sensor.alarm_clock_hour.state }}:
              {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
                0
              {%- endif -%}
                {{ states.sensor.alarm_clock_minute.state }}
    # Alarm clock code end

    binary_sensor:
      # Bathroom motion sensor
      - platform: mqtt
        state_topic: 'bathroom/motion'
        name: 'Bathroom motion'
        payload_on: 'on'
        payload_off: 'off'
        device_class: motion

    # Text to speech
    tts:
      platform: google

    group: !include groups.yaml
    automation: !include automations.yaml
    script: !include scripts.yaml


    # Spotify integration
    media_player:
      - platform: spotify
        client_id: xx
        client_secret: xx

    # Track devices connected to the Asus router
    device_tracker:
      - platform: bluetooth_tracker

    # MQTT with mosquitto
    mqtt:
      broker: xx
      port: xx
      client_id: xx-xx-xx
      username: xx
      password: xx

    # Mysensors
    mysensors:
      gateways:
        - device: '127.0.0.1'
          persistence_file: '/home/homeassistant/mysensors.json'
          tcp_port: 5003
      optimistic: false
      persistence: true
      retain: true
      version: '2.0'

    # Alarm clock code start
    input_slider:
      alarm_clock_hour:
        initial: 6
        min: 0
        max: 23
        step: 1
      alarm_clock_minute:
        initial: 20
        min: 0
        max: 55
        step: 5
     
    input_boolean:
      alarm_clock_status:
        initial: off


    # Alarm clock code end

    telegram_bot:
      - platform: polling
        api_key: 'xx'
        allowed_chat_ids:
          - 'xx'

    # Example configuration.yaml entry for the notifier
    notify:
      - name: xx
        platform: telegram
        chat_id: 'xx'

    # Locks
    lock:
      - platform: mqtt
        name: Warehouse 
        state_topic: "warehouse/lock/status"
        command_topic: "warehouse/lock/set"
        payload_lock: "LOCK"
        payload_unlock: "UNLOCK"

One of my Mysensor nodes:

    #include "relay_230V_5V.h"
    #include "OneButton.h"

    // Enable debug prints to serial monitor
    #define MY_DEBUG


    // Enable and select radio type attached
    #define MY_RADIO_NRF24

    #define CHILD_ID_JUHA_RELAY 1
    #define CHILD_ID_TIINA_RELAY 2
    #define CHILD_ID_HEART_RELAY 3
    #define CHILD_ID_HUE 4

    #include <MyConfig.h>
    #include <MySensors.h>

    MyMessage MSjuha(CHILD_ID_JUHA_RELAY, V_LIGHT);
    MyMessage MStiina(CHILD_ID_TIINA_RELAY, V_LIGHT);
    MyMessage MSheart(CHILD_ID_HEART_RELAY, V_LIGHT);
    MyMessage MSHueOn(CHILD_ID_HUE, V_SCENE_ON);
    MyMessage MSHueOff(CHILD_ID_HUE, V_SCENE_OFF);

    //Juha's Nightlight
    const int juhaControlPin = 2;
    const int juhaButton1Pin = 5;
    const int juhaButton2Pin = 6;
    bool buttonDefault = LOW;

    //Tiina's Nightlight
    const int tiinaControlPin = 4;
    const int tiinaButton1Pin = 7;
    const int tiinaButton2Pin = 8;

    //Heart shaped light
    const int heartControlPin = 3;

    //Init relay controls pins to this state
    bool relayDefault = HIGH;

    //classes for lights
    relay_230V_5V juhaNightlight(juhaControlPin, relayDefault);
    relay_230V_5V tiinaNightlight(tiinaControlPin, relayDefault);
    relay_230V_5V heartShapedLight(heartControlPin, relayDefault);

    //classes for buttons
    OneButton juhaButton1(juhaButton1Pin, buttonDefault);
    OneButton juhaButton2(juhaButton2Pin, buttonDefault);
    OneButton tiinaButton1(tiinaButton1Pin, buttonDefault);
    OneButton tiinaButton2(tiinaButton2Pin, buttonDefault);

    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("bedlights", "1.1", true);

        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_JUHA_RELAY, S_LIGHT, "Juha's Nightlight", true);
        present(CHILD_ID_TIINA_RELAY, S_LIGHT, "Tiina's Nightlight", true);
        present(CHILD_ID_HEART_RELAY, S_LIGHT, "Heart Nightlight", true);
        present(CHILD_ID_HUE, S_SCENE_CONTROLLER, "HUE Nightlight", true);
    }

    void setup()
    {
        // Attach button click functions
        juhaButton1.attachClick(juhaClick1);
        juhaButton1.attachDoubleClick(juhaDoubleclick1);
        juhaButton1.attachLongPressStart(juhaLongPressStart1);
        tiinaButton1.attachClick(tiinaClick1);
        tiinaButton1.attachDoubleClick(tiinaDoubleclick1);
        tiinaButton1.attachLongPressStart(tiinaLongPressStart1);
        juhaButton2.attachClick(juhaClick2);
        juhaButton2.attachDoubleClick(juhaDoubleclick2);
        juhaButton2.attachLongPressStart(juhaLongPressStart2);
        tiinaButton2.attachClick(tiinaClick2);
        tiinaButton2.attachDoubleClick(tiinaDoubleclick2);
        tiinaButton2.attachLongPressStart(tiinaLongPressStart2);
    }

    void loop()
    {
        juhaButton1.tick();
        tiinaButton1.tick();
        juhaButton2.tick();
        tiinaButton2.tick();



    }

    // Functions for acting to button press
    void juhaClick1()
    {
      juhaNightlight.toggleState();
      send(MSjuha.set(!juhaNightlight.getState()));
    }
    void juhaClick2()
    {
      heartShapedLight.toggleState();
      send(MSheart.set(!heartShapedLight.getState()));
    }
    void juhaDoubleclick1()
    {
      allOff();
    }
    void juhaDoubleclick2()
    {
      allOff();
      hueOff();
    }
    void juhaLongPressStart1()
    {
      tiinaNightlight.toggleState();
      send(MStiina.set(!tiinaNightlight.getState()));
    }
    void juhaLongPressStart2()
    {
      hueOn();
    }
    void tiinaClick1()
    {
      tiinaNightlight.toggleState();
      send(MStiina.set(!tiinaNightlight.getState()));
    }
    void tiinaClick2()
    {
      heartShapedLight.toggleState();
      send(MSheart.set(!heartShapedLight.getState()));
    }
    void tiinaDoubleclick1()
    {
      allOff();
    }
    void tiinaDoubleclick2()
    {
      allOff();
      hueOff();
    }
    void tiinaLongPressStart1()
    {
      juhaNightlight.toggleState();
      send(MSjuha.set(!juhaNightlight.getState()));
    }
    void tiinaLongPressStart2()
    {
      hueOn();
    }

    // Turn off all nightlights
    void allOff()
    {
      juhaNightlight.setState(HIGH);
      heartShapedLight.setState(HIGH);
      tiinaNightlight.setState(HIGH);
      send(MSjuha.set(!juhaNightlight.getState()));
      send(MSheart.set(!heartShapedLight.getState()));
      send(MStiina.set(!tiinaNightlight.getState()));
    }

    // Turn HUE lights on
    void hueOn()
    {
        send(MSHueOn.set("Nightlight_on"));
        wait(150);
        send(MSHueOn.set("idle"));
    }

    // Turn all HUE lights off
    void hueOff()
    {
        send(MSHueOff.set("Nightlight_off"));
        wait(150);
        send(MSHueOff.set("idle"));
    }


    // Message received functions from the central node
    void receive(const MyMessage &message)
    {
        if (message.type == V_LIGHT) 
        {
            if (message.sensor == CHILD_ID_JUHA_RELAY) 
            {
                if (message.getBool()== 1)
                {
                    juhaNightlight.setState(LOW);
                    send(MSjuha.set(!juhaNightlight.getState()));
                }
                else
                {
                    juhaNightlight.setState(HIGH);
                    send(MSjuha.set(!juhaNightlight.getState()));
                }
            }
            
            if (message.sensor == CHILD_ID_TIINA_RELAY) 
            {
                if (message.getBool()== 1)
                {
                    tiinaNightlight.setState(LOW);
                    send(MStiina.set(!tiinaNightlight.getState()));
                }
                else
                {
                    tiinaNightlight.setState(HIGH);
                    send(MStiina.set(!tiinaNightlight.getState()));
                }            
            }
            if (message.sensor == CHILD_ID_HEART_RELAY) 
            {
                if (message.getBool()== 1)
                {
                    heartShapedLight.setState(LOW);
                    send(MSheart.set(!heartShapedLight.getState()));
                }
                else
                {
                    heartShapedLight.setState(HIGH);
                    send(MSheart.set(!heartShapedLight.getState()));
                }
            }
        }
    }

There was a bug in 0.52. See https://github.com/theolind/pymysensors/pull/110 for solution.

Thank you!

That seems to do it. Next time need to check more carefully already know bugs.

1 Like