Template Light - State

Hi Everyone,

Need to preface this with I am fairly new to HA.
I have a pendant light that can only be controlled via RF. I have been able to create a script to handle light actions but can’t seem to keep track of the Light’s state.

Template Below:

light:
  - platform: template
    lights:
      family_room_fan_light:
        friendly_name: "Family Room Fan Light"
        unique_id: 999999003
        value_template: "{{ states('light.family_room_fan_light_state') == 'on' }}"
        turn_on:
          service: script.family_room_fan_light_actions
          data:
            action: "on"
        turn_off:
          service: script.family_room_fan_light_actions
          data:
            action: "off"

Light State Showing on HA as “OFF”, attempting to turn it on does turn it on but it does not change the state.

Any assistance would be greatly appreciated.

Is there actually an entity light.family_room_fan_light_state and where does it gets its state value?

Goes to show I have no idea what I’m doing =P. I thought the value template line defined the entity and tracked the state.

The value_template is what defines the state that the Template light entity is shown to have.

If you don’t have a way to determine whether the light is actually on or off you can leave value_template out of the configuration; Home Assistant will use “optimistic mode” to determine what state the Template light entity is shown to have. It’s better than nothing, but it is prone to be unreliable if you use anything but HA to turn the light on and off.

1 Like

Hi Luks017,

Ya, what he said. I have some RF433 stuff and it is fire and forget, no feedback.
Your best practice is to send the code 3 or more times and then assume it got there.
It’s all you got unless you build a sensor that watches the bulb to know somehow it is on or off…