Detect when a Zigbee lamp is turned off/on from the switch


Is there a way to detect when a Zigbee device and especially a lamp is turned off/on from the switch? i.e. someone disconnected it from the power source and connected it back?

I would like to detect when the lamp is switched off/on from the switch and change its state in HA.
If it’s turned off from the SW turn in on and change it’s colour to bright white.

Might be a tough one to do. Since you tagged MQTT in your post, I am making a guess that are using Zigbee2MQTT. In general, I think zigbee devices have a regular ‘check in’ schedule if they are just idle. Unfortunately, from my observations it is up to the firmware in each product to choose the interval. For example, and I am using ZHA, so maybe different in Zigbee2MQTT, but my Cree lightbulbs will go 60 minutes between check in, where as my OSRAM lightbulbs check in every minute. So this seems the first challenge, could be 60 minutes before I know the device is missing. There are low level ways to ‘ping’ devices, but I am not sure how or if that would be possible in some type of automation. And you are adding traffic to your network that might cause problems. Next challenge is to get notified when a device comes online. This is possible thru web socket calls on ZHA and probably some way in Zigbee2MQTT. Seems what you are planning would require a fairly sturdy state machine model, if you you can get access to the needed state change events. Hope you can find a way as this would be very useful.

If you are using Zigbee2MQTT setting the availability timeout in seconds in the configuration file will give you this. I have mine sent to 10 minutes.

availability_timeout: 600

What will it give exactly ? What is the behaviour when the timeout is reached ? :slight_smile:

If you have the Availability sensor in HA then you can generate an alert automation if it goes “offline”

This is my configured sensor as an example.

- platform: mqtt  
  state_topic: "zigbee2mqtt/Bathroom Light" 
  name: "Bathroom Light Status"  
  value_template: '{{ value_json.availability }}'


1 Like

Nice, thank you.

Wish that was exposed as an attribute in ZHA. Learning the differences between the various zigbee implementations… Thx!

1 Like

With ZHA, you can determine if a device has gone offline (I.E. switch is powered off).
Offline devices have their state set to ‘unavailable’ (while normal values are ‘on’ or ‘off’). But as mentioned above, you have to wait for the respective devices’ timeout for it to show in that state

1 Like


Thank you all for your replies.
I started to understand how Zigbee devices work and their limitations.
My intend is to add new functionality without removing existing functionality.

I guess I can leave the wall switches always on and control the lamps via software or Zigbee switches.
But what happens when the home automation system is down for whatever reason?

Do you have any smart light switch to suggest?
** That can work as dumb switches when HA is down?

Any Updates Here with zha? Have 4 ikea led Power supplies, one on switch, would be nice if others could be remotly switsched on and of via on on switch