How to setup a complex "test"and send message

HomeAssistant : 0.80.3

Hey all,

I have a collection of windows sensors around my house, connected to HA via MQTT and a sensor on my alarm again connected via MQTT

My objective is to trigger a check, “When the alarm set, see if any windows are open, if they are send a pushbullet message with the names of the window”

For the testing of the sensor values Im fine, I have a massive or condition in the automations.yaml
indent preformatted text by 4 spaces

Something like this (shortened)

{
“condition”: “or”,
“conditions”: [
{
“condition”: “state”,
“entity_id”: “binary_sensor.front_room_window_1”,
“state”: “on”
},
{
“condition”: “state”,
“entity_id”: “binary_sensor.front_room_window_2”,
“state”: “on”
},
{
“condition”: “state”,
“entity_id”: “binary_sensor.back_door”,
“state”: “on”
}
]
}

Now if a door/window is open I need to send a message but Im struggling to work out how to dymatically generate the string for push bullet

Ive written the following template to check all the windows and print the values but this doesnt appear to work for pushbullet message

{% set windows={“windows”: [
{“name”:"Front Room Window 1 ",“sensorName”:“binary_sensor.front_room_window_1”},
{“name”:"Front Room Window 2 ",“sensorName”:“binary_sensor.front_room_window_2”},
{“name”:“Kitchen Large Window”,“sensorName”:“binary_sensor.kitchen_large_window”},
{“name”:“Back Door”,“sensorName”:“binary_sensor.back_door”}
]} %}
{“message”: “Warning the following door/windows are open :
{% for state in windows.windows -%}
{%- if is_state(state.sensorName,“on”) %}{{state.name}},
{% endif -%}
{%- endfor %}”}

{“message”: “{{ states.binary_sensor.front_room_window_1}}”}

I have however worked out that the pushbullet message can be a little dynamic and i can reference state data using a data template

e.g. ```
message: “Fan running because current is {{ states.sensor.furnace.state }} amps”

but my template is much more complex, whats the best way to achieve the same result?

One idea I had was to create a new sensor and base that on my template or perhaps a python sensor where I call the python, it checks all the values and populates a sensor with a list of windows??

is there a better way?