Template light: Can effect list be hardcoded?

My end goal is to control a IR controlled LED strip with a template light.

What I have so far is this:

  - platform: template
    lights:
      test_light:
        friendly_name: "Test light"
        turn_on:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_on
        turn_off:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_off

        effect_list_template: "{{ ['test', 'test2'] }}"  
        set_color:

What is the correct yaml for a hardcoded effect list?

Docs say:

Defines a template to get the list of supported effects. Must render a list

Isn’t that a list I created?

you can use a template or just output a list

        effect_list_template: "{{ ['test', 'test2'] }}"
        effect_list_template:
        - test
        - test2
        effect_list_template: ['test', 'test2']

They all generate the same error:

If I remove the line with effects list then it works.

You’re looking at the wrong code. That error is talking about turn_off being incorrect. But that may be caused by your next error, which is

This is telling you that you’re missing required keys that pair with template_effect_list

i.e. you’re missing set_effect and effect_template.

There is nothing wrong with the turn on or off.

I can’t get that working hard coded. I had to add a input select to get the template light to work.

Did you read my post fully or are you trying to argue? Your errors are very clear, I explained what they mean and you have to correct them.

Either that or you posted the wrong errors.

But it will not work hard coded.
Try it yourself.

  - platform: template
    lights:
      test_light:
        friendly_name: "Test light"
        turn_on:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_on
        turn_off:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_off
        effect_list_template: "{{ ['test', 'test2'] }}"
        effect_template: "{{ 'test' }}"
        set_color:
        set_effect:
          - service: button.press
            data: {}
            target:
              entity_id: button.david_tv_backlight_{{ effect }}

Which is hard coded list and a hard coded template with a string, as it should?
returns:

2022-09-21 14:11:49.505 ERROR (MainThread) [homeassistant.components.light] Error while setting up template platform for light
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish
await self.async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/components/template/light.py", line 321, in async_added_to_hass
await super().async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 385, in async_added_to_hass
await self._async_template_startup()
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 356, in _async_template_startup
result_info.async_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 934, in async_refresh
self._refresh(None)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1111, in _refresh
self.hass.async_run_hass_job(self._job, event, updates)
File "/usr/src/homeassistant/homeassistant/core.py", line 567, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 321, in _handle_results
attr.handle_result(
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 126, in handle_result
self.on_update(result)
File "/usr/src/homeassistant/homeassistant/components/template/light.py", line 477, in _update_effect
if effect not in self._effect_list:
TypeError: argument of type 'NoneType' is not iterable

in the logs but no notification of the error.

Ah your template isn’t updating because there’s no entity to update it, so it never resolves.

This should work, it’ll update once a minute.

"{{ ['test', 'test2'] or now() }}"

or just use the input_select.


Seems like there needs to be a feature request to allow static lists.

1 Like

:man_shrugging: Don’t know if this is really needed.
I was trying to save in on the input select, but that is really all that is needed to get it working.

  - platform: template
    lights:
      test_light:
        friendly_name: "Test light"
        turn_on:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_on
        turn_off:
          service: button.press
          data: {}
          target:
            entity_id: button.david_tv_backlight_off
        effect_list_template: "{{ state_attr('input_select.david_tv_backlight_effects', 'options') }}"
        effect_template: "{{ states('input_select.david_tv_backlight_effects') }}"
        set_color:
        set_effect:
          - service: button.press
            data: {}
            target:
              entity_id: button.david_tv_backlight_{{ effect }}

Works.

Right, because the template watches an entity and has a resolved solution. If there’s no trigger to update the template, it doesn’t update. A template with {{ ['a','b'] }} has no entities to trigger updates. So it never resolves. I’d argue that it should attempt to resolve on startup, but that doesn’t seem to be the case.