Calling a script with parameters from automation

There is a script:

ifttt_script:
  alias: 'IFTTT sending mes'
  sequence:
    - service: persistent_notification.create
      data_template:
        title: 'IFTTT test'
        message: '{{ if_post }}'        

There is automation:

- alias: IFTTT Incoming connection
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    - service: script.turn_on
      entity_id: script.ifttt_script
      data_template:
        if_post: '{{ trigger.event.data.if_post }}'

After triggering automation in the logs:

Logger: homeassistant.components.automation
Source: helpers/script.py:802
Integration: Автоматизация (documentation, issues)
First occurred: 13:11:20 (2 occurrences)
Last logged: 13:15:40

IFTTT Incoming connection: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['if_post']

I ask for help.
Thanks.

There are two ways to do this:

  action:
    - service: script.ifttt_script # script as a servcie
      data_template:
        if_post: '{{ trigger.event.data.if_post }}'

Or:

  action:
    - service: script.turn_on # script turn on method
      entity_id: script.ifttt_script
      data_template:
        variables:  # <---------- requires this
          if_post: '{{ trigger.event.data.if_post }}'

See here for explanation of the two methods: https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts

1 Like