Detect online/offline state of ikea zigbee bulb

Hello Community,
I need to detect if light is switch ON or OFF in one of my rooms.
I have a bulb from Ikea and it is connected to hassio via zigbee2mqtt. It works just like a regular bulb with the regular switch (together with other bulbs in that room). I want to detect if my (regular)switch is in OFF or ON state.
As I understand bulb should be offline if switch is OFF and online if switch is ON But I couldn’t find a way how to detect this state of the bulb.
Is there some solution for that?

No one knows or it is just a stupid question?
Maybe other ways to detect if light is switch ON/OFF with minimum setup?

Using deCONZ the light would be marked as unavailable in HASS. Can’t say for Z2M

With Tradfri gateway the state is also ‘unavailable’ when the physicial switch is turned off. I also don’t know about Zigbee2MQTT.

I think the template to detect what you are asking for would be:

{{ not is_state('light.leeslampen_woonkamer','unavailable') }}

You can use that template e.g. in a template sensor:

  - platform: template
        friendly_name: "Wall switch"
        value_template: "{{ not is_state('light.leeslampen_woonkamer','unavailable') }}"

Unfortunately it doesn’t report state “unavailable”. Looks like it keeps the last state when it was online.

Perhaps this is of use? Test if Tradfri light is available/reachable?

yes, this works just fine. idea: turning on a light, that is not powered forces the state ‘unavailable’ to show.

let me know if it works out for you

It doesn’t work because if it was cut off in ON state. You can not switch it off. It still reports as ON.
Other way around as well.

the automation doesn’t switch off, it switches on. If, doing so, the light is unavailable , which it is when cut off, it should show unavailable…
thats the whole purpose of the automation.

just to be sure, this is the automation working just fine:

  - alias: 'Tradfri parking light shows unavailable'
    id: 'Tradfri parking light shows unavailable'
#    initial_state: 'on'
      platform: time_pattern
      minutes: '/5'
      seconds: 00
      - condition: template
        value_template: >
          {{ states('light.parking_light') !='unavailable' }}
      - condition: template
        value_template: >
          {{ is_state('binary_sensor.outside_daylight_sensor','on')}}
      service: light.turn_on
        entity_id: light.parking_light
        brightness: >
          {{state_attr('light.parking_light','brightness') |int }}
1 Like

This automation doesn’t do what you describe for me.
I see in zigbee2mqtt logs that it tries to change the state. But lamp doesn’t get “unavailable” state in hassio.

Well, what can I see, it does in my setup

This light is cutoff power daily and set to unavailable using this automation.

That’s super strange. Which version of zigbee2mqtt you are using?

I don’t. Use the IKEA Hub

C’mon! The thread is about zigbee2mqtt integration. Sometimes its better to read before commenting.

please behave.
in the first place was I tagged, and responded to that.
secondly this thread is not about zigbee2mqtt, there’s another thread about that indeed. not here. title is self explanatory.
thirdly, I was trying to help.

hope you will find your answer.

1 Like