Notification about specific open window/door

I’m trying to improve my meteo warnings notification process in NR. Currently it works as presented in the attachement. Depending on the warning, it generate 1st part of a message and then check which windows/doors are open. If it find the first open entity, it generate 2nd part of the message which is “House is insecured”. If it don’t, the second part sounds like “House is secured”. The final message is something like “Storm incoming. House is insecured”.

I would like to impreve it with notification which exact windows/doors are open, but I don’t have a clue how it should or can be done. I would like to achieve final messsage which is something like: “Storm incoming. House is insecured. Close kitchen window and balcony doors.” The text should change, depending which entities were discovered as open. I have tried to create and assign specific variable to doors/window which were discovered as open and include it in final message. It parially work, because if entity is discovered as closed, the final message include “Undefined” instead just pass it.

Much appreciate your help and thank you in advance.

[{"id":"d1d7e11a.61e38","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f0d8036f.a1398","type":"server-state-changed","z":"d1d7e11a.61e38","name":"Wind warning","server":"b1358d16.4ce12","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.burze_dzis_net_wind_warning","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":130,"y":80,"wires":[["9d27258.bab44d8"],[]]},{"id":"750d44d.b6fc2bc","type":"server-state-changed","z":"d1d7e11a.61e38","name":"Rain warning","server":"b1358d16.4ce12","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.burze_dzis_net_precipitation_warning","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":130,"y":140,"wires":[["62bea725.b4db58"],[]]},{"id":"36796184.ad215e","type":"server-state-changed","z":"d1d7e11a.61e38","name":"Storm warning","server":"b1358d16.4ce12","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.burze_dzis_net_storm_warning","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":130,"y":200,"wires":[["c4888d60.04527"],[]]},{"id":"b3773f05.09ad6","type":"server-state-changed","z":"d1d7e11a.61e38","name":"Storms nerby","server":"b1358d16.4ce12","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.burze_dzis_net_storms_nearby","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":130,"y":260,"wires":[["80fe5c4e.0f4bd"],[]]},{"id":"f19297b0.8a1a58","type":"api-current-state","z":"d1d7e11a.61e38","name":"Is kitchen windo open?","server":"b1358d16.4ce12","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.kitchen_window","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":760,"y":180,"wires":[["7869b320.e2e85c"],["15b60f3b.2e7e51"]]},{"id":"15b60f3b.2e7e51","type":"api-current-state","z":"d1d7e11a.61e38","name":"Is left bedroom window open?","server":"b1358d16.4ce12","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.bedroom_window_left","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":870,"y":240,"wires":[["7869b320.e2e85c"],["dbd74080.0b7e8"]]},{"id":"dbd74080.0b7e8","type":"api-current-state","z":"d1d7e11a.61e38","name":"Is right bedroom window open?","server":"b1358d16.4ce12","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.bedroom_window_right","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":950,"y":300,"wires":[["7869b320.e2e85c"],["f9e7606f.12a8f"]]},{"id":"f9e7606f.12a8f","type":"api-current-state","z":"d1d7e11a.61e38","name":"Are balcony doors open?","server":"b1358d16.4ce12","version":1,"outputs":2,"halt_if":"closed","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"sensor.balcony_doors","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1010,"y":360,"wires":[["7869b320.e2e85c"],["68ba325a.30c86c"]]},{"id":"9d27258.bab44d8","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"warning","pt":"msg","to":"Strong wind expected.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":80,"wires":[["f19297b0.8a1a58"]]},{"id":"62bea725.b4db58","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"warning","pt":"msg","to":"Heavy rain expected.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":140,"wires":[["f19297b0.8a1a58"]]},{"id":"c4888d60.04527","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"warning","pt":"msg","to":"Storm incoming.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":200,"wires":[["f19297b0.8a1a58"]]},{"id":"80fe5c4e.0f4bd","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"warning","pt":"msg","to":"There is a storm in 20km. radius.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":260,"wires":[["f19297b0.8a1a58"]]},{"id":"68ba325a.30c86c","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"housestate","pt":"msg","to":"House is secured. Windows and balcony doors are locked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":380,"wires":[["5876a8d1.1e3838"]]},{"id":"7869b320.e2e85c","type":"change","z":"d1d7e11a.61e38","name":"","rules":[{"t":"set","p":"housestate","pt":"msg","to":"House is insecured. Check windows and balcony doors.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":260,"wires":[["5876a8d1.1e3838"]]},{"id":"5876a8d1.1e3838","type":"function","z":"d1d7e11a.61e38","name":"Message","func":"msg.wiadomosc =\n{\n    \"subject\":\"Meteo warnings\",\n    \"message\":\"Attention! \"+msg.warning+\" \"+msg.housestate+\"\",\n    \"recipient\":\"all\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1500,"y":320,"wires":[[]]},{"id":"b1358d16.4ce12","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I asked a similar question some time ago and got this script. I don’t fully understand it but I’m sure you can work it out.

window_check:
  alias: Check Windows
  sequence:
  - service: tts.google_translate_say
    entity_id: media_player.living_room_home
    data_template:
      message: >
        {% set open_doors = states | selectattr('entity_id', 'in', state_attr('group.alldoors','entity_id')) | selectattr('state','in',['on','open']) | map(attribute='name') | list %}
        {% if open_doors | length == 1 %}
          Hi. It is 10pm and the {{ open_doors[0] }} is open.
        {% else %}
          Hi. It is 10pm and the {{ open_doors[:-1] | join(', ') }}{{' door,' if open_doors | length > 2 else ' '}} and {{ open_doors[-1]}} are open.
        {% endif %}

That is not exactly what i’m looking for, as it is a script to be used in HA, not in Node-Red,but I think I may use a part of it for my purposes and try to implement it in NR. Great, thanks for the tip.