Comparing temperature sensor values

Im trying to compare two temperature sensor values in a current state node; one darksky outside temperature and one living room sensor. The goal is to close window shutters on hot days as long as its hotter outside than inside.

For some reason the test always results in False, regardless if I try <, >, <= or >=.

If I compare either sensor with a number I type in, it works fine.

[ { "id": "66bbaa80.b522e4", "type": "api-current-state", "z": "c9c66103.680d8", "name": "warmer inside", "server": "469aa6d5.5063f8", "version": 1, "outputs": 2, "halt_if": "sensor.living_temperature_2", "halt_if_type": "entity", "halt_if_compare": "gt", "override_topic": true, "entity_id": "sensor.dark_sky_temperature", "state_type": "num", "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "blockInputOverrides": true, "x": 300, "y": 740, "wires": [ [ "f0c4f7fb.ee2368", "cb7ee5cd.f1e2b8" ], [ "f3bac0df.21769", "7130ecf9.6cc224" ] ] }, { "id": "469aa6d5.5063f8", "type": "server", "z": "", "name": "Home Assistant" } ]

This is the “warmer outside” node:

1 Like

Typically when these kind of tests are failing (are giving the same result whatever the value), it can be related to the type of data.
You assume 17.4 is a number, but in fact if it is a string “17.4” then your test will not give the expected result.
Can you check that?

GV

They are both numbers AFAICT. Not sure how I determine that for sure? But when I replace the inside living temperature sensor with a numeric value, the test works fine for either sensor, meaning I can compare the dark sky outside temp to a number or the inside living temp to a number, and that works as expected. Its only when I compare both sensors that I get incorrect results.

When I connect a debug node I get:

sensor.living_temperature_2 : msg.payload : number
22.4

When i swap the sensor entities around the debug node gives:

sensor.dark_sky_temperature : msg.payload : number
13.9

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/conditionals.html#entity-and-preventity

entity is a reference to the trigger entity not any entity in HA. You want to use the JSONata Expression and $entities() to check against another entities property.

$entities("sensor.living_temperature").state

2 Likes

Thank you! Finally getting there. Turns out in jsonata the entity state is indeed a string, but this solves:

$number($entities("sensor.dark_sky_temperature").state) > $number($entities("sensor.living_temperature_2").state)

Thanks again, been banging my head on this for a long time.

I have been trying to get the same to work for a long time. How do you only trigger once when the condition meets the outside temperature is greater then the inside?

I have it notify my phone but every time the outside temp rises it triggers and notifies me.

Ok, good for you.

Next time remember you can use the Developer Tools->Template part to check your code

How do you only trigger once when the condition meets the outside temperature is greater then the inside?

Not sure I understand the question. The code I posted above only triggers when outside temp (sensor.dark_sky_temperature) is greater than inside temp (sensor.living_temperature_2). But that was just to test the code. The logic I actually use is a little more complicated. First I check if a hot day is forecast (max predicted temp > 28C), if that is case then I close the blinds when two other criteria are met:

  • inside its getting warm, I set that to > 25C (just one nice summer day doesnt heat up my house too much and I prefer seeing the sun) and
  • when outside its currently warmer than inside.

This is the entire flow:

[{"id":"fa467dd1.fad86","type":"poll-state","z":"c9c66103.680d8","name":"Check hot day","server":"469aa6d5.5063f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"600","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.dark_sky_daytime_high_temperature_0d","state_type":"num","halt_if":"28","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"x":70,"y":620,"wires":[["b95efac6.6e7f78"],[]]},{"id":"b95efac6.6e7f78","type":"api-current-state","z":"c9c66103.680d8","name":"Living >25C and hotter outside","server":"469aa6d5.5063f8","version":1,"outputs":2,"halt_if":"$number($entities(\"sensor.living_temperature_2\").state )> 25 \tand  \t$number($entities(\"sensor.dark_sky_temperature\").state)  > $number($entities(\"sensor.living_temperature_2\").state)","halt_if_type":"jsonata","halt_if_compare":"jsonata","override_topic":true,"entity_id":"sensor.dark_sky_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":310,"y":620,"wires":[["2501aa78.eafb76","716917d7.302a58"],["f7cdae29.fd8ba","ead5bcd2.bf326"]]},{"id":"716917d7.302a58","type":"api-call-service","z":"c9c66103.680d8","name":"","server":"469aa6d5.5063f8","version":1,"debugenabled":false,"service_domain":"cover","service":"close_cover","entityId":"cover.bf41bbbdb082541f23wq8x","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":800,"y":600,"wires":[[]]},{"id":"ead5bcd2.bf326","type":"api-call-service","z":"c9c66103.680d8","name":"","server":"469aa6d5.5063f8","version":1,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.bf41bbbdb082541f23wq8x","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":800,"y":640,"wires":[[]]},{"id":"469aa6d5.5063f8","type":"server","z":"","name":"Home Assistant"}]

edit: now I get it, you only want to trigger once and once only. I dont care about that because I can send a close command as often as I want, it does nothing if the blinds are already closed. Let me get back to you on that.

OK, to send only once, you could use a delay node. Set the action to “rate limit” and you can limit it to once per day. Then click the “drop intermediate messages”

For this type of scenario, I use the “traffic light” node (https://flows.nodered.org/node/node-red-contrib-traffic).
E.g. at 3am in the morning, you send a “green” message to the traffic light.
As soon as your condition is true, you send a “red” message. With this type of solution, even when the dark sky temperature changes and if the test is still true, it will be blocked by the traffic light.

GV

How are you sending the “red” message when the condition becomes true?

Here is an example… Every 5 minutes, I check that a particular element is above 75%. If yes, I send a telegram message and put the traffic light to off (red). If is goes below 75% then green again, and a reset at night.

[{"id":"7e36a4bd.1e9b2c","type":"influxdb in","z":"779cea26.b667a4","influxdb":"97a42112.cc31e","name":"Disk ?","query":"SELECT mean(\"used_percent\") FROM \"disk\" WHERE (\"device\" = 'mapper/pve-vm--103--disk--0')  AND time > now() - 15m","rawOutput":false,"precision":"","retentionPolicy":"","x":290,"y":440,"wires":[["1643b19b.d2f73e"]]},{"id":"d7e40cb1.d53b8","type":"traffic","z":"779cea26.b667a4","name":"Feu","property_allow":"payload","filter_allow":"on","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"off","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":570,"y":360,"wires":[["de056333.9db07","a850d8fd.ee7098"]]},{"id":"1643b19b.d2f73e","type":"switch","z":"779cea26.b667a4","name":"75% ?","property":"payload[0].mean > 75","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":440,"wires":[["d7e40cb1.d53b8"],["d2982e72.9af75"]]},{"id":"de056333.9db07","type":"telegrambot-notify","z":"779cea26.b667a4","name":"75 %","bot":"6e4e0931.7f7b58","chatId":"782589784","message":"Le disque de download.giraud.me est occupé à plus de 75%","parseMode":"","x":750,"y":360,"wires":[]},{"id":"6e459674.720d98","type":"cronplus","z":"779cea26.b667a4","name":"Check 5'","outputField":"payload","timeZone":"","options":[{"topic":"5_minutes","payload":"","type":"str","expression":"0 3/5 * * * *"}],"x":160,"y":440,"wires":[["7e36a4bd.1e9b2c"]]},{"id":"e9c28a0b.c1c2a8","type":"cronplus","z":"779cea26.b667a4","name":"Daily reset","outputField":"payload","timeZone":"","options":[{"topic":"Every day","payload":"","type":"str","expression":"0 0 3 * * *"}],"x":350,"y":520,"wires":[["d2982e72.9af75"]]},{"id":"d2982e72.9af75","type":"change","z":"779cea26.b667a4","name":"On","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":480,"wires":[["d7e40cb1.d53b8"]]},{"id":"a850d8fd.ee7098","type":"change","z":"779cea26.b667a4","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":440,"wires":[["d7e40cb1.d53b8"]]},{"id":"97a42112.cc31e","type":"influxdb","z":"","hostname":"192.168.9.134","port":"8086","protocol":"http","database":"telegraf","name":"","usetls":false,"tls":""},{"id":"6e4e0931.7f7b58","type":"telegrambot-config","z":"","botname":"MyTelegramBot","usernames":"","chatIds":"12345678","pollInterval":"300"}]

GV

1 Like

Thank you. Works perfect.

Hello,
trying to do exactly the same thing,
i want to send a push message on my iphone, when it is time to close the windows in the morning if outside temp is hotter then inside, and in the evening, the opposite, to know when i can open all the windows.

Could you tell me what is the “Daily reset” object ?
Could you post your config?

Thanks

I made a similar automation using a timerange, bigtimer, and a function node… it sends a list of opened windows when triggered, and does a lot of logic in the background that changes output as the weather changes.

One thing to consider here, is the times when it may be warmer outside during winter. In this case you may want windows open. Conversely closing windows when it is colder in winter makes more sense. Also, maybe when it is like 68F-78F outside, keeping the windows open regardless of inside temp may be desired, etc… Fortunately this is a nodered topic, so there are plenty of tools to use to get this done.

Just wanted to mention this since it is summer time (north of equator anyways). So less complicated automations may work for now, but could trigger an issue with WAF as it cools down. Consider this now to keep that WAF 100% all year long. :wink:

Very good observations indeed :slight_smile:

would you help me copy pasting some of your nodered code (bigtimer timerange and function node ?)

thanks in advance,

Here is a shortened version of what I use now. It takes one outdoor temp (backyard_temp in this case… that hourly temp is an appendix I just forgot to delete), and compares it to several indoor temp sensors, but you can change these to whatever you like (just be sure to edit the function node and list nodes accordingly). It does require making a group of entities that contains all of your ‘perimeter’ nodes. In this context, ‘perimeter’ is defined as openings that will let outside air inside (so like not a garage cover for example). The parts on top are a bonus that I kept in there; those nodes will turn the ac or heater off if doors/windows stay open too long, then turn it back on to the correct mode when the perimeter is later closed. This version only shows a few door/window entities, but my actual flow has like 40 entities… just extend the delay chain on the bottom to add more.

[{"id":"2174f4f6.ffe5dc","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.thermostat_temperature","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":480,"y":500,"wires":[["92ba5710.095348"]]},{"id":"b26a86ee.f64498","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.master_slider_temp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":420,"wires":[["92ba5710.095348"]]},{"id":"3e61bf5b.c0a8","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.dining_slider_temp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":560,"wires":[["92ba5710.095348","e59d3815.ea9f58"]]},{"id":"d273f4bd.1ea208","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.backyard_temp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":450,"y":360,"wires":[["92ba5710.095348","ca22ba4c.96ec68"]]},{"id":"ca22ba4c.96ec68","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":170,"y":420,"wires":[["b26a86ee.f64498","ed3f714b.bb3e5"]]},{"id":"d445e398.54fd","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":170,"y":500,"wires":[["2174f4f6.ffe5dc","6269b8f8.bb7298"]]},{"id":"6269b8f8.bb7298","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":170,"y":560,"wires":[["3e61bf5b.c0a8"]]},{"id":"771de382.eca9ec","type":"change","z":"e44a471b.b2ab38","name":"","rules":[{"t":"set","p":"complete","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":560,"wires":[["92ba5710.095348"]]},{"id":"92ba5710.095348","type":"join","z":"e44a471b.b2ab38","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":790,"y":480,"wires":[["612b3709.b8b7a8"]]},{"id":"612b3709.b8b7a8","type":"function","z":"e44a471b.b2ab38","name":"Open the windows?","func":"// Takes an array of temperatures where payload[0]\n// is the outside temp, and the rest are inside\n// temps.\n\n// A payload of \"open_windows\" is sent on the 1st\n// output if it is warmer outside and outside is\n// <=80F, or if it is cooler outside and outside\n// is >66F.\n\n// A payload of \"close_windows\" is sent on\n// the 2nd output if it is warmer outside and\n// outside is >80F, or if it is cooler outside \n// and outside is <=66F. \n\nvar i = 0;\nvar maxTemp = 0;\nvar minTemp = 200;\n\n// Store the highest & lowest temps inside\nfor(i = 1; i < msg.payload.length; i++) {\n    if(msg.payload[i] > maxTemp) {\n        maxTemp = msg.payload[i];\n    }\n    if(msg.payload[i] < minTemp) {\n        minTemp = msg.payload[i];\n    }\n}\n\n// outside is warmer\nif(msg.payload[0] > maxTemp) {\n    // hot outside\n    if(msg.payload[0] > 85) {\n        msg.payload = \"close_windows\";\n        return [null,msg];\n    }\n    // comfy to cold outside (warm winter afternoon)\n    else {\n        msg.payload = \"open_windows\";\n        return [msg,null];\n    }\n}\n// outside cooler\nelse if(msg.payload[0] < minTemp) {\n    // outside is comfy to hot (cool summer evenings)\n    if(msg.payload[0] > 68) {\n        msg.payload = \"open_windows\";\n        return [msg,null];\n    }\n    // cold outside\n    else {\n        msg.payload = \"close_windows\";\n        return [null,msg];\n    }\n}\nelse {\n    return [null,null];  // only if all 3 temps are equal\n}","outputs":2,"noerr":0,"x":990,"y":480,"wires":[["708b7d06.c43e24"],["1468880c.7d2d08"]],"outputLabels":["open_windows","close_windows"]},{"id":"708b7d06.c43e24","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"group.climate_perimeter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1070,"y":420,"wires":[[],["d8a8d20c.35507"]]},{"id":"1468880c.7d2d08","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"group.climate_perimeter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1070,"y":540,"wires":[["574192e1.06204c"],[]]},{"id":"7f08e638.5739a8","type":"bigtimer","z":"e44a471b.b2ab38","outtopic":"","outpayload1":"","outpayload2":"","name":"Big Timer","comment":"","lat":"38.59415","lon":"-121.36612","starttime":"0","endtime":"0","starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":120,"y":280,"wires":[[],["2169a260.a0871e"],[]]},{"id":"503026b2.8f6968","type":"interval-length","z":"e44a471b.b2ab38","format":"json","bytopic":false,"minimum":"70","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"secs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":true,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":">70sec","x":1380,"y":660,"wires":[["4f15fcf0.ac9994"],[]]},{"id":"accbbd16.ac353","type":"function","z":"e44a471b.b2ab38","name":"kev: Open window reminder","func":"msg.payload = {\n\tchatId:\"xxx\", //my phone\n\ttype:\"message\",\n\tcontent: \"OK to open windows\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1440,"y":360,"wires":[[]]},{"id":"a7e262b6.8b2c2","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"person.kevin","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1160,"y":660,"wires":[["503026b2.8f6968"],[]]},{"id":"1088cb53.c63da5","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"person.kevin","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1220,"y":300,"wires":[["63d88b20.288bc4"],[]]},{"id":"2169a260.a0871e","type":"time-range-switch","z":"e44a471b.b2ab38","name":"","lat":"38.59415","lon":"-121.36612","startTime":"8:00","endTime":"0:00","startOffset":0,"endOffset":0,"x":150,"y":360,"wires":[["d273f4bd.1ea208","13448019.0d639"],[]]},{"id":"ffc7e39c.4d5cf","type":"change","z":"e44a471b.b2ab38","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":360,"wires":[["d8a8d20c.35507"]]},{"id":"d8a8d20c.35507","type":"stoptimer","z":"e44a471b.b2ab38","duration":"20","units":"Second","payloadtype":"str","payloadval":"stop","name":"","x":1150,"y":360,"wires":[["1088cb53.c63da5"],[]]},{"id":"574192e1.06204c","type":"stoptimer","z":"e44a471b.b2ab38","duration":"20","units":"Second","payloadtype":"str","payloadval":"stop","name":"","x":1150,"y":600,"wires":[["a7e262b6.8b2c2"],[]]},{"id":"ac62ba47.6b17d8","type":"change","z":"e44a471b.b2ab38","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":600,"wires":[["574192e1.06204c"]]},{"id":"b3700890.f34b08","type":"server-state-changed","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"entityidfilter":"group.climate_perimeter","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":220,"y":140,"wires":[["ffc7e39c.4d5cf","ef16f3.de46e91"],["ac62ba47.6b17d8","4aa14b4f.4feeb4"]]},{"id":"acb402c.a92f7","type":"function","z":"e44a471b.b2ab38","name":"kev: Close these windows","func":"var text = msg.payload;\nmsg.payload = {\n\tchatId:\"xxx\", //my phone\n\ttype:\"message\",\n\tcontent: \"Please close:\\r\\n\"+text\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1550,"y":1000,"wires":[[]]},{"id":"9c56e04b.098c5","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.lauren_window_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":920,"wires":[["97edc76d.8a2208","e96d3f9f.eeb44"],["97edc76d.8a2208"]]},{"id":"a5dba0d5.11063","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580,"y":920,"wires":[["9c56e04b.098c5"]]},{"id":"84a770c9.374c2","type":"join","z":"e44a471b.b2ab38","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1490,"y":940,"wires":[["acb402c.a92f7"]]},{"id":"97edc76d.8a2208","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1150,"y":960,"wires":[["c29f31a3.e87fd"]]},{"id":"c29f31a3.e87fd","type":"change","z":"e44a471b.b2ab38","name":"","rules":[{"t":"set","p":"complete","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":1000,"wires":[["b21219e4.937778"]]},{"id":"e96d3f9f.eeb44","type":"change","z":"e44a471b.b2ab38","name":"payload to friendly_name","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.friendly_name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":920,"wires":[["84a770c9.374c2"]]},{"id":"b21219e4.937778","type":"change","z":"e44a471b.b2ab38","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":1040,"wires":[["84a770c9.374c2"]]},{"id":"cc5668c6.a82538","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.master_window_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":850,"y":740,"wires":[["fae426f3.5502a8"],[]]},{"id":"4f15fcf0.ac9994","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":740,"wires":[["cc5668c6.a82538","cdda4d14.49e21"]]},{"id":"fae426f3.5502a8","type":"change","z":"e44a471b.b2ab38","name":"payload to friendly_name","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.friendly_name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":740,"wires":[["84a770c9.374c2"]]},{"id":"bd359611.caf7f8","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.master_window_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":850,"y":800,"wires":[["5f3e7260.43e3bc"],[]]},{"id":"cdda4d14.49e21","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":800,"wires":[["bd359611.caf7f8","ec431a99.804598"]]},{"id":"5f3e7260.43e3bc","type":"change","z":"e44a471b.b2ab38","name":"payload to friendly_name","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.friendly_name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":800,"wires":[["84a770c9.374c2"]]},{"id":"ffcb7cda.5e4a6","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.lauren_window_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":850,"y":860,"wires":[["b04ded47.dab8"],[]]},{"id":"ec431a99.804598","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":860,"wires":[["ffcb7cda.5e4a6","a5dba0d5.11063"]]},{"id":"b04ded47.dab8","type":"change","z":"e44a471b.b2ab38","name":"payload to friendly_name","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.friendly_name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":860,"wires":[["84a770c9.374c2"]]},{"id":"63d88b20.288bc4","type":"interval-length","z":"e44a471b.b2ab38","format":"json","bytopic":false,"minimum":"70","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"secs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":true,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":">70sec","x":1440,"y":300,"wires":[["accbbd16.ac353"],[]]},{"id":"13448019.0d639","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"weather.weather_hourly","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":450,"y":280,"wires":[["82008715.c393b8"]]},{"id":"6ad89635.1e7258","type":"api-current-state","z":"e44a471b.b2ab38","name":"Thermostat heat?","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"heat","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"climate.thermostat_mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":950,"y":220,"wires":[["ddbb7748.70ffe8"],[]]},{"id":"ddbb7748.70ffe8","type":"api-call-service","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"climate.thermostat_mode","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1340,"y":160,"wires":[["ed036348.8ac29"]]},{"id":"9483d248.2c4da","type":"api-call-service","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"debugenabled":false,"service_domain":"climate","service":"set_hvac_mode","entityId":"climate.thermostat_mode","data":"{\"hvac_mode\":\"heat\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1820,"y":160,"wires":[[]]},{"id":"ed036348.8ac29","type":"ha-wait-until","z":"e44a471b.b2ab38","name":"Wait for perimeter to close","server":"684e76d1.f36e78","outputs":1,"entityId":"group.climate_perimeter","property":"state","comparator":"is","value":"off","valueType":"str","timeout":0,"timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":1570,"y":160,"wires":[["9483d248.2c4da"]]},{"id":"ef16f3.de46e91","type":"stoptimer","z":"e44a471b.b2ab38","duration":"120","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":690,"y":200,"wires":[["6ad89635.1e7258","977a6a08.ecdbe8"],[]]},{"id":"4aa14b4f.4feeb4","type":"change","z":"e44a471b.b2ab38","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":200,"wires":[["ef16f3.de46e91"]]},{"id":"24a2091.06660f6","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.master_temperature","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":460,"wires":[["92ba5710.095348"]]},{"id":"ed3f714b.bb3e5","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":170,"y":460,"wires":[["24a2091.06660f6","d445e398.54fd"]]},{"id":"e59d3815.ea9f58","type":"delay","z":"e44a471b.b2ab38","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":750,"y":600,"wires":[["771de382.eca9ec"]]},{"id":"82008715.c393b8","type":"change","z":"e44a471b.b2ab38","name":"Current Temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":280,"wires":[[]]},{"id":"8db7f3d4.c7468","type":"trigger-state","z":"e44a471b.b2ab38","name":"Thermostat Mode","server":"684e76d1.f36e78","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"climate.thermostat_mode","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":4,"customoutputs":[{"outputId":"olf1u8jzh5c","messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"heat"},{"outputId":"i52lss6i20q","messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"cool"}],"outputinitially":false,"state_type":"str","x":690,"y":120,"wires":[[],[],[],["4d0d15d5.d4b3fc"]]},{"id":"1a4c762c.dbbdaa","type":"api-call-service","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"debugenabled":false,"service_domain":"climate","service":"set_hvac_mode","entityId":"climate.thermostat_mode","data":"{\"hvac_mode\":\"cool\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1820,"y":220,"wires":[[]]},{"id":"79a8bbdd.2d42f4","type":"ha-wait-until","z":"e44a471b.b2ab38","name":"Wait for perimeter to close","server":"684e76d1.f36e78","outputs":1,"entityId":"group.climate_perimeter","property":"state","comparator":"is","value":"off","valueType":"str","timeout":0,"timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":1570,"y":220,"wires":[["1a4c762c.dbbdaa"]]},{"id":"de351d7b.c58da","type":"api-call-service","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"climate.thermostat_mode","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1340,"y":220,"wires":[["79a8bbdd.2d42f4"]]},{"id":"4d0d15d5.d4b3fc","type":"api-current-state","z":"e44a471b.b2ab38","name":"","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"group.climate_perimeter","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1010,"y":160,"wires":[["de351d7b.c58da"],[]]},{"id":"977a6a08.ecdbe8","type":"api-current-state","z":"e44a471b.b2ab38","name":"Thermostat cool?","server":"684e76d1.f36e78","version":1,"outputs":2,"halt_if":"cool","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"climate.thermostat_mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":950,"y":280,"wires":[["de351d7b.c58da"],[]]},{"id":"684e76d1.f36e78","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Most of the flow uses pretty standard methods that I’ve learned here and there on these forums. Like creating the list using delay+join nodes, and repeated message prevention with interval nodes… those are good things to know in general. The bigtimer is just feeding a pulse every minute to the time range node; it’s doing other stuff on the flow that I didn’t upload, but if you don’t need it just a repeat node may be more efficient there. The function in the middle is doing all of the magic… and it leaves a lot of room for improvement (like feeding it a text sensor so you can adjust the set points from the HA dashboard, factoring in humidity, etc). Please share if you come up with better code for that function.

What’s missing of course, is my Telegram node at the ends to send the actual open/close window notifications (too much private info to remove on that one). If you have Telegram setup in nodered, this should be pretty simple to complete. You can see where to fill in your chatid in the 2 ending function nodes… then feed that to your working Telegram node et voila. If you use other systems to send notifications to your phone, then you may have to adjust the function nodes so they send payloads that are compatible with your system.

2 Likes

Help with JSONata
I need to compare the expression with another sensor, but I think this expression is wrong, the temperature should be + 2.
$entities("sensor.temperature_158d00045c2ea8").state + 2

1 Like

Could You please expand that more detailed?

I do have it working but I would like to understand. What this state node read from this entity. field?
image