Hi all,
I’m trying to do something like this in a yaml service call (short snip with only 2 lines):
service: notify.signal_jprates
data:
message: 'test message'
data:
attachments: >
{%- if
is_state('binary_sensor.sensor1_access_control_window_door_is_open',
'on') -%}
- file_path/sensor1.jpg
{% endif %}
{%- if
is_state('binary_sensor.sensor2_access_control_window_door_is_open',
'on') -%}
- file_path/sensor2.jpg
{% endif %}
If I check the result from this template on developers tools I get the result I want:
So I thought the above yaml would be equivalent to this:
service: notify.signal_jprates
data:
message: 'test message'
data:
attachments:
- file_path/sensor1.jpg
- file_path/sensor2.jpg
However this unfortunately does not work as I expected, it seams to treat the template as if it was a single line string, not a multi-line one.
The underlying problem that I’m trying to solve here is that I have multiple sensors of which only a few (of course up to all of them) are normally open, basically windows and doors with outside access, and I’m trying to send a signal message with only the pictures from the opened ones, the closed ones are of no interest.
The only thing I know is that at least 1 of them is open, that’s the condition to trigger the automation, but I can’t guess how many of them, and it would be crazy to create over a dozen service calls to send a separate message for each opened door/window.
How can I dynamically construct the list of pictures for the “attachments:” section?
Any ideas appreciated.
TIA,
-jprates