Passing Automation Trigger Device Name to Restful API

Hi Everyone,

I hoping someone could point me in the right direction on this! I’ve been able to pass information on the device from automations that use slack and others when I use {{ trigger.to_state.attributes.friendly_name }} and it works great. However, what I try send the same variable via a rest command, I get this error in the log -

How can I send both sensor value and name via the rest API since they are appear to be ignored.

Sample Configs:

Automation:

alias: alarm_feed
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.g4_dome_vehicle_detected
      - binary_sensor.g4_dome_person_detected
      - binary_sensor.g4_instant_person_detected
condition: []
action:
  - service: rest_command.alarm_feed
    data: {}
mode: single

Rest Config

rest_command:
  sanasight_alarm_feed:
    url: https://incident.test.com/ha_receiver/receive
    method: post
    headers:
      content-type: 'application/json'
    payload: '{"event_time": "date", "XXX-DATETIME-VAR-XXX????": "{{ trigger.to_state.attributes.friendly_name }}"}'
    verify_ssl: true

You’re not passing anything to that REST command.

Putting the word “trigger” in the REST command doesn’t make it aware of what happened in your automation .

Refer to the last example in the documentation.

You haven’t passed any data?

Try this:

action:
  - service: rest_command.alarm_feed
    data: 
      name: "{{ trigger.to_state.attributes.friendly_name }}"

And for the rest command:

    payload: '{"event_time": "date", "{{ now() }}": "{{ name }}"}'

You may need to escape some of those characters, not sure.

1 Like