Unavailable/available notification

Hi all,

I’m trying to figure out how to monitor a state-change from Home Assistant entities - I can get it to tell me when an entity becomes “unavailable” but struggling to figure an easy way to notify when it becomes available again??

Is there a simple way?

I tried this but nothing happens when the entity goes unavailable so I must have gone a bit wrong ??

The entity that you are watching, is that an entity that returns the temperature? If so add a connection sensor instead. Then in the trigger node use the conditions section, not the custom output section.

1 Like

Brilliant, thanks, I’ll add that sensor and try again.

:slight_smile:

And just to clear something up for you.

States will only be updated in HA if they are different from the previous one, so a state of unavailable together with a previous state of unavailable is not possible.

You could use previous state is unavailable and current state is not unavailable.instead.

1 Like

Thanks all, it’s working now.

I added the binary sensor and changed the state node. The conditions are actually “on” and “off” but its going now.

It does seem slow to respond to the off state though - monitoring it via the HA front-end it takes a good while to change to disconnected/off but is very fast to change back.

I set update_interval to 30s which seemed reasonable but its way longer than that.

A device will typically send a message at boot up, so it is fast to detect a device becoming available.

A device going offline will typically not send a message. It might run out of power or have crashed or similar unexpected event.
This means HA and the integrations can only assume a device is offline, if it did not respond at a time it was supposed to and that is the reason why an unavailable state is slower to detect. Sometimes it might take hours, like for sensors that only report once a day.

1 Like

Thanks for that.

I guess we cannot adjust the offline status delay??

You can create a heartbeat using the interval component, add to the esp

interval:
  - interval: 30s
    then:
      - homeassistant.event:
          event: esphome.heartbeat.nodename

Then use an events all with a trigger node after.

[{"id":"021d4406c6878f58","type":"server-events","z":"8e6ef4f6cbb13d83","name":"","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"esphome.heartbeat.nodename","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":700,"y":420,"wires":[["fe39495f3aab7683","f63e21cd69a9cfa7"]]},{"id":"f63e21cd69a9cfa7","type":"trigger","z":"8e6ef4f6cbb13d83","name":"","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"45","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":950,"y":420,"wires":[["fe39495f3aab7683"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":6,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":["y","yes","true","on","home","open"],"connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"ccb5dd758fcd65c7","type":"global-config","env":[],"modules":{"node-red-contrib-home-assistant-websocket":"0.80.3"}}]
1 Like