Template for a light

I have a IR lamp which i can manage via a broadlink script and a selection list with all the commands, like on, off and some colors like white etc.

With the new posibilities of hass, specialy the area card and area functionality i like to have this IR lamp device recognized like a real lamp so it will go off when all the light off that area goes off.

So i made an extra template light for the IR light. I manage the IR device via a selection/optionlist.

I cant get this template to work. It gives an error that says that state is an invalid option…

- platform: template
  lights:
    usblampdummy:
      unique_id: usblampdummy
      state: >-
        {% if is_state('input_select.usblamp', 'uit') %}
          off
        {% else %}
          on
        {% endif %}
      friendly_name: "usblampdummy"
      turn_on:
        service: input_select.select_option
        data:
          option: flame
        target:
          entity_id: input_select.usblamp
      turn_off:
        service: input_select.select_option
        data:
          option: uit
        target:
          entity_id: input_select.usblamp

You have made a legacy format template light. See the current docs:

and here’s the legacy section:

Note the top-level template: and the state: in the new config, and no friendly_name. Your older config is under light: and would use value_template instead.

Beware copying old forum posts or tutorials, or using AI — always better to consult the current documentation.

i call the light2.yaml from my configuration.yaml like
light: !include light2.yaml and place the code there.

i understand that i have to place the code under template like
template: !include template.yaml
and remove the friendly name in the code

learned again!
and yes, was unaware of using old documentation…

1 Like

You don’t need to remove the friendly_name:, just replace it with name:

Well, you can’t have friendly_name in the config so if suggest that’s the same as removing it, but I take your point… semantics.

The name replaces both the slug (usblampdummy:) and the friendly_name).

1 Like

i have followed the advices and it works! THANK YOU ALL!
Only thing that isnt right yet is the section turn_on and off…
I use service: and the templatedoc says to use action…
Do i have to change this, it does work now :slight_smile:

- light:
    - name: "usblampdummy"
      unique_id: usblampdummy
      state: >-
        {% if is_state('input_select.usblamp', 'uit') %}
          off
        {% else %}
          on
        {% endif %}
      turn_on:
        service: input_select.select_option
        data:
          option: flame
        target:
          entity_id: input_select.usblamp
      turn_off:
        service: input_select.select_option
        data:
          option: uit
        target:
          entity_id: input_select.usblamp

That’s a recent change and the old way still works. Automations used to be written:

action:
  - service: light.turn_on

but now use:

actions:
  - action: light.turn_on

Again, the old way is still supported. I’d update yours to action: but there’s no need to.

yep,did change to action and also removed targetlabel
Works great now!
Thanks again

I

You could simplify your state template to

state: "{{ not is_state('input_select.usblamp', 'uit') }}"

thats nicer code!
Now gonna make my first fan template code!
That has a lamp and a fan in one device.
Thinking about splitting them.
Now learned how to make a light template
thanks again