Can I use input_select in time_pattern for the automation?

This is a automation which works but here I have fixed value of the time_pattern:

alias: 00_TMP - color change
trigger:
  - platform: time_pattern
    seconds: '/5'
action:
  - service: light.turn_on
    data:
      entity_id: light.spare
      color_name: '{{ states(''input_select.light_color_5'') }}'
  - service: input_select.select_next
    entity_id: input_select.light_color_5
mode: single

but I would like to setup seconds interval based on below input_select:

  light_color_change_time:
    options:
      - 2
      - 3
      - 5
      - 10
      - 20
      - 30
      - 60
      - 120
      - 300 

so the automation looks like below but it doesn’t work:

alias: 00_TMP - color change
trigger:
  - platform: time_pattern
    seconds: '/{{ states.input_select.light_color_change_time.state }}'
action:
  - service: light.turn_on
    data:
      entity_id: light.spare
      color_name: '{{ states(''input_select.light_color_5'') }}'
  - service: input_select.select_next
    entity_id: input_select.light_color_5
mode: single

Any idea what is wrong?

Time pattern triggers do not support templates.

Instead of a Time Pattern Trigger (which doesn’t support templating, like tom_I said) here is an alternative method of changing a light’s color on a periodic basis.

Create an input_boolean called input_boolean.color_changer.

  • When the input_boolean is turned on it will trigger the automation (shown below) and start the color-changing process (the color changes according to the time specified by input_select.light_color_change_time).
  • When turned off it will stop the color-changing process.
alias: 00_TMP - color change
trigger:
- platform: state
  entity_id: input_boolean.color_changer
  to: 'on'
action:
- repeat:
    while: "{{ is_state('input_boolean.color_changer', 'on') }}"
    sequence:
    - service: light.turn_on
      data:
        entity_id: light.spare
        color_name: "{{ states('input_select.light_color_5') }}"
    - service: input_select.select_next
      entity_id: input_select.light_color_5
    - delay:
        seconds: "{{ states('input_select.light_color_change_time') }}"
mode: single
1 Like

@123 Thank you for the example, I made a small adjustments and it works as expected. Thank you :slight_smile:

alias: 00_TMP - color change
trigger:
  - platform: state
    entity_id: input_boolean.color_change
    to: 'on'
action:
  - repeat:
      while:
        - condition: template
          value_template: '{{ is_state(''input_boolean.color_change'', ''on'') }}'
      sequence:
        - service: light.turn_on
          data:
            entity_id: light.spare
            color_name: '{{ states(''input_select.light_color_5'') }}'
        - service: input_select.select_next
          entity_id: input_select.light_color_5
        - delay: '{{ states(''input_select.light_color_change_time'') }}'
mode: single