Proper syntax for parsing a sensor value in an action?

I’m trying to include the value of a selector in my action, but I can’t seem to get it to parse properly. The following works fine in developer tools > template sandbox:

"{{ states('select.dishwasher_selected_program') }}"

However including it in my automation, it doesn’t get parsed and errors out with Option {{ states('select.dishwasher_selected_program') }} is not valid for entity select.dishwasher_active_program, valid options are:...

Automation YAML (see 2nd line from bottom):

alias: Dishwasher - Handle "Run Now" Pressed
description: ""
triggers:
  - entity_id:
      - input_button.dishwasher_run_now
    trigger: state
conditions: []
actions:
  - device_id: f618f7a21647c5208227d3a01213c3c0
    domain: select
    entity_id: eceaf7ea812fb1aba958d556d3699845
    type: select_option
    option: "{{ states('select.dishwasher_selected_program') }}"
mode: single

What’s the proper syntax to include this in my automation so it parses and presents the current value of the selector to my script?

What is that device in the action? What are you trying to do with the select value? You seem to be trying to run the select_option action to change whatever that thing is to match your other select entity:

Always better to use plain “action” actions (used to be “call service”) than restricted device actions that often don’t support templates, which seems to be the problem here…

Good call. Change it to a basic “Select” action works fine:

  - action: select.select_option
    metadata: {}
    data:
      option: "{{ states('select.dishwasher_selected_program') }}"
    target:
      entity_id: select.dishwasher_active_program

Thank you!

1 Like