Template to select light profile

I have the automation below that works just fine… only the profile line is ignored. I’m trying to set the profile using an input (so I cant change it at different times of day). At the moment the input is simply set to ‘concentrate’. I’ve re-written this 100 different ways but each time the template part is just ignored (it works if you skip the template bit and just type ‘concentrate’ into the automation file). Any help much appreciated.

- id: '1535320640889'
  alias: Turn on Conservatory light when there is movement
  trigger:
  - entity_id: binary_sensor.conservatory_motion_sensor_fibaro
    platform: state
    to: 'on'
  condition:
  - below: '201'
    condition: numeric_state
    entity_id: sensor.conservatory_motion_sensor_fibaro_luminance
  action:
  - data_template:
      entity_id:  light.conservatory_lights_group
      profile: >
        {states.input_select.time_of_day.state}
    service: light.turn_on
  - data:
      entity_id: input_select.last_room_with_motion
      option: Conservatory
    service: input_select.select_option

Should be:

        {{states.input_select.time_of_day.state}}

Thanks… but Im afraid that hasnt worked either. Full code again in case I did it incorrectly:

- id: '1535320640889'
  alias: Turn on Conservatory light when there is movement
  trigger:
  - entity_id: binary_sensor.conservatory_motion_sensor_fibaro
    platform: state
    to: 'on'
  condition:
  - below: '201'
    condition: numeric_state
    entity_id: sensor.conservatory_motion_sensor_fibaro_luminance
  action:
  - data_template:
      entity_id:  light.conservatory_lights_group
      profile: >
        {{states.input_select.time_of_day.state}}
    service: light.turn_on
  - data:
      entity_id: input_select.last_room_with_motion
      option: Conservatory
    service: input_select.select_option

What do you get if you enter that template into the Template editor?

Confirm that you’re using the exact same names from the built in light profiles csv file, or are you trying to set a scene?

If the latter it’s a different service.

These are the built in names from the csv. The code works fine if I type them in place of the template code. I’m open to alternative solutions (such as setting xy_color directly based on inputs).

Thanks again.

sometimes it is a bit tricky to get templates with input_selects options. Especially when quotes are involved. Are you positive the state of the input_select matches the syntactical requirements of the profile?

I have limited experience with the profiles, and only use 1:

  lights_partying_reset:
    alias: Lights partying reset
    sequence:
      service: light.turn_on
      data:
        entity_id:
          - light.dining_corner
          - light.cabinet
          - light.kist
          - light.home_theater
        profile: relax

which (probably) means there should be no quotes around the profile. Can you confirm the input_select doesn’t have quotes either?

btw you have some (lack of) indentations contrary to what seems to be the default. Not sure if it would help, but just to be sure, try:

- alias: Turn on Conservatory light when there is movement
  id: 'Turn on Conservatory light when there is movement'
  trigger:
    platform: state
    entity_id: binary_sensor.conservatory_motion_sensor_fibaro
    to: 'on'
  condition:
    condition: numeric_state
    entity_id: sensor.conservatory_motion_sensor_fibaro_luminance
    below: '201'
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.conservatory_lights_group
        profile: >
          {{states('input_select.time_of_day')}}
    - service: input_select.select_option
      data:
        entity_id: input_select.last_room_with_motion
        option: Conservatory

Also when i type it into the template editor I get ‘concentrate’ (including the ')

When I type it in directly (ie no template)… it seems to respond fine with and without quotes.

Can you see any error message now in the log, or does it simply do nothing?

you could try the service in the service dev-tools page and see if it results in success or in errors.

like:

if all fails maybe the profile doesn’t accept a template for data? You could then try a service template with 4 little scripts:

  service_template: >
    script.lights_mode_{{ states('input_select.time_of day') }}

and have the 4 scripts script.lights_mode_relax, script.lights_mode_concentrate etc each use the entity_id and profile directly.

  lights_mode_concentrate:
    alias: Lights mode concentrate
    sequence:
      service: light.turn_on
      data:
        entity_id:
          light.conservatory_lights_group
        profile: concentrate

btw, here are the xy settings for the profiles: https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/light/light_profiles.csv

btw 2: I’ve recently rewritten all my state conditions as value_templates, and have positive experience on that regarding readability but also performance. Might be impossible but nonetheless.

So, you could rewrite the condition as:

- condition: template
  value_template: >
    {{states('sensor.conservatory_motion_sensor_fibaro_luminance') | float < 201 }}
1 Like

I would guess that’s your problem. It should not have quotes. How is input_select.time_of_day defined?