How to define an automation correctly in the automation editor?

Hi!

First I have an input_select defined inside my configuration.yaml:

input_select:
  harmony:
    name: Harmony
    options:
      - PowerOff
      - Fernsehen
      - Anlage
      - BluRay
      - Videorecorder
      - Musik
      - Apple TV
    icon: mdi:monitor

Now I want to define the following automation, that I found here inside the automation-editor:

  alias: Update Harmony input_select
  description: ''
  trigger:
  - entity_id: remote.harmony_hub
    platform: state
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.harmony
      option: "{{ states.remote.harmony_hub.attributes.current_activity }}"

But when I input this into the automation-editor:

I am getting this output in the automation.yaml and it is not working:

  alias: Update Harmony input_select
  description: ''
  trigger:
  - entity_id: remote.harmony_hub
    platform: state
  condition: []
  action:
  - data:
      option: '{{ states.remote.harmony_hub.attributes.current_activity }}'
    entity_id: input_select.harmony
    service: input_select.select_option

Can anybody point me into the right direction to get the automation correctly inside the automation.yaml with the automation-editor?

First:

This is not how you should get an attribute value:

"{{ states.remote.harmony_hub.attributes.current_activity }}"

This is a better way (and also how it’s documented):

"{{ state_attr('remote.harmony_hub', 'current_activity') }}"

Second:
To use templates in the action, you need data_template instead of data, this is not supported by the automation UI editor.

To solve this you have 2 options:

  1. Change it manually in the file you copied from.
  2. Switch to YAML mode in the editor like this:
2 Likes

Ok, thank you! I copied it from another thread.

Thank you also for this! Now I see clearer!