Hello
I have 2 scripts which are called depending on states of two sensors. The scripts require input data (as variables). The scripts work fine when called via both developer tools
and via automation
without service template. But, it doesn’t work with service template. The service template itself gets chosen correct which tells me the template conditions are okay. But, script isn’t called.
alias: "Cam:"
trigger:
- platform: mqtt
topic: bi/alert/motion/main
variables:
cam: "{{ trigger.topic.split('/')[3] }}"
condition:
- condition: template
value_template: "{{ trigger.payload_json.trigger == \"ON\" }}"
action:
- service: >
{% if states('device_tracker.something') == 'home' and states('sun.sun') ==
'below_horizon' %}
script.A
{% elif states('device_tracker.something') == 'home' and states('sun.sun')
== 'above_horizon' %}
script.A
{% else %}
script.B
{% endif %}
data:
cam_short_name: "{{ cam }}"
cam_name: "{{ trigger.payload_json.name }}"
cam_fire_time: "{{ trigger.payload_json.time }}"
cam_rec_link: "{{ trigger.payload_json.id }}"
mode: single
The data variables are created correctly (seen from error log below). So, it seems it the combination of service and data fields (which becomes variables for the scripts) need the right formatting?
Error:
Error: Template rendered invalid service: script.A data: cam_short_name: "main" cam_name: "front_main" cam_fire_time: "2023-10-18T15:45:16.085Z" cam_rec_link: "@19289829960501"