Data_template

Hi I try to pass url in html5 notify from automation to script using data_template. Below are part of automation and script.

**Automation:**
- alias: 'Camera - move detect'
  initial_state: True
  trigger:
    - platform: state
      entity_id:
        - sensor.kartur_events
        - sensor.kganek_events
        - sensor.ksypialnia_events
        - sensor.kparter_events
  action:
    - service: script.message_notify
      data_template:
        title: Informacja
        message: 'Wykryto ruch na kamerze {{ trigger.from_state.attributes.friendly_name }}'
        data:
          url: 'some url'

**and Script**
message_notify:
  alias: "Message notify script"
  sequence:
    - service: notify.html5_notify
      data_template:
        title: "{{ title }} - "
        message: "{{ message }}"
        data:
          url: "{{ url }}"

All above works except url value which are simply ignored. Can you help with this? I try a lot of combination but without success.

Please use code blocks and syntax highlighting when posting config snippets.

Did you try the notification right in the automation rather than as a script?

Yes and it works but I want to have generic notify script

it’s because of the way you are passing the variables. The shape of the data template when passing variables is different then when using them:

keep your script the same. this should be your automation data:

- service: script.message_notify
  data_template:
    title: Informacja
    message: Wykryto ruch na kamerze {{ trigger.from_state.attributes.friendly_name }}
    url: 'some url'

Take a look at how to pass variables to scripts.

Maybe something like this works:

  action:
    - service: script.turn_on
      entity_id: script.message_notify
      data:
        variables:
          title: Informacja
          message: 'Wykryto ruch na kamerze {{ trigger.from_state.attributes.friendly_name }}'
          url: 'some url'

Close, You need to change data to data_template. I forgot ‘variables’ in my example:

action:
    - service: script.turn_on
      entity_id: script.message_notify
      data_template:
        variables:
          title: Informacja
          message: 'Wykryto ruch na kamerze {{ trigger.from_state.attributes.friendly_name }}'
          url: 'some url'
1 Like

You’re so right. :+1:

1 Like

thank you for your help it works perfectly!

1 Like