Automation, multiple data templates

Hello,

I’m trying to make data template inside my automation to pass two different paramenters: input_selectr and option. Input select is working fine, but I can’t figure out how to modify Option value based on which entity triggered automation.

- id: Just left
  alias: Just left
  trigger:
    - platform: state
      entity_id: device_tracker.k_phone
      from: 'home'
      to: 'not_home'
    - platform: state
      entity_id: device_tracker.m_phone
      from: 'home'
      to: 'not_home'
  action:
    - service: input_select.select_option
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'device_tracker.k_phone' %}
            input_select.k_status
          {% elif trigger.entity_id == 'device_tracker.m_phone' %}
            input_select.m_status
          {% endif %}
        option: Just Left

Is it possible to make data_template for “option” so I can modify value based on who triggered automation?
Instead “Just Left” I’d like to have (for example) “K Just Left” and M Just Left, so automation would call input_select.k_status with option K Just Left or input_select.m_status with option M Just Left.

Use the same template you used for the input select entity_id e.g.

- id: Just left
  alias: Just left
  trigger:
    - platform: state
      entity_id: device_tracker.k_phone
      from: 'home'
      to: 'not_home'
    - platform: state
      entity_id: device_tracker.m_phone
      from: 'home'
      to: 'not_home'
  action:
    - service: input_select.select_option
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'device_tracker.k_phone' %}
            input_select.k_status
          {% elif trigger.entity_id == 'device_tracker.m_phone' %}
            input_select.m_status
          {% endif %}
        option: >
          {% if trigger.entity_id == 'device_tracker.k_phone' %}
            K Just Left
          {% elif trigger.entity_id == 'device_tracker.m_phone' %}
            M Just Left
          {% endif %}

Assuming that ‘K Just Left’ is a valid option for input_select.k_status, and likewise for M.

1 Like

Thank you!
Finally it’s working! Can’t believe I couldn’t figure it out, stupid me.

you could cut it just a bit shorter:

- id: Just left
  alias: Just left
  trigger:
    - platform: state
      entity_id: device_tracker.k_phone
      to: 'not_home'
    - platform: state
      entity_id: device_tracker.m_phone
      to: 'not_home'
  action:
    - service: input_select.select_option
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'device_tracker.k_phone' %}
            input_select.k_status
          {% else %}
            input_select.m_status
          {% endif %}
        option: >
          {% if trigger.entity_id == 'device_tracker.k_phone' %}
            K Just Left
          {% else %}
            M Just Left
          {% endif %}

or even:

{{ trigger.entity_id[15:-6]|title}} just left