Test if Tradfri light is available/reachable?

That doesn’t work.
Hub is smart enough to not send the same info to the bulb.
You have to change the brightness.
What I did, create a script:

alias: Control IKEA light
sequence:
  - if:
      - condition: template
        value_template: "{{ states(light_name) != 'unavailable' }}"
    then:
      - if:
          - condition: template
            value_template: "{{ states(light_name) == 'on' }}"
        then:
          - if:
              - condition: template
                value_template: "{{ state_attr(light_name,'brightness') > 1 }}"
            then:
              - service: light.turn_on
                data:
                  brightness: "{{ state_attr(light_name,'brightness') - 1 }}"
                target:
                  entity_id: "{{ light_name }}"
              - delay:
                  milliseconds: 100
              - service: light.turn_on
                data:
                  brightness: "{{ state_attr(light_name,'brightness') + 1 }}"
                target:
                  entity_id: "{{ light_name }}"
            else:
              - service: light.turn_on
                data:
                  brightness: "{{ state_attr(light_name,'brightness') + 1 }}"
                target:
                  entity_id: "{{ light_name }}"
              - delay:
                  milliseconds: 100
              - service: light.turn_on
                data:
                  brightness: "{{ state_attr(light_name,'brightness') - 1 }}"
                target:
                  entity_id: "{{ light_name }}"
        else:
          - service: light.turn_off
            data: {}
            target:
              entity_id: "{{ light_name }}"
mode: parallel
icon: mdi:lightbulb-question-outline
max: 50

Then call the script in your code:

alias: "[Contols] Check IKEA lights"
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition: []
action:
  - repeat:
      sequence:
        - service: script.turn_on
          target:
            entity_id: script.control_ikea_light
          data:
            variables:
              light_name: "{{ repeat.item }}"
      for_each: >-
        {{ expand('light.ikea_lights') |
        map(attribute='entity_id') | list }}
mode: single

I’m using a group that contains all my IKEA lights `light.ikea_lights

Explanations: if light is off, I off it. If it is on, I change the brightness by “1” up or down to not off it nor exceed 255 and back.

This force a message to the light and if it doesn’t work, it is marked as unavailable by HA.

1 Like