How to check a device still online in the ZigBee network

I hope someone can help me with the following situation.
I have a few Ikea lighbulbs that I can control with Homey, and working to satisfaction. However, I also believe that the normal lightswitch should be working as everyone in the house is used to, and I am not planning to replace my switches around the house with Zwave or other intelligent switches. So, when the power is turned off by the switch the light goes off and when turned on the light goes on. So far so good. However that status change of the power is not registered in Homey (understandable).
With WIFI connected (xiaomi) light bulbs I use the Smart Presence app to test a device is offline or online, so I can sync the status with the power status and enable scenes when power is turned off/on.
Is there is similar possiblity with Zigbee devices, to be developed perhaps, to test if a light is offline/online in the zigbee network (ie. being powered on or not)?

1 Like

Hi Oscar,
I also have Tradfri bulbs, but not controlled by Homey yet. My experience with only the Ikea dimmer is that the bulbs DO remember the last state if they are switched off and on by a physical switch.
Isnā€™t there a setting in the Homey Tradfri app or with the devices itself that you can or need to adjust?

Peter,
There are no separate settings in Homey for this as far as I could find out.
I am also not looking to the lights to be restored to the state they were in; turning on the power should just turn on the light by default.
I am looking for a solution that homey knows (by a ping?) that a device is offline (powered off), so that when it comes back online that I can have an action triggered or control ā€œlights outā€ via Homey or Alexa. Currently the device remains ā€œonā€ in homey when power goes off, so no flows are triggered. If I can test the online vs offline status I would have a way of detecting the power is off, so in Homey it should be off as well.

Ah, ok, mis-interpreted that. Alas, i wouldnā€™t know if that is possible or how to do that.

I just checked with the Tradfri gateway, and it looks like that device doesnā€™t really notice that the power has been removed from a bulb either (I waited for about 5 minutes). Only when you make it send a command to a bulb it will notice and mark the device as offline.

So I donā€™t think that there is a sort of ā€œpingā€ signal that can be used to check if devices are still online or not.

It seems the gateway is more aware than Homey.
With Homey I can send any command to the light bulb and it will not change status.
Perhaps with the gateway, if it regularly sends a command (which one?), it will see the status being offline or online. Could you test this?

While it might at least be a work-around for my Ikea bulbs, I would still hope that basic capability could be provided native from Homey or through some of the apps.

If I try to change either the on/off status or the dim value (from Homey using the gateway app), the gateway will notice that the device is offline in about 10 seconds. The Homey gateway app marks the device as ā€œunavailableā€ at that point.

And the other way around works too: if I switch on the bulb, it takes about 5 seconds for the gateway and Homey to notice itā€™s back online again.

In theory, you could periodically send a ā€œdimā€ command containing the same dim value that itā€™s already set to, or an on/off command with the same state as when the bulb was last seen, to force a status update. However, I donā€™t know if Homey, or the gateway app or the gateway is smart and see that youā€™re setting the dim value to exactly the same value, and just ignore it. Donā€™t have time to test that now

That seems to work as expected: Iā€™m running a flow that sets the brightness of the lamp to the value it had last (using a tag), and when the bulb is turned off, itā€™s marked offline in about 10 seconds.

Robert, Thank you.
It looks that the Tradfri gateway indeed is doing the trick. Very nice.

I am keen to see if there may be other solutions working with Homey natively - which I would still prefer.

when the power goes out, is there a clever way to tell Homey to give a command to all lights ikea equal to the last status in memory on homey?
so if I shorten that the current returns I do it by hand.
if then there was a way to understand when homey comes back online giving it automatically

I donā€™t think thereā€™s a way to do that. Some lights (I think the Hueā€™s) can be configured to remember their last status, perhaps the IKEA lights can do the same?

Yes they do.

1 Like

The Tradfri bulbs do that by default, either when powered off by remote (and still connected to 230v) or by switching them off completely with a switch or plug (no 230v).

but only if you use the ikea hub. if you connect directly to Homey without ikea hub doesnā€™t work.
when the power go off and on (eg blackout) the homey see the light ikea off, but the light are on.
I use the app:

IKEA TrƄdfri

by Athom B.V. v1.4.2 - 13.09.19

Let me dig this topic out - Iā€™m also interested in tracking the state of zigbee bulbs (tradfri, hue, osram) which can be disconnected from electricity. I have two use cases:

  • Possibility to check if I have turned the lights off when I left home
  • Creating a flow with ā€œbulb has been turned onā€ event as a trigger

Unfortunately it seems like neither case can be right now achieved using Homey :frowning: Even when I periodically send ā€œdimā€ command (or whatever else) - no matter if I connect bulbs to Homey directly or using Hue bridge, Homey never mark them as unavailable.

This is what happens:

  • Bulbs connected to Homey directly: when I try to dim the disconnected bulb from Homey UI, it shows red error message, the new state is not remembered, but the device is still marked as available. When I dim the bulb from the flow, the new state is not remembered, but the device is still marked as available.
  • Bulbs connected to Hue bridge: when I try to dim the disconnected bulb from Homey or from the flow, it doesnā€™t even show the red error message, the new state is remembered, everything behaves as if the change has actually happened! What really makes me mad is the fact, that the Hue bridge CAN DETECT offline devices within seconds - I donā€™t know how it does it, but when only I disconnect the device, the Hue app displays ā€œunavailableā€ text next to this light. Maybe the Hue bridge periodically sends some kind of ping to bulb?

One workaround for bulbs connected to Homey directly is to periodically try do dim it by 1% - ex. from 100% to 99% - and then check if the state is remembered. However it requires a lot of flow cards, just to check one single bulb, I donā€™t know how could I parametrize it - and the result can only be stored inside variable, the UI is still incorrect.

If anybody finds the solution, Iā€™m very interested in it!

In Domoticz i had implemented an enhanced Dzvents script that would get a JSON from the HUE bridge every minute. in this JSON the state of each lamp is described, included if they were available (reachable). The results would be stored in a table and if a lamp was not ā€œseenā€ every minutes for 5 minutes, the lamp was turned off.
Iā€™m sure the same can be done on Homey, it is just that my java script knowledge is non-existent.

The original dzVents script can be found here: (it is the third script, which does not have any dependencies https://www.domoticz.com/wiki/Simple_script_to_update_Philips_Hue_status

In short the url to get the complete light status overviewcis
http:///api/0yBVz2bSgFmPfsMieO4NecDuIfwJPERlfOA8CZO-N/lights
where you have to put your own IP address for the bridge (so that has to become static) and your HUE-bridge key (token).
See https://www.sitebase.be/generate-phillips-hue-api-token/ to get the token.

Next the returned JSON has to be transformed into a table.
and for each lamp in the table the ā€˜stateā€™ has to be checked: if the state.reachable == false while homey/HUE==ON it needs to be turned off, to sync the HUE state to the IRL state.
In the script the ā€œstate.onā€ is also checked and synced. (in case the lights are switched outside Domoticz. Not sure if this is also needed for Homey?

Quoted from the the dzVents script (which is based on/built on LUA)

           for i, light in pairs(lights) do
                if (domoticz.devices( light.name ) ~= nil) then
                    local device = domoticz.devices( light.name )
                    if( light.state.on == true and device.state == 'Off') then
                        device.switchOn()
                    elseif( light.state.on == false and device.state == 'On') then
                        device.switchOff()
                    elseif( light.state.reachable == false and device.state == 'On') then
                        previousData.add( light.name )

Then the script has some extra bits with a persistent table, so that only when a light is not reachable for 5 consecutieve minutes, it will be turned off. To prevent a lamp is switched of in the first minute when a connection fails. The on/off syncing was done in the first minute.

I hope one of you could take the above to create some script? (fingers crossed). Alternatively

For hue, this will help you:

http://yourhuebridgeip/debug/clip.html
In the window you see, post to /API:
{ā€œdevicetypeā€: ā€œmy_playground#blablaā€}
Do this after you pushed the blue button on the bridge.

This way you will get the username you need to perform these actions:

https://developers.meethue.com/develop/hue-api/lights-api/

(Make sure to create a developers account to get in that api docs)

Then, make sure you can with with the better logic app (in combination with the Http flow cards). To get the light reachable status.

In Http flow cards, use under ā€œthenā€ the get JSON action.

1 Like

@James_Wyatt Thank you for your contribution, i think this is a very good method in detecting offline Hue devices.

Iā€™m trying to implement your idea but HTTP request flow cards gives an error: Value not found.

Almost thereā€¦ maybe you have a suggestion what could be wrong?

Did you use the correct URL?

Did you use the right lamp? Are you able to access the clip API debugger?

And thanks for the compliment :slight_smile:

In your example i see the URL starts with HTTP instead of HTTPS.

Changed that to make it work. What concerns me, is that the solution is less secure now; my API key is visible with a packetsniffer.

You donā€™t trust your own network?