Help with input_select.select_option based on sensor value automation

Hi all,

I’m having a hard time figuring the error in my syntax. What I am trying to accomplish is selecting one of the four input_select options based on my treadmill power consumption:

alias: Treadmill speed set based on power
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.shelly_vintti_power
    above: '50'
condition:
  - condition: state
    entity_id: input_boolean.treadmill_monitor
    state: 'on'
action:
  - service: input_select.select_option
      option:
        data_template: >-
        {% set treadmill_power = states('sensor.shelly_vintti_power') | float %}
        {% if 0 < treadmill_power < 350 %} 'easy' {% elif 350 < treadmill_power <
        400 %} 'moderate' {% elif 400 < treadmill_power < 450 %} 'threshold' {% else
        %} 'hard' {% endif %}
    entity_id: input_select.treadmill_speed
mode: single

Can someone help me spot the error?

You could try this. Your indents and change data is different than what I use for similar processes:

alias: Treadmill speed set based on power
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.shelly_vintti_power
    above: '50'
condition:
  - condition: state
    entity_id: input_boolean.treadmill_monitor
    state: 'on'
action:
  - service: input_select.select_option
    data:
      entity_id: input_select.treadmill_speed
      option: >-
        {% set treadmill_power = states('sensor.shelly_vintti_power') | float %}
        {% if 0 < treadmill_power < 350 %} 'easy' {% elif 350 < treadmill_power <
        400 %} 'moderate' {% elif 400 < treadmill_power < 450 %} 'threshold' {% else
        %} 'hard' {% endif %}
    
mode: single
1 Like

Try this:

action:
  - service: input_select.select_option
    data:
      entity_id: input_select.treadmill_speed
      option: >
        {% set treadmill_power = states('sensor.shelly_vintti_power') | float %}
        {% if 0 <= treadmill_power < 350 %} easy
        {% elif 350 <= treadmill_power < 400 %} moderate
        {% elif 400 <= treadmill_power < 450 %} threshold
        {% else %} hard
        {% endif %}
1 Like

LOL, your answer popped in at almost the exact same time as mind :smiley:

Yup, saw the same thing (fraction of a second difference). The differences in our respective posts is that I removed the quotes from the state values and changed < to <= in some of the tests (otherwise the value would fail to be included in the test).

Thank you to both of you to both of you! Now when I set the sensor.shelly_vintti_power with the Developer Tool to any value, the desired input_select option is chosen correctly. However, now I noticed a new bug in my code. The automatic “real” sensor.shelly_vintti_power updates do not trigger a selection so there must be something wrong with

trigger:
  - platform: numeric_state
    entity_id: sensor.shelly_vintti_power
    above: '50'
1 Like

That trigger will fire only when the power value changes from below 50 to above 50. In other words, it triggers only when the value crosses the threshold of 50.

Once the value is above 50 and continues to increase or decrease but remains above 50, no further triggering occurs. It must first decrease below 50, and then rise above it, to trigger the automation.

1 Like

Thanks again!

trigger:
  - platform: state
    entity_id: sensor.shelly_vintti_power

Worked and now I can run in red lights :smiley: