How to use value from input_select in automation

Hello everybody,
I try to set up my light in the living room and my idea was to use a input_select to set the brightness. I have set a automation that circles through the states but I am not able to put the input select value in the automation. here is what I have:

input_select.state_light:
  name: Light
  options:
    - 100
    - 75
    - 50
    - 25

automation:
- alias: switch_1
  description: ""
  trigger:
    - device_id: 123456
      domain: abc
      platform: device
      type: remote_button_long_press
      subtype: remote_button_long_press
  condition: []
  action:
    service: input_select.select_next
    entity_id: input_select.state_light

- alias: light_dimming
  description: ""
  trigger:
    platform: state
    entity_id: input_select.state_light
    to: "off"
  condition: []
  action:
    - type: turn_on
      device_id: abcde
      entity_id: light.bulb_1
      domain: light
      brightness_pct: { { states('input_select.state_light') } }
      flash: long
mode: single

Can someone help me to set it up and running?
Best
F

I believe you want this:

- alias: light_dimming
  description: ""
  trigger:
  - platform: state
    entity_id: input_select.state_light
  condition: []
  action:
  - service: light.turn_on
    data:
      entity_id: light.bulb_1
      brightness_pct: "{{ trigger.to_state.state }}"
  mode: single

The State Trigger monitors the state of input_select.state_light. When its state changes, the automation is triggered and executes the service call which sets the light’s brightness to the new state value.

Your version was close but included a few things that were either unnecessary or incorrect.

  • Your State Trigger included to: "off" however input_select.state_light doesn’t have an off value so the automation will never trigger.
  • Your template contains several syntax errors. The correct form would be
    brightness_pct: "{{ states('input_select.state_light') }}"
    but there’s no need to use the states() function because the value you want is already available via the Trigger State Object.
  • You included flash: long and I’m not sure why because you didn’t mention that you wanted the light to flash. If you do, just put that back into the example I posted (below brightness_pct).
1 Like

thank you soo mutch for your help. I corrected my erors and now it is working (almost) perfectly :slight_smile:

I have one last question on the input_states:

I am able to turn the light on and off as well as switch through the cases. The last step I would need to implement is to set the state to a certain case when the light is turned off (or on)

I tried it with this addition in the action:

    - service: input_select.select_option
      data:
        entity_id: input_select.state_light
        option: 100

This solution does not work at the moment. I searched the forum and used google but could not find the error in here :-S

Best
F

okay, my bad… now I understood the docs :slight_smile:

    - service: input_select.set_options
      data:
        entity_id: input_select.state_light
        options: 100

this made the trick :slight_smile:

Thanks for your help :slight_smile:

2 Likes

You’re welcome!

For the benefit of other users, please consider marking my first post with the Solution tag. It will automatically place a check-mark next to the topic’s title. This signals to other users that this topic now has an accepted solution and helps them find answers to similar questions.