Which doors/windows are open?

I’m trying to integrate a notification into my thermostat flow to tell me which doors/windows are open.
I’ve created a group.doors_windows which contains 9 entities. I already have it turning the thermostats off when it’s open for 5 minutes and back on when all are closed. But I’m getting stuck on forming the message to tell me which entities are open.

I’ve tried this in a template sensor to try to form the message but it always returns null.

{{ states | selectattr('entity_id', 'in',
      state_attr('group.doors_windows','entity_id')) |
      selectattr('state','in',['on','open']) | list | map(attribute='name') |
      join(', ') }}

Any help is appreciated.

Are you trying to do this in NR or HA?

In NR you can use the get-entities node:

image

1 Like

That is exactly what I’m trying to do! I just found the thread on this get entities node so I’ll play with it.

That did exactly what I needed and so simple! Thank you very much!

I can picture a few more uses for something like this. Primarily minimizing z-wave traffic for my goodnight and away automations by only sending off/lock/etc commands to items that are on. Should speed up the process a little bit.

1 Like

@MRobi can you share your flow please?

Here you go

[{"id":"42442f06.7b14f","type":"server-state-changed","z":"5ddddd21.00d204","name":"Door/Window Open","server":"94fdcfdf.a00b","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"group.doors_windows","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":110,"y":1500,"wires":[["5cb1066a.159528"]]},{"id":"5cb1066a.159528","type":"switch","z":"5ddddd21.00d204","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":1500,"wires":[["92868919.54d7a8"],["a13066de.6decb8"]]},{"id":"92868919.54d7a8","type":"stoptimer","z":"5ddddd21.00d204","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"5 Minutes","x":580,"y":1500,"wires":[["81951836.f6f138"],[]]},{"id":"a13066de.6decb8","type":"change","z":"5ddddd21.00d204","name":"Stop Timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":1560,"wires":[["92868919.54d7a8","a154c077.9126e"]]},{"id":"3bfdd611.5a426a","type":"api-call-service","z":"5ddddd21.00d204","name":"Door/Window Open","server":"94fdcfdf.a00b","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.door_open","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1010,"y":1500,"wires":[["3b2966e7.564c1a"]]},{"id":"a154c077.9126e","type":"api-call-service","z":"5ddddd21.00d204","name":"Door/Window Closed","server":"94fdcfdf.a00b","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.door_open","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":1560,"wires":[[]]},{"id":"81951836.f6f138","type":"api-call-service","z":"5ddddd21.00d204","name":"Turn Off Thermostats","server":"94fdcfdf.a00b","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"climate.daikinap97021, climate.thermostat_bathroom, climate.thermostat_dining_room, climate.thermostat_downstairs_bathroom, climate.thermostat_entrance, climate.thermostat_gym, climate.thermostat_haileys_room, climate.thermostat_kitchen, climate.thermostat_living_room_2, climate.thermostat_master_bathroom, climate.thermostat_master_bedroom, climate.thermostat_play_room, climate.thermostat_spare_bedroom, climate.thermostat_storage, climate.thermostat_theatre, climate.thermostat_living_room_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":800,"y":1500,"wires":[["3bfdd611.5a426a"]]},{"id":"3b2966e7.564c1a","type":"ha-get-entities","z":"5ddddd21.00d204","server":"94fdcfdf.a00b","name":"Which Doors/Windows?","rules":[{"property":"entity_id","logic":"in_group","value":"group.doors_windows","valueType":"str"},{"property":"state","logic":"includes","value":"on, open","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":1270,"y":1500,"wires":[["e0d33504.13ee68"]]},{"id":"e0d33504.13ee68","type":"template","z":"5ddddd21.00d204","name":"Format Msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":1470,"y":1500,"wires":[["ce669e51.69747"]]},{"id":"ce669e51.69747","type":"join","z":"5ddddd21.00d204","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", ","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1610,"y":1500,"wires":[["85ccf662.f8c1e8"]]},{"id":"85ccf662.f8c1e8","type":"api-call-service","z":"5ddddd21.00d204","name":"Notify","server":"94fdcfdf.a00b","version":1,"debugenabled":false,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"{{payload}} left open for 5 minutes. Thermostats turned off\",\"title\":\"Temperature\",\"data\":{\"priority\":0,\"sound\":\"pianobar\"}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1750,"y":1500,"wires":[[]]},{"id":"94fdcfdf.a00b","type":"server","z":"","name":"Home Assistant","addon":true}]
1 Like

Thanks man. :ok_hand:

I know this is an old thread, but I just have to say thank you! This just helped me finish the automation I was implementing to turn off my thermostat if any of my doors were kept open for a while.

Hi,

Thank you very much ,. I’m looking for a long time solution, and probably yours fits!

Is there a new / up-to-date code?

well, yeah, this is a bit more up to date, though you could also use the new template: integration…

  - platform: template
    sensors:
      doors:
        friendly_name: Doors
        value_template: >
          {%- set count = expand('group.doors')
                                 |selectattr('state','==','on')
                                 |list|count %}
          {{count}}
        attribute_templates:
          Doors: >
            {%- set count = expand('group.doors')
                                   |selectattr('state','==','on')
                                   |list|count %}
            {% set phrase = 'door is' if count == 1 else 'doors are' %}
            {%- if count > 0 %}
            {{count}} {{phrase}} open:
             {{expand('group.doors')|selectattr('state','==','on')
                                   |map(attribute='name')
                                   |join(', \n')}}
            {%- else %} All doors closed
            {%- endif %}

Ok I got it, thank you!

But I use inside node red,

Slowly begins to move the automation there

I am asking for help with the following automation: (it already exists and works in yaml).

I want like a hotel, have a window / door open for 5 minutes and the air conditioner is on then I get a message from Alexa, and if after 5 minutes Alexa does not close say what I did not close and close the air conditioner.

ok, thats cool.
never understood the need to use NodeRed though, seems so much more complicated, without any major advantage?

Ummmmm

I also thought like you but I know less to write code, so it works if node red,

Can you help? Or something else please :slight_smile:

help with what?
you say your automation in Yaml already works?

100% right but I want to move it to NODE RED :slight_smile:

overcomplicated?
modeling system behavior using custom language wrapped into data metalanguage isn’t overcomplicated?

NR is more natural (for many, remember, children start with images, not a written language, diagrams are ussually easier to read than source code etc) doesn’t change every month like HA yaml automation language does. By default provides more features (often not achievable by yaml automations)

And sports features way beyond its vanilla installation. if you don’t know that there are thousands of custom nodes to download dedicated for specific things.

With NR you can do automation things you could’t do with ha automation. Some says that in such cases python/appdaemon may take precedence. But does it make it any easier while in NR you can draw a few more nodes and voila?

Keep in mind, NR can run whole smart home automation alone. It should be enough to prove its usability.

I’m not even mentioning it’s debugging features. Yep, I know, HA automations has some since a month. NR for years.
TBH I don’t understand the effort HA devs put into this automation language. It cannot win the race. It will be always lacking features, and the more will grow, the more complicated will be. Because yaml is not programming language, so procedural constructs (not even talking about oop) must be somehow gimmicked.

1 Like

The get entities node in kermit’s post works fine, you can use the example above.

Import this flow into node red and modify to fit your needs.

1 Like
[{"id":"798d1dba.23cc4c","type":"stoptimer","z":"9ea4ccf5.ca15b","duration":"1","units":"Second","payloadtype":"num","payloadval":"stop","name":"5 Minutes","x":780,"y":180,"wires":[["92e82a74.b3fbb"],["11530369.1bb21d"]]},{"id":"ee0050b8.edc618","type":"change","z":"9ea4ccf5.ca15b","name":"Stop Timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":360,"wires":[[]]},{"id":"10820c2.ce48bf4","type":"api-call-service","z":"9ea4ccf5.ca15b","name":"Turn Off Thermostats","server":"f22f6e73.21e16","version":3,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"climate.salon","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":80,"wires":[["4df73d37.9ea43c"]]},{"id":"4df73d37.9ea43c","type":"ha-get-entities","z":"9ea4ccf5.ca15b","name":"Which Doors/Windows?","server":"f22f6e73.21e16","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.salon_door_and_window_sensors","valueType":"str"},{"property":"state","logic":"includes","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":1370,"y":80,"wires":[["6ba1bfee.900dc8","c4cdf582.d8a768"]]},{"id":"6ba1bfee.900dc8","type":"template","z":"9ea4ccf5.ca15b","name":"Format Msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":1610,"y":80,"wires":[["9bfc35b6.cb662"]]},{"id":"9bfc35b6.cb662","type":"join","z":"9ea4ccf5.ca15b","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", ","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1810,"y":80,"wires":[["28f4a7b5.e5d978"]]},{"id":"2c99162a.dc758a","type":"ha-get-entities","z":"9ea4ccf5.ca15b","name":"Salon Doors/Windows?","server":"f22f6e73.21e16","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.salon_door_and_window_sensors","valueType":"str"},{"property":"state","logic":"includes","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":390,"y":200,"wires":[["443104b4.db016c"]]},{"id":"5aa7e75b.db2338","type":"server-state-changed","z":"9ea4ccf5.ca15b","name":"AC salon ON ?","server":"f22f6e73.21e16","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.salon","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"heat_cool","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":100,"wires":[["2c99162a.dc758a"],[]]},{"id":"28f4a7b5.e5d978","type":"api-call-service","z":"9ea4ccf5.ca15b","name":"Sed Notify  yuval Phone","server":"f22f6e73.21e16","version":3,"debugenabled":false,"service_domain":"notify","service":"mobile_app_sm_a705fn","entityId":"","data":"{ \"message\": \"{{payload}}\" }","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2010,"y":80,"wires":[[]]},{"id":"22a06839.db251","type":"comment","z":"9ea4ccf5.ca15b","name":"Notifications if Open Windows -  ac salon ","info":"","x":200,"y":40,"wires":[]},{"id":"89eb1f3a.7b959","type":"api-current-state","z":"9ea4ccf5.ca15b","name":"climate.salon","server":"f22f6e73.21e16","version":2,"outputs":2,"halt_if":"cool,heat,fan_only","halt_if_type":"num","halt_if_compare":"is","entity_id":"climate.salon","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":130,"y":180,"wires":[[],[]]},{"id":"1e0af6cd.fdd1b1","type":"api-current-state","z":"9ea4ccf5.ca15b","name":"Ac_Check_open_or_closed","server":"f22f6e73.21e16","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.openclose_11","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":400,"y":100,"wires":[["2c99162a.dc758a"],[]]},{"id":"46ddc9.114fe238","type":"inject","z":"9ea4ccf5.ca15b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"on","payload":"","payloadType":"date","x":170,"y":280,"wires":[["2c99162a.dc758a"]]},{"id":"c4cdf582.d8a768","type":"api-call-service","z":"9ea4ccf5.ca15b","name":"Announce Family Room","server":"f22f6e73.21e16","version":3,"debugenabled":false,"service_domain":"notify","service":"alexa_media_yuval_s_echo","entityId":"","data":"{\"message\":\"{{payload.attributes.friendly_name}}\",\"data\":{\"type\":\"tts\"}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1610,"y":180,"wires":[[]]},{"id":"443104b4.db016c","type":"switch","z":"9ea4ccf5.ca15b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":200,"wires":[["798d1dba.23cc4c"],["ee0050b8.edc618"]]},{"id":"11530369.1bb21d","type":"api-current-state","z":"9ea4ccf5.ca15b","name":"IS Close ? send Notification ","server":"f22f6e73.21e16","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"group.salon_door_and_window_sensors","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":820,"y":260,"wires":[[],[]]},{"id":"92e82a74.b3fbb","type":"api-current-state","z":"9ea4ccf5.ca15b","name":"IS Open - send  Notification ","server":"f22f6e73.21e16","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"group.salon_door_and_window_sensors","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":820,"y":80,"wires":[["10820c2.ce48bf4"],[]]},{"id":"f22f6e73.21e16","type":"server","name":"yuval_Home Assistant","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I did the following thing, but it does not work really well for me …
Alexa says some window or door is open which is great but time does not work well.
can you help…

I want

  1. Air conditioner door - a message is received from an open window.
  2. After 5 minutes if I did not close the window another message.
  3. A message is received telling me why the air conditioner is turned off because of a window or door and which.