Automate ceiling fans using temperature difference between sensors

[{"id":"ef60f0756f97cbb7","type":"inject","z":"a531e868a7ed264e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"94","payloadType":"num","x":470,"y":80,"wires":[["3b58028c95265493"]]},{"id":"8d0240b1eac1ade7","type":"inject","z":"a531e868a7ed264e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"72","payloadType":"num","x":470,"y":120,"wires":[["121fe5786a6d7bfb"]]},{"id":"121fe5786a6d7bfb","type":"change","z":"a531e868a7ed264e","name":"topic=\"down\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"down","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":120,"wires":[["c26dcf57a46ff9a6"]]},{"id":"3b58028c95265493","type":"change","z":"a531e868a7ed264e","name":"topic=\"up\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":80,"wires":[["c26dcf57a46ff9a6"]]},{"id":"5a6351507afa2ef9","type":"debug","z":"a531e868a7ed264e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":100,"wires":[]}]

You kind of missed the JOIN node.

[{"id":"10721da48c1bcd7e","type":"join","z":"a531e868a7ed264e","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":910,"wires":[["5a6351507afa2ef9","f6a70f2cd9731569"]]},{"id":"3b58028c95265493","type":"change","z":"a531e868a7ed264e","name":"topic=\"up\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":890,"wires":[["10721da48c1bcd7e"]]},{"id":"121fe5786a6d7bfb","type":"change","z":"a531e868a7ed264e","name":"topic=\"down\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"down","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":930,"wires":[["10721da48c1bcd7e"]]},{"id":"5a6351507afa2ef9","type":"debug","z":"a531e868a7ed264e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":870,"wires":[]},{"id":"f6a70f2cd9731569","type":"function","z":"a531e868a7ed264e","name":"","func":"let temp1 = msg.payload[0];\nlet temp2 = msg.payload[1];\n\nnode.warn(\"Temperature1 \" + temp1);\nnode.warn(\"Temperature2 \" + temp2);\n\nlet answer = temp1 - temp2;\n\nmsg.payload = answer;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":910,"wires":[["22a479949e399bea"]]},{"id":"ef60f0756f97cbb7","type":"inject","z":"a531e868a7ed264e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"94","payloadType":"num","x":160,"y":890,"wires":[["3b58028c95265493"]]},{"id":"8d0240b1eac1ade7","type":"inject","z":"a531e868a7ed264e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"72","payloadType":"num","x":160,"y":930,"wires":[["121fe5786a6d7bfb"]]},{"id":"22a479949e399bea","type":"debug","z":"a531e868a7ed264e","name":"Answer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":910,"wires":[]}]

I think the join node is here.

[{"id":"62fba08944ee6b3b","type":"api-current-state","z":"26f1cb2b488b3697","name":"","server":"cbacdc21.f27ef","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.red_temperature","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"num"},{"property":"topic","propertyType":"msg","value":"redtemp","valueType":"str"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":250,"y":460,"wires":[[],["61696e44d4a7f14c","65bc86b6bab412ab"]]},{"id":"114b1be5e23291b8","type":"inject","z":"26f1cb2b488b3697","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":90,"y":380,"wires":[["62fba08944ee6b3b","6644eb6ebcd0fb51"]]},{"id":"6644eb6ebcd0fb51","type":"api-current-state","z":"26f1cb2b488b3697","name":"","server":"cbacdc21.f27ef","version":2,"outputs":2,"halt_if":"on","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.upstairs_temperature","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"num"},{"property":"topic","propertyType":"msg","value":"upstairstemp","valueType":"str"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":250,"y":200,"wires":[[],["da859696d7470bd2","f855f6a24b7c20b2"]]},{"id":"19a820dcdccc45cf","type":"join","z":"26f1cb2b488b3697","name":"join both sensors","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":300,"wires":[["124acf7998d8b959","ebd3e91057467c10"]]},{"id":"124acf7998d8b959","type":"debug","z":"26f1cb2b488b3697","name":"join debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":180,"wires":[]},{"id":"da859696d7470bd2","type":"debug","z":"26f1cb2b488b3697","name":"upstairs temp debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":100,"wires":[]},{"id":"61696e44d4a7f14c","type":"debug","z":"26f1cb2b488b3697","name":"red temp debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":340,"wires":[]},{"id":"ebd3e91057467c10","type":"function","z":"26f1cb2b488b3697","name":"computation","func":"var payload=msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":400,"wires":[["30f6933281a4f539"]]},{"id":"30f6933281a4f539","type":"debug","z":"26f1cb2b488b3697","name":"computation node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":640,"wires":[]},{"id":"f855f6a24b7c20b2","type":"change","z":"26f1cb2b488b3697","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"upstairstemp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":240,"wires":[[]]},{"id":"65bc86b6bab412ab","type":"change","z":"26f1cb2b488b3697","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"redtemp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":400,"wires":[["19a820dcdccc45cf"]]},{"id":"cbacdc21.f27ef","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

I imported the flow you posted 2 posts back. I didn't get a join node.

I put one in and wrote some stuff to show you what you want to do.

Thanks however I'm lost how do I get the flow you posted into my flow. dumb question, but have to ask

Have you read that post I have mentioned on how to import/export flows (post 26)?

Top right of Node-red screen..... The burger (menu) button.
import
paste the stuff I posted and click on the import button.

yes I read it, and it cleared up the </> button, but wasn't real clear about highlighting the workspace and then using the "burger" menu to use the export. I see the import , but how do I get to your post. I selected the code and tried to paste into the import. I did get a new flow, however it wasn't close to the one I'm working on.

Well, I can't comment on that.

BUT...

Let's not clutter this thread.

I'll be in touch.

@connie You are making progress.
This is the flow you posted above. Ignore the red dotted lines, that's because I don't have those node types installed.

  1. You have to draw a line connecting the first "set msg.topic" node to the join node so data will flow between these nodes.

  2. You are correctly setting different msg.topics - redtemp and upstairstemp.
    Your join node is correctly set to Manual mode and to output after 2 message parts.
    However, you have to "Use the value of msg.topic as the key" not msg.payload.

This error is why in an earlier try you got the output
70.9: 70.9
79.9: 79.9

Fix these two errors and you should get (for example)
"redtemp": 79.9
"upstairstemp": 70.9

When you come to the function node, the values will be available as msg.payload.redtemp and msg.payload.upstairstemp

You are welcome

Awesome! Thank you! really appreciate your patience. Now I'm going to work on the code for the function button to compare the two values and subtract to have a trigger fire if the difference is greater than 10. I am researching the Json functions.

Why?

You have the join bit working - yes?

Copy and paste/share the message here and any problems can be ironed out.

Though I am near the bottom in terms of skills, I don't think there is any benefit in doing what you want using JSON stuff.

Maybe you mean JavaScript?

If so, I have already shown you how to do that.
But there may be a problem with the message's structure. (Who knows)

Post what is coming out of the join node and we will move to the next stage.

[{"id":"19a820dcdccc45cf","type":"join","z":"26f1cb2b488b3697","name":"join both sensors","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":300,"wires":[["124acf7998d8b959","ebd3e91057467c10"]]},{"id":"124acf7998d8b959","type":"debug","z":"26f1cb2b488b3697","name":"join debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":180,"wires":[]}]

Trying to learn. I hope the Join node and debug for it are correctly pasted here
Connie

You really need to practice how to paste things.

That isn't usable as is.

You need to post the message.

Not the nodes.

So on the right of the screen (in the debug window) do as I explained in one of my posts to copy the message and paste it.

12/15/2021, 10:28:53 PMnode: join debug
upstairstemp : msg : Object
object
_msgid: "4e881ba11c5356a6"
payload: object
topic: "upstairstemp"
data: 0

Is this correct?

No.

If it is/was correct, the payload would be expandable.
It is shown as an object.

Thereā€™s a great page in the docs that will explain how to use the debug panel.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

So when @Trying_to_learn asks you to copy and paste the payload or message, he means click the "copy value" button associated.

Ps, forgive me for saying so, but you appear to be fairly new to all this? If so, I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thank you for responding. You are absolutely correct. I am an absolute beginner. I will definitely watch mode red essential. Thatā€™s exactly what I am looking for.
Btw. I was able to write the code to calculate the difference between sensors. Small accomplishment but Iā€™m excited.
Connie

Connie.biehle@gmail.com

1 Like