If this and that or that or that or that

Hi all. I’m trying to figure out an automation in node red and hoping someone can help.

I have three thermostats at several window sensors and the logic i’m going for is:

if a window is violated & any of the three thermostats are heating or cooling, send an email with the details of the thermostats.

i got very close but it’s sending double or triple emails because two or three thermostats might be heating or cooling.

Screen shot shows my existing logic.

What’s in the state nodes? Export the flow so that someone may be able to trace your logic.

[{"id":"e286e3660606b50e","type":"api-current-state","z":"14c365016f5c23b5","name":"Z17 Violated","server":"325b32af.71ce1e","version":3,"outputs":2,"halt_if":"Normal","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.elkm1_jm_bedroom_1a","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"zone","propertyType":"msg","value":"","valueType":"entityState"},{"property":"zone","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":270,"y":260,"wires":[["a8136d30535e0dd4","df1f5da04ed1be57","2cbdc1e94ec9b26b"],[]]},{"id":"5a3ec7d01bd279a0","type":"e-mail","z":"14c365016f5c23b5","server":"smtp.office365.com","port":"587","secure":false,"tls":true,"name":"[email protected]","dname":"Send email","x":1210,"y":380,"wires":[]},{"id":"df1f5da04ed1be57","type":"api-current-state","z":"14c365016f5c23b5","name":"Right Therm is not idle","server":"325b32af.71ce1e","version":3,"outputs":2,"halt_if":"idle","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.rightside_hvacaction","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rtherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"rtherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":260,"wires":[["bcb2c50706865797"],[]]},{"id":"2cbdc1e94ec9b26b","type":"api-current-state","z":"14c365016f5c23b5","name":"Left Therm is not idle","server":"325b32af.71ce1e","version":3,"outputs":2,"halt_if":"idle","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.leftside_hvacaction","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"ltherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"ltherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":320,"wires":[["bcb2c50706865797"],[]]},{"id":"300c630574829432","type":"function","z":"14c365016f5c23b5","name":"Email info","func":"msg.topic = \"Haledon Window Open\"\nmsg.payload = \"A window is open while heating or cooling. \"\n    + \"<br>\"\n    + \"<br> Haledon\"\n    + \"<br>\"\n    + \"<br> Window Information\"\n    + \"<br>\"\n    + \"<br> - Zone: \" + msg.zone.attributes.index\n    + \"<br> - Name: \" + msg.zone.attributes.friendly_name\n    + \"<br> - Status: \" + msg.zone.attributes.logical_status\n    + \"<br>\"\n    + \"<br> Thermostat Information\"\n    + \"<br>\"\n    + \"<br> Right Side Thermostat\"\n    + \"<br> - Current Temperature: \" + msg.rtherm.attributes.current_temperature\n    + \"<br> - Setpoint: \" + msg.rtherm.attributes.temperature\n    + \"<br> - Fan Mode: \" + msg.rtherm.attributes.fan_mode\n    + \"<br> - Humidity: \" + msg.rtherm.attributes.current_humidity\n    + \"<br> - HVAC Mode: \" + msg.rtherm.state\n    + \"<br>\"\n    + \"<br> Left Side Thermostat\"\n    + \"<br> - Current Temperature: \" + msg.ltherm.attributes.current_temperature\n    + \"<br> - Setpoint: \" + msg.ltherm.attributes.temperature\n    + \"<br> - Fan Mode: \" + msg.ltherm.attributes.fan_mode\n    + \"<br> - Humidity: \" + msg.ltherm.attributes.current_humidity\n    + \"<br> - HVAC Mode: \" + msg.ltherm.state\n    + \"<br>\"\n    + \"<br> Basement Thermostat\"\n    + \"<br> - Current Temperature: \" + msg.bastherm.attributes.current_temperature\n    + \"<br> - Setpoint: \" + msg.bastherm.attributes.temperature\n    + \"<br> - Fan Mode: \" + msg.bastherm.attributes.fan_mode\n    + \"<br> - Humidity: \" + msg.bastherm.attributes.current_humidity\n    + \"<br> - HVAC Mode: \" + msg.bastherm.state\n return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1120,"y":240,"wires":[["5a3ec7d01bd279a0"]]},{"id":"a8136d30535e0dd4","type":"api-current-state","z":"14c365016f5c23b5","name":"basement therm is not idle","server":"325b32af.71ce1e","version":3,"outputs":2,"halt_if":"idle","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.basement_hvacaction","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"bastherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"bastherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":520,"y":200,"wires":[["bcb2c50706865797"],[]]},{"id":"cb0c30b63a65faf3","type":"inject","z":"14c365016f5c23b5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"10","topic":"","payload":"","payloadType":"date","x":80,"y":260,"wires":[["e286e3660606b50e"]]},{"id":"bcb2c50706865797","type":"api-current-state","z":"14c365016f5c23b5","name":"basement therm full status","server":"325b32af.71ce1e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.thermostat_32_f2_72_group_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"bastherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"bastherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":780,"y":260,"wires":[["5e78f28b90e5e3d8"]]},{"id":"5e78f28b90e5e3d8","type":"api-current-state","z":"14c365016f5c23b5","name":"Right Therm full status","server":"325b32af.71ce1e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.thermostat_right_side","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rtherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"rtherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":800,"y":340,"wires":[["0c8d3a462d1991ca"]]},{"id":"0c8d3a462d1991ca","type":"api-current-state","z":"14c365016f5c23b5","name":"Left Therm full status","server":"325b32af.71ce1e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.thermostat_left_side","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"ltherm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"ltherm","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1040,"y":300,"wires":[["300c630574829432"]]},{"id":"325b32af.71ce1e","type":"server","name":"Home Assistant","addon":true}]

there are multiple ways how to do that depending on details and corner cases. But sometimes it requires a different view :wink:

Try this way:

  • pass the message from your window violation check to get entitities node
  • Configure get entitities node to Count mode, seeking for thermostats in state you need
  • Pass the output to a decision (switch) node. If the payload is greater than zero then send a message

thanks for the reply maxym. would you mind providing an example of how to do this? I’ve been getting through node red pretty well for basic things but I’m not a programmer.

Different task but the same idea:

and settings of GetEntities node. It looks for all people entities which are set to Home state.
Obviously, your node will look for thermostat entities and their state. Get Entities can look for entities using regular expression patterns or just having a list of entities. There are many options. And then matches their attributes (incl. state) against expected values.

I don’t think I’m doing something correctly here.



Not sure what both the first images represent. Those are attempts?
Anyway, in both cases, those brackets around entity names are likely wrong.

Also, you can aggregate settings, especially using the regular expression. For example, the below should be enough to match rightside_hvacation and basement_hvacation having a state different than idle.

image

The first 2 images were the top and bottom of the node configuration so you can see the whole thing. seems the aggregate worked. Will the entities node not allow you to add more that one entity otherwise? for the switch mode i had to add =0,=1,=2,=3 and only link =1,=2,=3 to the next node. correct?

not sure what you mean

Thanks for you help on this. Which part did you not know what i meant?
for the entities node - it seemed to only work when i used the aggregate and not the multiple entries.
for the switch node, i was just making sure i fully understood. since there are 3 thermostats i had to put 4 entries in it based on what the count may be. 0 would be if all thermostats are idle and 1-3 would be a if some or all are not idle.

If I understood your initial need correctly, then you have to create the same flow (window violation sensor → get entities) for each window.sending a message when count>0 could be common to all of them.

name of sensor which triggers the action should be found in the message passed from node to node. If not, you can always pick it up where available and set some other attribute with it (ie topic or anything you want)

Ahh I found your initial need is to send info about thermostats (not a window). Collecting thermostats names should be possible with get entities too. Check if not available already next to payload containing count. check various options of get entity node. use debug node in object mode to inspect a whole message message