Webhook - action depending on state

Hi all
I keep getting and error message in the File Editor (automations.yaml)

missed comma between flow collection entries at line 36, column 8:
{% if is_state("trigger.json.valu …
^


 - alias: Receive Message
    trigger:
    - platform: webhook
      webhook_id: alarm_status
    action:
      {% if is_state("trigger.json.value_id", "on") %}
        service: input_boolean.turn_on
        entity_id: input_boolean.alarm_status
      {% elif is_state("trigger.json.value_id", "off") %}    
        service: input_boolean.turn_off
        entity_id: input_boolean.alarm_status
      {% endif %}

Any help would be appreciated. Thanks

key: value

You can template a value. You can’t template a key. You have both in your templates.

Also your indentation of alias: does not match the rest of your automation. But I’ll assume that is a copy/paste error.

    action:
      service: >
        {% if is_state("trigger.json.value_id", "on") %}
          input_boolean.turn_on
        {% elif is_state("trigger.json.value_id", "off") %}    
          input_boolean.turn_off
        {% endif %}
      entity_id: input_boolean.alarm_status

If the trigger.jason.value_id can be anything other than on or off you need an else case too. If it can only be on or off you could simplify the template to:

    action:
      service: "input_boolean.turn_{{ state('trigger.json.value_id') }}"
      entity_id: input_boolean.alarm_status
1 Like

Try this:

 - alias: Receive Message
    trigger:
    - platform: webhook
      webhook_id: alarm_status
    action:
      service: >
        input_boolean.turn_{{ trigger.json.value_id }}
      entity_id: input_boolean.alarm_status
      
2 Likes

Thanks tom_I
Unfortunately, I could not get your suggestions to work - nevertheless I’m very new to HA and learned a lot from your response. I bet you it’s maybe the way I entered it. I tried Burningstone’s solution below and it worked.
Thanks again!

Thank you! It works :slight_smile:

1 Like

Yeah I stuffed it up, I should have written:
service: "input_boolean.turn_{{ trigger.json.value_id }}"

2 Likes