Mysensors - Node availabilty, Heartbeat etc

Hi All.
I am starting to set up Mysensors integration.
I have my mysenors /RFM95(433Mhz) to MQTT gateway running on the ESP32.
The Hassio Mysensors intagration, sees my first basic node (door/button binary sensor), Great.
But…
I am looking for checking the sensor availability, so I know if it drops off the system for some reason.

Research reveals the heart beat function, so now my node sends to the heartbeat topic…
mygateway1-out/2/255/3/0/22
the millis since node startup…a ever increasing number…

My question, has anyone else come up with a nice automation or process to create a node availability sensor for this.
Or, did I miss something in the Mysensors integration which already takes care of heart beats and such.

Cheers
P

Hi. Did you figure a good solution on this.
I am seeing heartbeat messages but do not know how to use them. Because there are big gaps in the increment of heartbeat messages.

I would appreciate if you could let me know your experience /thoughts

Thanks.

Answered my own question:

How to add node availability sensor to Home assistant.

Date: 26/4/20

Platform: Hassio Core 0.107.7 Operating system 3.12

Mysensors 2.3.2

Assumptions: You have a mysensors MQTT gateway setup on your home assistant and a mysensors node (Node 1) and child sensors sending data in, and you have hassio receiving/processing that sensor data.
Tip: use MQTTExplorer to check your MQTT messages are flowing through the gateway and MQTT broker

  1. We use mysensors heartbeats sent every 30 seconds from the node.
    insert this code into your mysensors hardware node sketch firmware and upload

insert the void loop()

//-------------- Heart Beat---------------------------------------------------------
//this is sent by the Mysensors MQTTGateway to topic: mygateway1-out/1/255/3/0/22
static unsigned long lastLoopTime = 0; // Holds the last time the main loop ran.
if (millis() - lastLoopTime > 30000) {//one every 30 seconds
lastLoopTime = millis();
sendHeartbeat();//sends heartbeat msg time in millisseconds
}
//-------------------------------------------------------------------------------

  1. confirm heartbeat messages are coming through via the gateway and create a Hassio sensor: sensor.node_1_heart_beats -

platform: mqtt
name: “node1 heartbeats”
state_topic: “mygateway1-out/1/255/3/0/22”

you should see large integers every 30 seconds
3) make sure you have the Time_Date sensor configured in the Hassio configuration.yaml
4) add these automatons: which will compare local time with the time sensor.node_1_heart_beats is updated (with your node heartbeat via MQTT)

alias: Heartbeat RX regularity monitor, no HB after 40 s= avail = offline
description: ‘’
trigger:

  • platform: template
    value_template: ‘{{ (states.sensor.time.last_changed - states.sensor.node_1_heart_beat.last_changed).total_seconds()> 40 }}’
    condition: []
    action:
  • data:
    payload: offline
    topic: tele/Node1
    service: mqtt.publish

alias: Heartbeat RX regularity monitor, HB within 40 s = avail = online
description: ‘’
trigger:

  • platform: template
    value_template: ‘{{ (states.sensor.time.last_changed - states.sensor.node_1_heart_beat.last_changed).total_seconds()
    < 40 }}’
    condition: []
    action:
  • data:
    payload: online
    topic: tele/Node1
    service: mqtt.publish
  1. setup a sensor in Home assistant sensor.node1_availability to monitor the MQTT topic tele/Node1
  • platform: mqtt
    name: “Node1 Availability”
    state_topic: “tele/Node1”