Using Zigbee online status of bulb as trigger with MQTT

Hi everyone,
this is my first post here, though I am reading posts in here for a while and did manage to get my problems normally solved with this easily.

For today I have a problem I am trying to figure out since a couple of days and did not manage so far.

First my Setup: I am using HASS OS on a Raspberry pie 4 wit a dedicated Vlan and Wifi for it and all Automation things. I am currently slowly building up, I started first by adding a SonOff Zigbee bridge and flashed it with Tasmota, I am using it via MQTT to integrate it in ZHA.

I have a few motion sensors that work fine, but I also have already motion sensors installed in front of the house in 2 out of 6 Lamps (All Zigbee enabled and linked). I would like to use those two lamps as trigger for the others, since they are switched off when there is no motion it seems the first idea of a trigger on the status “on” does not work. I would need a trigger aiming at the MQTT Status.

I did find this Topic, which I hoped would be enough to solve my problem: Trigger automation when device becomes online - #8 by BooBoss
I guess this is how I should do it, now I am trying to figure out what the topic is that I need to trigger. I did open Mosquitto broker on HA and listened to the Topic “#” - with the result of a lot of information. I figured out it was most likely one of these messages that was indicating the switched on light

Message 2 received on tele/zigbridge/LWT at 13:09:


What I seem not to be able to extrapolate from this is the device ID and I am a bit lost at how to use it. I tried to use the trigger MQTT, Topic tele/zigbridge/LWT and Status Online to no avail.

My logic tells me that the topic must be wrong, I highly doubt any device is registered with such a simple Identifier?

So I guess I need a bit of support in finding out how to identify the correct MQTT topic, that - in case all the other thoughts were correct - should solve my problem.

Thanks so much for reading, I hope this was detailed enough to understand.

Best regards, Fripi

Yes, it looks like the “I am online” message of your Zigbee controller, not of the lights (the “LWT” in the topic stands for “Last Will and Testament”, which is a way for MQTT brokers to track, and tell other MQTT clients, if a device is connected (“Online”) or not (“Offline”)). So this message is not useful for what you’re trying to accomplish.

However, there’s another issue in your setup, in that (from what I understand) your lights are being switched on/off by physical means (switching the power to the light). Zigbee devices should always be powered, otherwise they will drop off the network (potentially causing problems because other devices rely on them to pass their messages back to the controller) and it may take some time before the Zigbee controller will inform you of its state, making it rather useless for motion sensing (which is probably also why “a trigger on the status “on” doesn’t work”, as you say).

1 Like

Thanks for the support, Robert.

You understood correctly and I know that this is not the ideal setup, but thats what I have got and will not be able to change too soon.

The Zigbee network is quite dense in these areas, as mentioned before 4 out of 6 lights are always powered on. So I doubt that will have any interference. Also I understood that the network is mainly established around the active nodes, a node just available 20 minutes a day should not be included, I would guess.

I was wondering about that but the before mentioned post also said this about it:

So as far as I understand there should be no problem with motion sensing, I can easily live with 3 seconds of delay. I am just really not getting how to find the correct topic.

I am currently running MQTT Explorer but still cant figure out how to find the correct topic. I am reading up on MQTT as much as possible, but it seems to be a problem that does not occur to often :smiley:

Will update if I manage this. Thanks so far.

It’s not a matter of interference, it’s a matter of end devices (battery powered Zigbee devices, like sensors) being connected to a light that gets powered down. Those end devices will lose their connection with the Zigbee network, and for some brands, these devices will not start looking for another connection.

From what I understand, that post refers to devices running Tasmota (so WiFi lights/switches/etc that run Tasmota), not Zigbee devices that are being handled by a Tasmota device.

If you don’t see any messages appearing on topic # (which basically matches all topics) then it’s not going to work.

Ah yes, thank you, my wording was wrong here. I am rather sure that the routes will not be a problem due to the many options that are online 24/7. But will keep that in mind. I currently only have a Zigbee LED which is in this socket right now and registered in my network. If that would be a problem I could maybe delete the registration.

My problem is more that I have far too many messages and am not sure how to sort them and I also cant seem to find the topic in the overview.

So to find the correct Topic (Assuming it exists) would be then found by logging in, opening Configuration - Mosquitto - Listening to topic “#” and then turning on the Lightbulb, correct? And one of the messages I see would be the correct one, assuming I see something.

I am just confused as I get output like this

Message 25 received on cmnd/zigbridge/STATUS at 18:15:
QoS: 0 - Retain: false

Message 24 received on tele/zigbridge/LWT at 18:14:
QoS: 0 - Retain: true

Message 23 received on tasmota/discovery/E8DB849E1D05/sensors at 18:14:
    "sn": {
        "Time": "2022-04-29T08:18:16"
    "ver": 1
  • On my way to turn on the lightbulb (well, too jump up and down in front of it) I pass by another sensor that turns on the light, that works - but also this I cannot seem to find, hence my disbelief that there is nothing. I guess I am doing something wrong since I also have no Idea which of these could be the actual motion detector. Also I am missing out where I can actually find the ID, for example in tasmota/discovery/E8DB849E1D05/sensors I understand that a message was sent to this topic with the content of (Time) - but where exactly did it come from?

However, thanks for helping again, I am okay if it doesn’t work in the end but I can wrap my head around what I am seemingly not understanding. MQTT seems to be straight forward, but I obviously dont get it yet :laughing:

While trying to research more I also found this here Detect online/offline state of ikea zigbee bulb - #27 by santik where the question of status is raised as well. I observed the behaviour of my HASS panel as well and found that it also just lists the bulb as online after power is disconnected, thereforean automation on the power on status cant work. Maybe I can use the Availability timeout to make sure the status switches back to offline - and then the trigger might actually work :smiley:
Availability timeout mentioned here: Zigbee2mqtt light still showing up even when powered off

Guess I will try that now, having a problem is always a great learning opportunity :slight_smile:

If you use the Sonoff zbbridge with ZHA, the only mqtt messages you receive are about the zbbridge itself. The Zigbee devices talk to ZHA, so no mqtt involved.