Can someone help me out with dynamic notifications?

Templating I think it’s called? Here is the flow I’m working with:

Currently, if the garage door is open, TTS states; “It’s about to rain, so I’m closing the garage door. Please check all other doors and windows.”, if the garage door is closed, TTS states; “message”: “It’s about to rain, and the garage door is already closed. Please ensure all other doors and windows are closed as well.”.

If any doors or windows are left open, I get a Pushover notification sent to my phone. If 3 windows are open, I get three separate notifications to my phone.

I’d like to have more dynamic notifications that change depending on the situation. IF the garage door is open, and the dining room and front door are open, I’d like to receive a notification that says something like “It’s about to rain so I closed the garage door, and the dining room window and front door are open”.

I know this is possible with entity states and templating,m but I hae no idea how to start something like this. I’ve done a few Bayesian templates using prefabbed code, but I can’t find anything like that for this.

Does anyone have an example of what I’m trying to do?

[{"id":"84bc97e2.1bfc08","type":"tab","label":"Rainy Day","disabled":false,"info":""},{"id":"a5afbd08.facb3","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Turn on Rain Lights","server":"26956a45.92d866","version":1,"service_domain":"light","service":"turn_on","entityId":"group.rain_lights","data":"{\"brightness_pct\":45,\"transition\":1.5,\"rgb_color\":[7,235,205]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":530,"y":180,"wires":[[]]},{"id":"9d17211d.506","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Turn Off Rain Lights","server":"26956a45.92d866","version":1,"service_domain":"light","service":"turn_off","entityId":"group.rain_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":380,"y":720,"wires":[[]]},{"id":"d6507fe0.9b446","type":"server-state-changed","z":"84bc97e2.1bfc08","name":"Rain","server":"26956a45.92d866","version":1,"entityidfilter":"sensor.dark_sky_precip","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"rain","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":50,"y":400,"wires":[["2985f081.00df8","24ea9b14.88b054","265d3bb9.174074","664d7488.7c0dac","f7e4a96f.f1a7d8","375251b8.53a96e","d0ef0adb.52cb28","b79908a0.90a738","9a99ae33.3ec9d","fe5a3ea1.60c89","ab6026b.d40fad8"],["9d17211d.506"]]},{"id":"50cff154.28671","type":"comment","z":"84bc97e2.1bfc08","name":"Close the garage door if raining","info":"","x":410,"y":40,"wires":[]},{"id":"2985f081.00df8","type":"time-range-switch","z":"84bc97e2.1bfc08","name":"","lat":"27.918805","lon":"-81.866830","startTime":"05:00","endTime":"21:30","startOffset":0,"endOffset":0,"x":350,"y":200,"wires":[["a5afbd08.facb3"],[]]},{"id":"24ea9b14.88b054","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Garage Door open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"open","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"cover.garage_door","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":80,"wires":[["cc78e494.0aa7c8"],["1ca81669.8ad63a"]]},{"id":"cc78e494.0aa7c8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Close Garage Door","server":"26956a45.92d866","version":1,"service_domain":"cover","service":"close_cover","entityId":"cover.garage_door","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":60,"wires":[["84c74241.9846f"]]},{"id":"ca3ae3fc.0f92f","type":"comment","z":"84bc97e2.1bfc08","name":"If any doors or windows are left open, send notification.","info":"","x":480,"y":260,"wires":[]},{"id":"265d3bb9.174074","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Front Door open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.front_door_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":300,"wires":[["47252d83.75e824"],[]]},{"id":"664d7488.7c0dac","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Ava's window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.ava_s_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":380,"wires":[["8e62c140.629cc"],[]]},{"id":"f7e4a96f.f1a7d8","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Wyatt's window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.wyatt_s_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":460,"wires":[["b3a12ac9.2900d8"],[]]},{"id":"375251b8.53a96e","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Kid's bathroom window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.kids_bathroom_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":410,"y":580,"wires":[["ec79725c.3ee05"],[]]},{"id":"d0ef0adb.52cb28","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Gwen's window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.gwen_s_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":340,"wires":[["56bf9ba1.032994"],[]]},{"id":"b79908a0.90a738","type":"api-current-state","z":"84bc97e2.1bfc08","name":"LM Bedroom window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.lm_bedroom_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":500,"wires":[["4eaaa549.fdacac"],[]]},{"id":"9a99ae33.3ec9d","type":"api-current-state","z":"84bc97e2.1bfc08","name":"RM Bedroom window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.rm_bedroom_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":420,"wires":[["59add103.8821d"],[]]},{"id":"fe5a3ea1.60c89","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Slider open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.slider_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":350,"y":540,"wires":[["8cc61ae4.0f11c8"],[]]},{"id":"ab6026b.d40fad8","type":"api-current-state","z":"84bc97e2.1bfc08","name":"Dining room window open?","server":"26956a45.92d866","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.dining_room_window_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":620,"wires":[["ff7ea999.e7e2f8"],[]]},{"id":"47252d83.75e824","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Front door notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the Front Door is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":300,"wires":[[]]},{"id":"56bf9ba1.032994","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Gwen's window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and Gwen's window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":340,"wires":[[]]},{"id":"8e62c140.629cc","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Ava's window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and Ava's window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":610,"y":380,"wires":[[]]},{"id":"59add103.8821d","type":"api-call-service","z":"84bc97e2.1bfc08","name":"RM bedroom window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the RM bedroom window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":420,"wires":[[]]},{"id":"b3a12ac9.2900d8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Wyatt's window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and Wyatt's window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":460,"wires":[[]]},{"id":"4eaaa549.fdacac","type":"api-call-service","z":"84bc97e2.1bfc08","name":"LM bedroom window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the LM bedroom window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":500,"wires":[[]]},{"id":"8cc61ae4.0f11c8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Slider notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the Slider is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":530,"y":540,"wires":[[]]},{"id":"ec79725c.3ee05","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Kids bathroom window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the Kids bathroom window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":700,"y":580,"wires":[[]]},{"id":"67d9ba09.116514","type":"comment","z":"84bc97e2.1bfc08","name":"Turn off lights when rain is gone","info":"","x":410,"y":680,"wires":[]},{"id":"84c74241.9846f","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Garage door notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, so I'm closing the garage door.\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":40,"wires":[["fdfc9f4c.fd62c"]]},{"id":"c1cd5fca.31d07","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say \"Closing the Garage...\"","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, so I'm closing the garage door. Please check all other doors and windows.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1330,"y":60,"wires":[[]]},{"id":"a0be89f4.158908","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Set volume 50%","server":"26956a45.92d866","version":1,"service_domain":"media_player","service":"volume_set","entityId":"media_player.kitchen_hub","data":"{\"volume_level\":0.5}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1100,"y":80,"wires":[["c1cd5fca.31d07"]]},{"id":"ff7ea999.e7e2f8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Dining room window notification","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain, and the dining room window is open!\",\"title\":\"Home Assistant\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":620,"wires":[[]]},{"id":"9f3c6b61.de4378","type":"comment","z":"84bc97e2.1bfc08","name":"If between 5a and 9p, turn on rain lights.","info":"","x":430,"y":140,"wires":[]},{"id":"8eaa9740.b40f18","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say Gwen's window is open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and Gwen's window is open!\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1290,"y":340,"wires":[[]]},{"id":"5a48cbef.d28f64","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say Ava's window is open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and Ava's window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1270,"y":380,"wires":[[]]},{"id":"70fced48.ccba14","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say right master window open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the right master window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1360,"y":420,"wires":[[]]},{"id":"e5dd219e.ec47d","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say Wyatt's window open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and Wyatt's window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1280,"y":460,"wires":[[]]},{"id":"a7827465.a061b8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say left master window open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the left master window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1350,"y":500,"wires":[[]]},{"id":"f1f42567.64af08","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say the slider is open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the slider is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1150,"y":540,"wires":[[]]},{"id":"68c0dc7e.048c14","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say kids bathroom window open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the kids bathroom window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1430,"y":580,"wires":[[]]},{"id":"28babf63.f35b3","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"45","units":"Second","payloadtype":"num","payloadval":"0","name":"45sec","x":1150,"y":420,"wires":[["70fced48.ccba14"],[]]},{"id":"4d80721c.a6e1ec","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"75","units":"Second","payloadtype":"num","payloadval":"0","name":"75sec","x":1150,"y":500,"wires":[["a7827465.a061b8"],[]]},{"id":"84eff7c4.252068","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"105","units":"Second","payloadtype":"num","payloadval":"0","name":"105sec","x":1200,"y":580,"wires":[["68c0dc7e.048c14"],[]]},{"id":"43513515.3a577c","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"120","units":"Second","payloadtype":"num","payloadval":"0","name":"120sec","x":1160,"y":620,"wires":[["27655dc2.909452"],[]]},{"id":"27655dc2.909452","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say Dininf room window open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the Dining room window is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1380,"y":620,"wires":[[]]},{"id":"5d7aa873.406ab8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say Front door is open","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the Front Door is open.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1100,"y":300,"wires":[[]]},{"id":"ec41b92c.d0a148","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"15","units":"Second","payloadtype":"num","payloadval":"0","name":"15sec","x":1090,"y":340,"wires":[["8eaa9740.b40f18"],[]]},{"id":"54cf03cc.93c55c","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"30sec","x":1070,"y":380,"wires":[["5a48cbef.d28f64"],[]]},{"id":"a60f103d.5dde","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"60","units":"Second","payloadtype":"num","payloadval":"0","name":"60sec","x":1090,"y":460,"wires":[["e5dd219e.ec47d"],[]]},{"id":"18b7dbd5.d6aaf4","type":"stoptimer","z":"84bc97e2.1bfc08","duration":"90","units":"Second","payloadtype":"num","payloadval":"0","name":"90sec","x":970,"y":540,"wires":[["f1f42567.64af08"],[]]},{"id":"da8504c8.a09be8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"GH say \"It's about to rain...\"","server":"26956a45.92d866","version":1,"service_domain":"tts","service":"google_cloud_say","entityId":"media_player.kitchen_hub","data":"{\"message\":\"It's about to rain, and the garage door is already closed. Please ensure all other doors and windows are closed as well.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":140,"wires":[[]]},{"id":"9add856b.f61d18","type":"comment","z":"84bc97e2.1bfc08","name":"Disconnected these, as I think my new implementation is better.","info":"","x":1210,"y":260,"wires":[]},{"id":"804c4777.8141e8","type":"api-call-service","z":"84bc97e2.1bfc08","name":"Set volume 50%","server":"26956a45.92d866","version":1,"service_domain":"media_player","service":"volume_set","entityId":"media_player.kitchen_hub","data":"{\"volume_level\":0.5}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1100,"y":160,"wires":[["da8504c8.a09be8"]]},{"id":"962fb6a.9b71f48","type":"inject","z":"84bc97e2.1bfc08","name":"Off @ 9:30pm","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"30 21 * * *","once":false,"onceDelay":0.1,"x":160,"y":720,"wires":[["9d17211d.506"]]},{"id":"fdfc9f4c.fd62c","type":"time-range-switch","z":"84bc97e2.1bfc08","name":"","lat":"27.918805","lon":"-81.866830","startTime":"07:00","endTime":"21:30","startOffset":0,"endOffset":0,"x":930,"y":100,"wires":[["a0be89f4.158908"],[]]},{"id":"1ca81669.8ad63a","type":"time-range-switch","z":"84bc97e2.1bfc08","name":"","lat":"27.918805","lon":"-81.866830","startTime":"07:00","endTime":"21:30","startOffset":0,"endOffset":0,"x":930,"y":180,"wires":[["804c4777.8141e8"],[]]},{"id":"26956a45.92d866","type":"server","z":"","name":"Hass.io","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
2 Likes

There’s a bunch on here you could simplify. For example, instead of getting the state of each individual window, you can get all entities that match whatever type of sensor that you’re using, output an array of those, and deliver that information as a single notification. I do this for presence detection.

Using a Get Entities node, I set two property conditions.

  1. Property: entity_id is regular expression ^person.*
  2. Property: state is regular expression ^whateverzone1|^whateverzone2|^etc

This particular node outputs the count of people who are home so I can test if X > 0 then away mode is off.

You could do the same for the windows and squeeze that big block of “window open” into two nodes. 1) check the windows, 2) give me a list of windows in a single notification.

On another note, in the scope of automation, you’ll be happier in the long run if you ONLY receive notifications when something isn’t right, instead of having your garage door tell you something that’s not important…like that it’s closed.

1 Like

Thanks for this! This definitely is pointing me in the right direction.

As far as the notifications, you’re right, the novelty has worn off. The wife and I thought it was neat to have a natural sounding voice tell us updates, but telling me the garage door is closed 5 times a day is annoying. We’re in Florida so it rains a lot, haha.

Thanks again!

So, I think I pretty much understand what you’re saying, but I do not think I am implementing it correctly.

Here’s what I have right now, and it doesn’t change, even if I open one of the windows/doors.

[
    {
        "id": "10032478.42e0bc",
        "type": "ha-get-entities",
        "z": "7e722c6a.707654",
        "server": "26956a45.92d866",
        "name": "",
        "rules": [
            {
                "property": "entity_id",
                "logic": "is",
                "value": "binary_sensor.avas_window, binary_sensor.dining_room_window, binary_sensor.front_door, binary_sensor.gwens_window, binary_sensor.kids_bathroom_window, binary_sensor.lm_bedroom_window, binary_sensor.rm_bedroom_window, binary_sensor.slider, binary_sensor.wyatts_window",
                "valueType": "str"
            },
            {
                "property": "state",
                "logic": "is",
                "value": "closed",
                "valueType": "str"
            }
        ],
        "output_type": "array",
        "output_empty_results": false,
        "output_location_type": "msg",
        "output_location": "payload",
        "output_results_count": 1,
        "x": 290,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "26956a45.92d866",
        "type": "server",
        "z": "",
        "name": "Hass.io",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

I also have a group that I use for my security system that would work in this case, would I be able to use the group for this purpose?

Okay, you may want to make a few changes to your setup. You probably have binary sensors in your system for more than just windows.

From an organizational standpoint, I would rename your sensors. Example:

binary_sensor.kitchen_window --> binary_sensor.window_kitchen
binary_sensor.dining_room_window --> binary_sensor.window_dining_room

By doing this, you can use a regular expression to find all entities that start with binary_sensor.window.

So, in your Get entities node, you need to change the drop-down from string to *.regular expression and then enter a regular expression that will limit the resulting set of entities to the ones that match ^binary_sensor.window*.

This will give you either a count of the number of windows open, in which case you could have a less specific notification saying, “Hey, 2 windows are still open” or output an array that contains the only resulting binary sensors found in the get entities node.

3 Likes

Alright, I went through and did as you suggested and renamed all my entities, and it is definitely easier to organize everything, thank you for the suggestion!

This is what I’ve come up with so far from what I’ve learned from you, and from additional searching.

IT appears to be workinging, but the notify output is not correct and I’m not seeing a way to clean it up. It’s coming out like this:

It's about to rain and the LM Bedroom Window, Kid's Bathroom Window, Gwen's Window, RM Bedroom Window, Wyatt's Window, Ava's Window, Dining Room Window are open.

Seems like it’s not processing apostrophes correctly?

Here’s the code:

[{"id":"a80accf8.747c6","type":"tab","label":"Test Tab","disabled":false,"info":""},{"id":"508684dc.6f8c1c","type":"ha-get-entities","z":"a80accf8.747c6","server":"26956a45.92d866","name":"","rules":[{"property":"entity_id","logic":"is","value":"binary_sensor.window","valueType":"re"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":250,"y":80,"wires":[["ebbe868a.32f398","6bef236e.7d82dc"]]},{"id":"ebbe868a.32f398","type":"template","z":"a80accf8.747c6","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":460,"y":80,"wires":[["ebb822a1.15428","8b43fad6.de77e8"]]},{"id":"ebb822a1.15428","type":"join","z":"a80accf8.747c6","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":630,"y":80,"wires":[["568380ad.b3c5f","304201a2.ad0ece"]]},{"id":"568380ad.b3c5f","type":"api-call-service","z":"a80accf8.747c6","name":"Notify","server":"26956a45.92d866","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"It's about to rain and {{payload}} are open.\",\"title\":\"Left Open\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":750,"y":80,"wires":[["6d76c225.e35f3c"]]},{"id":"8b98746d.bb7958","type":"inject","z":"a80accf8.747c6","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":80,"wires":[["508684dc.6f8c1c","7efe2d8c.8018b4","44a5745a.d007cc"]]},{"id":"6bef236e.7d82dc","type":"debug","z":"a80accf8.747c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":120,"wires":[]},{"id":"8b43fad6.de77e8","type":"debug","z":"a80accf8.747c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":140,"wires":[]},{"id":"304201a2.ad0ece","type":"debug","z":"a80accf8.747c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":40,"wires":[]},{"id":"7efe2d8c.8018b4","type":"ha-get-entities","z":"a80accf8.747c6","server":"26956a45.92d866","name":"","rules":[{"property":"entity_id","logic":"is","value":"binary_sensor.door","valueType":"re"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":250,"y":140,"wires":[["6bef236e.7d82dc"]]},{"id":"44a5745a.d007cc","type":"ha-get-entities","z":"a80accf8.747c6","server":"26956a45.92d866","name":"","rules":[{"property":"entity_id","logic":"is","value":"cover.door_garage","valueType":"re"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":250,"y":20,"wires":[["ebbe868a.32f398","6bef236e.7d82dc"]]},{"id":"6d76c225.e35f3c","type":"debug","z":"a80accf8.747c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":80,"wires":[]},{"id":"26956a45.92d866","type":"server","z":"","name":"Hass.io","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Not sure about the apostrophe problem, but there’s another way to grab that information that I worked out last night using a function node. I’m not a programmer, but I figured out this much at least. Instead of using a combination of template and join nodes, you can do this with a single function node.

  1. Set your get entities nodes to output to an array instead of splitting into individual messages.
  2. Create a function node and write a function like the following:
var arr = [];
toSentence = function(arr){ return arr.join(", ").replace(/,\s([^,]+)$/, ' and $1');};

for (var i=0; i<msg.payload.length; i++) {
    arr.push(msg.payload[i].attributes.friendly_name);
}

var sentence = toSentence(arr); // => dogs, cats and snakes
msg.payload = sentence;
return msg;

And this is with explanations and in your context:

// First, create an empty array.
var windows = []; 

// Next, a function to make an intelligible sentence from the results.
toSentence = function(arr) {
     return windows.join(", ").replace(/,\s([^,]+)$/, ' and $1');
};

// Loop through the `get entities` results and push the `friendly_name` into the empty array.
for (var i=0; i<msg.payload.length; i++) {
    windows.push(msg.payload[i].attributes.friendly_name);
}

var result = toSentence(windows);  // Run the function toSentence on the array `windows`.
msg.payload = result; // Set the payload equal to the result.
return msg;  // return the message.

See if this changes the results.  If not, it may have something to do with how the notification is rendered...
2 Likes

use triple { } around variables in the call-service nodes

2 Likes

That didn’t seem to do anything, unfortunately, as far as the apostrophe’s go.

I guess I just have no idea what I’m doing. I’ve looked through the code as best I can and I somewhat understand what’s going on, but this is what I get notified with

Actually, you were right. I had to add tripple brackets in the function node and now it appears to be working correctly.

[{"id":"d6e3e403.ae1f18","type":"template","z":"13782dc5.dcab82","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{payload.attributes.friendly_name}}}","output":"str","x":460,"y":180,"wires":[["48dd5b29.293864","fa80e21c.84a87"]]}]

This works great! Is there any chance to get them joint with an line break? I tried both
and /n but I could not get it to work.

EDIT: Nvm I alway forgets to use tripple brackets on the service node :sweat_smile: