Thought this was going to be simple, but I am having a heck of a time getting this right. Read a few threads that are attempting to do something similar, but I was not able get things working from those either.
My overall goal is to compare the temperature readings from two sensors in adjoining rooms. If the difference in temperature is greater than say 3 degrees I want to turn on a ceiling fan. I want to do this regardless of which sensor has the higher temperature.
My thoughts were to get the temperature values from the current state node, convert those strings to numbers, store those values as a flow context and then use a function node to get the absolute value of the difference between the two values. I got as far as storing the values as a flow context (I think?) Any manipulation of the flow context values throws some sort of error. Often NaN (not a number). If I make the function node just try to output the flow context as a msg I get am undefined error?
[{"id":"7aa8c4c163a28492","type":"tab","label":"Flow 8","disabled":false,"info":"","env":[]},{"id":"a628025a0f27d945","type":"debug","z":"7aa8c4c163a28492","name":"debug 64","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":540,"y":300,"wires":[]},{"id":"ee4a1bc6d22b5341","type":"api-current-state","z":"7aa8c4c163a28492","name":"Family Room Temp","server":"b4312dad.7f0fd","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.family_room_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":130,"y":140,"wires":[["8593fbb9d1cad670"]]},{"id":"5463b5fa51bb3d2d","type":"api-current-state","z":"7aa8c4c163a28492","name":"Kitchen Temp","server":"b4312dad.7f0fd","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.kitchen_sensor_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":120,"y":200,"wires":[["904e7fdac7afb6aa"]]},{"id":"b6be20abed27559a","type":"inject","z":"7aa8c4c163a28492","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["ee4a1bc6d22b5341","5463b5fa51bb3d2d"]]},{"id":"e5b865c328a3fedf","type":"change","z":"7aa8c4c163a28492","name":"Kitchen to Flow","rules":[{"t":"set","p":"Kitchen_Temp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":200,"wires":[["f2e382aa069fb9e9"]]},{"id":"8593fbb9d1cad670","type":"function","z":"7aa8c4c163a28492","name":"Fam Convert to #","func":"var text = msg.payload;\nmsg.payload = parseFloat(text);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":140,"wires":[["758f65fbde507b0b"]]},{"id":"904e7fdac7afb6aa","type":"function","z":"7aa8c4c163a28492","name":"Kitchen Convert to #","func":"var text2 = msg.payload;\nmsg.payload = parseFloat(text2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":200,"wires":[["e5b865c328a3fedf"]]},{"id":"ead9b1e2a558fe7c","type":"debug","z":"7aa8c4c163a28492","name":"debug 66","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":140,"wires":[]},{"id":"19824ef575a85fd0","type":"function","z":"7aa8c4c163a28492","name":"Flow to msg.payload","func":"msg.payload = flow.Kitchen_Temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":300,"wires":[["a628025a0f27d945"]]},{"id":"9ece613225e4482d","type":"inject","z":"7aa8c4c163a28492","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":300,"wires":[["19824ef575a85fd0"]]},{"id":"f2e382aa069fb9e9","type":"debug","z":"7aa8c4c163a28492","name":"debug 67","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":200,"wires":[]},{"id":"758f65fbde507b0b","type":"change","z":"7aa8c4c163a28492","name":"Fam to Flow","rules":[{"t":"set","p":"Kitchen_Temp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["ead9b1e2a558fe7c"]]},{"id":"b4312dad.7f0fd","type":"server","name":"Home Assistant","addon":true}]