Template Light Error

So, here’s my Template Light:

- platform: template
  lights:
    escritorio_luzteto:
      friendly_name: "Luz Teto"
      level_template: "{{ state_attr('light.escritorio_lteto2', 'brightness') | int }}"
      value_template: "{{ is_state('switch.escritorio_interruptorparede_l2', 'on') }}"
      temperature_template: "{{ state_attr('light.escritorio_lteto2', 'color_temp') }}"
      color_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') | float}}"
      turn_on:
        - service: switch.turn_on
          entity_id: switch.escritorio_interruptorparede_l2
      turn_off:
        - service: switch.turn_off
          entity_id: switch.escritorio_interruptorparede_l2
      set_level:
        - service: light.turn_on
          data_template:
            entity_id: light.escritorio_lteto2
            brightness: "{{ brightness }}"
      set_temperature:
        - service: light.turn_on
          data_template:
            entity_id: light.escritorio_lteto2
            color_temp: "{{ color_temp }}"
      set_color:
        - service: light.turn_on
          data_template:
            hs_color:
              - "{{ h }}"
              - "{{ s }}"
            entity_id: light.escritorio_lteto2

Everything works - except I have no effects or transitions - until I include the line

effect_list_template: "{{ state_attr('light.escritorio_lteto2', 'effect_list') }}"

Which is copied directly from Template Light - Home Assistant

I get the error “Invalid config for ‘template’ from integration ‘light’ at lights.yaml, line 3: some but not all values in the same group of inclusion ‘effect’ ‘lights->escritorio_luzteto->’, got None” when I check the configuration.

I’m a bit puzzled.

Help?

With what? Everything works except effects, until you include the line that lists available effects, then it all works?

What is the problem / error?

EDIT: I see you’ve now edited the post to explain the problem.

What does this return in Developer Tools / Template?

{{ state_attr('light.escritorio_lteto2', 'effect_list') }}

Yeah, sorry, the line wasn’t in bold on the code so I reformatted the post.

That line alone shows:

Result type: list
[
“blink”,
“breathe”,
“channel_change”,
“finish_effect”,
“okay”,
“stop_effect”
]
This template listens for the following state changed events:

Entity: light.escritorio_lteto2

You’re missing the set_effect: entry in the configuration. Try adding that (it’s in the example on the Template Light page).

It’s not the most useful error message…

That wasn’t it.

Current code:

- platform: template
  lights:
    escritorio_luzteto:
      friendly_name: "Luz Teto"
      level_template: "{{ state_attr('light.escritorio_lteto2', 'brightness') | int }}"
      value_template: "{{ is_state('switch.escritorio_interruptorparede_l2', 'on') }}"
      temperature_template: "{{ state_attr('light.escritorio_lteto2', 'color_temp') }}"
      color_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') | float}}"
      effect_list_template: "{{ state_attr('light.escritorio_lteto2', 'effect_list') }}"
      turn_on:
        - service: switch.turn_on
          entity_id: switch.escritorio_interruptorparede_l2
      turn_off:
        - service: switch.turn_off
          entity_id: switch.escritorio_interruptorparede_l2
      set_level:
        - service: light.turn_on
          data_template:
            entity_id: light.escritorio_lteto2
            brightness: "{{ brightness }}"
      set_temperature:
        - service: light.turn_on
          data_template:
            entity_id: light.escritorio_lteto2
            color_temp: "{{ color_temp }}"
      set_color:
        - service: light.turn_on
          data_template:
            hs_color:
              - "{{ h }}"
              - "{{ s }}"
            entity_id: light.escritorio_lteto2
      set_effect:
          - service: light.turn_on
            data:
              entity_id:
                - light.escritorio_lteto2
              effect: "{{ effect }}"
      supports_transition_template: "{{ true }}"

Error form that code on Developer/Templace:

ValueError: Template error: int got invalid input ‘None’ when rendering template ‘- platform: template lights: escritorio_luzteto: friendly_name: “Luz Teto” level_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘brightness’) | int }}” value_template: “{{ is_state(‘switch.escritorio_interruptorparede_l2’, ‘on’) }}” temperature_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘color_temp’) }}” color_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘hs_color’) | float}}” effect_list_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘effect_list’) }}” turn_on: - service: switch.turn_on entity_id: switch.escritorio_interruptorparede_l2 turn_off: - service: switch.turn_off entity_id: switch.escritorio_interruptorparede_l2 set_level: - service: light.turn_on data_template: entity_id: light.escritorio_lteto2 brightness: “{{ brightness }}” set_temperature: - service: light.turn_on data_template: entity_id: light.escritorio_lteto2 color_temp: “{{ color_temp }}” set_color: - service: light.turn_on data_template: hs_color: - “{{ h }}” - “{{ s }}” entity_id: light.escritorio_lteto2 set_effect: - service: light.turn_on data: entity_id: - light.escritorio_lteto2 effect: “{{ effect }}” supports_transition_template: “{{ true }}”’ but no default was specified

OK, you are misunderstanding what a template is. A template is Jinja code, and is just the bit in {{ ... }}. Developer Tools / Template is just for testing those bits.

However, as you are getting that specific error, it’s pointing me towards the |int and |float filters in the top of the config — one of those is being fed something non-numeric.

One of those is in color_template, which the documentation doesn’t list as an acceptable entry for a Template Light. Where has that come from?

image

I think that should be hs_template. Change the title, and remove the |int and |float (not needed for attributes as they can be real numbers):

      level_template: "{{ state_attr('light.escritorio_lteto2', 'brightness') }}"

and

      hs_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') }}"

That bit come from Using a Template Light to Control a Custom Light in Home Assistant - James Ridgway.

As I said on the original post, everything works except transitions with that code.

So what happens if you put that code into lights.yaml and check it?

With the original code, I get:

ValueError: Template error: float got invalid input ‘(26.827, 35.453)’ when rendering template ‘- platform: template lights: escritorio_luzteto: friendly_name: “Luz Teto” level_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘brightness’) | int }}” value_template: “{{ is_state(‘switch.escritorio_interruptorparede_l2’, ‘on’) }}” color_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘hs_color’) | float}}” temperature_template: “{{ state_attr(‘light.escritorio_lteto2’, ‘color_temp’) }}” turn_on: - service: switch.turn_on entity_id: switch.escritorio_interruptorparede_l2 turn_off: - service: switch.turn_off entity_id: switch.escritorio_interruptorparede_l2 set_level: - service: light.turn_on data_template: entity_id: light.escritorio_lteto2 brightness: “{{ brightness }}” set_temperature: - service: light.turn_on data_template: entity_id: light.escritorio_lteto2 color_temp: “{{ color_temp }}” set_color: - service: light.turn_on data_template: hs_color: - “{{ h }}” - “{{ s }}” entity_id: light.escritorio_lteto2’ but no default was specified

But light itself works flawlessly.

Basically, I’m just trying to create a light that turns on\off on a wall switch (switch.escritorio_interruptorparede_l2) and everything else gets sent to the lamp (light.escritorio_lteto2) to handle.

I don’t know how else to say this.

This template, which you have in color_template but I think should be in hs_template:

{{ state_attr('light.escritorio_lteto2', 'hs_color') }}

is returning a tuple: (26.827, 35.453). Your version of the code is unnecessarily trying and failing to turn that into a float:

color_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') | float}}"

Please replace that line in lights.yaml with this:

hs_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') }}"

and see what the configuration check says.

Better!

Says " ‘s’ is undefined "

I’m still unable to add the effects line and get transitions though.

Which it is, as a raw template. That config isn’t intended to be pasted in full into the template editor.

Put it in lights.yaml and try it.

It’s working the same as before… I still can’t get the effects line in and I can’t get transitions from the lamp when Adaptive Lightning takes over.

Reading through that code a bit more: we’ve fixed the obvious error, but it’s out of date to the current system, showing the problem with using examples outside the official documentation.

Put this in lights.yaml in place of your existing code (not the template editor) and see what the config checker says:

- platform: template
  lights:
    escritorio_luzteto:
      friendly_name: "Luz Teto"
      level_template: "{{ state_attr('light.escritorio_lteto2', 'brightness') }}"
      value_template: "{{ is_state('switch.escritorio_interruptorparede_l2', 'on') }}"
      temperature_template: "{{ state_attr('light.escritorio_lteto2', 'color_temp') }}"
      hs_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') }}"
      effect_list_template: "{{ state_attr('light.escritorio_lteto2', 'effect_list') }}"
      effect_template: "{{ state_attr('light.escritorio_lteto2', 'effect') }}"
      turn_on:
        - service: switch.turn_on
          target:
            entity_id: switch.escritorio_interruptorparede_l2
      turn_off:
        - service: switch.turn_off
          target:
            entity_id: switch.escritorio_interruptorparede_l2
      set_level:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            brightness: "{{ brightness }}"
      set_temperature:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            color_temp: "{{ color_temp }}"
      set_hs:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            hs_color:
              - "{{ h }}"
              - "{{ s }}"
      set_effect:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            effect: "{{ effect }}"
      supports_transition_template: "{{ true }}"

Configuration warnings

Invalid config for ‘template’ from integration ‘light’ at lights.yaml, line 3: some but not all values in the same group of inclusion ‘effect’ ‘lights->escritorio_luzteto->’, got None

Done some reading: you also need to include effect_template, which I’ve added to the code above. I’m assuming your light has an effect attribute. If it doesn’t, we’ll have to think again.

That’s what the (inclusive) means against the options:

image

and what the mysterious “group of inclusion” is talking about in the error message.

Ok, great! Effects are now working.
However, I’m somehow unable to get transitions still.

Current code:

- platform: template
  lights:
    escritorio_luzteto:
      friendly_name: "Luz Teto"
      level_template: "{{ state_attr('light.escritorio_lteto2', 'brightness') }}"
      value_template: "{{ is_state('switch.escritorio_interruptorparede_l2', 'on') }}"
      temperature_template: "{{ state_attr('light.escritorio_lteto2', 'color_temp') }}"
      hs_template: "{{ state_attr('light.escritorio_lteto2', 'hs_color') }}"
      effect_list_template: "{{ state_attr('light.escritorio_lteto2', 'effect_list') }}"
      effect_template: "{{states('light.escritorio_lteto2')}}"
      turn_on:
        - service: switch.turn_on
          target:
            entity_id: switch.escritorio_interruptorparede_l2
      turn_off:
        - service: switch.turn_off
          target:
            entity_id: switch.escritorio_interruptorparede_l2
      set_level:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            brightness: "{{ brightness }}"
      set_temperature:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            color_temp: "{{ color_temp }}"
      set_hs:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            hs_color:
              - "{{ h }}"
              - "{{ s }}"
      set_effect:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            effect: "{{ effect }}"
      supports_transition_template: "{{ true }}"

Ok, that seems to be a problem with the Light Group light.escritorio_lteto2.

It’s a group of 3 lamps. I can get transitions when I call them on a single lamp but if call them on the group I don’t. Guess it’s a different issue so I’ll open another thread.

Thanks for your help!

Your Template Light config doesn’t currently have any transition code. Try adding a line to the set_hs: section:

      set_hs:
        - service: light.turn_on
          target:
            entity_id: light.escritorio_lteto2
          data:
            hs_color:
              - "{{ h }}"
              - "{{ s }}"
            transition: "{{ transition|float }}"

That’s as per the docs. I don’t have any lights with transitions, so just based on those.

Also, your effect_template isn’t as I suggested. If it works, then fine :slight_smile: .

I think the transition is another issue because I tried the call service through Developer Options and couldn’t get it to work. I’ve tried adding that transition bit to the code and it doesn’t work on brightness or temperature (which are the main ones I’ll use).

I’ve corrected the effect_template. Missed the part where you edited the previous post.

1 Like