How to check if a device is available with Node-Red and Z2M?

Hi all,

I’m using Home Assistant OS, Node Red and Zigbee2MQTT.

We have a smart Zigbee lightbulb that is integrated into a non-smart motion sensor. Meaning, depending on motion, the power to the light is turned on and off.

I have a Node Red Flow that calculates the proper brightness depending on time of day and sends it to the light. This is repeated every 10 seconds.

This works but has one problem: When the light is offline, and the flow tries to set the light brightness, then in the Zigbee2MQTT dashboard lots of error messages appear. Those error messages float over the UI and obscure parts of it.

Is it possible to check whether or not the device is online, before setting its brightness? I tried “get current state”, but that reports “on” even though the lightbulb is actually disconnected from power.

Thanks!

You can check the mqtt topic.

zigbee2mqtt/your_device/availability

Thanks. I set it up like this, and it is connected but the event never fires.

In Node Red: Created a “MQTT IN” on topic “zigbee2mqtt/Toilet Light/availability”
Server localhost:1883, username and password like in Home Assistant.

I have connected a debug node to see what’s going on.

After deploying, it says “connected” next to the MQTT IN node. So that seems to be correct. But after powering on the lightbulb, the event never fires, and no debug output is written.

I forgot that it is disabled by default

1 Like