# Automate ceiling fans using temperature difference between sensors

**URL:** <https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813>\
**Category:** General\
**Created:** [7 December 2021 07:03 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813 "2021-12-07T07:03:33Z")\
**Posts on this page:** 12\
**Page:** 4

<div class="post-metadata">

**Author:** ![MRobi1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrobi1/32/52824_2.png) [@MRobi1](https://discourse.nodered.org/u/MRobi1)\
**Post date:** [18 December 2021 16:07 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/65 "2021-12-18T16:07:51Z")

</div>

For future reference, the home assistant Events:state node that you'd be using as a trigger has the ability to change the msg.topic without needing a change node. Just scroll down to Output Properties and you'll see msg.topic. Change it to a string and type whatever topic you'd like.

By default it is:  
msg.topic = entity id

So in this case, using 2 different temp sensors, each would have a unique entity id so you should be able to output directly into the join node without having to use a change node to modify the topic.

Now if this were me, I would add an additional output property to your events:state node to create a flow variable.  
On the 1st: flow.temp1=entity state  
On the 2nd: flow.temp2=entity state  
Doing it this way you can not only skip using the change node but also won't need the join node. You output them both directly to a function node and use the flow variables to do your calculation. It may sound more advanced but it's likely the simplest way to do this.

---

<div class="post-metadata">

**Author:** ![connie](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@connie](https://discourse.nodered.org/u/connie)\
**Post date:** [18 December 2021 22:33 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/66 "2021-12-18T22:33:15Z")

</div>

Thank you for your ideas, and I will certainly incorporate them on my next project. Presently, I have been able to use the function node to calculate the difference, but haven't had any success to create an output that will trigger the ceiling fan. Do you know how I would write the code in the function node to do this? Any help would be appreciated.  
Connie

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 December 2021 08:06 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/67 "2021-12-19T08:06:33Z")

</div>

> [@connie](#):
>
> Do you know how I would write the code in the function node to do this

Before you can write the code you need to know what it has to do. What output do you want from the function?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [19 December 2021 23:37 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/68 "2021-12-19T23:37:24Z")

</div>

As an extended comment on Colin's post, you need to know what commands / topics are required to be sent to the fan to get it working.

So the first question is, what type of control does it have (Tuya, zigbee, Tasmota, Sonoff, other)?

---

<div class="post-metadata">

**Author:** ![connie](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@connie](https://discourse.nodered.org/u/connie)\
**Post date:** [20 December 2021 00:01 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/69 "2021-12-20T00:01:55Z")

</div>

I need a call service to the fans which are wired to a tp-link wall switch. I want the fans to come on when the temperature difference between two sensors is 9 degrees and shut off when less than 9 degrees.  
Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 December 2021 07:27 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/70 "2021-12-20T07:27:52Z")

</div>

What is a call service?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [20 December 2021 08:51 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/71 "2021-12-20T08:51:43Z")

</div>

Is the wall switch one of these? [https://www.kasasmart.com/us/products/smart-switches](https://www.kasasmart.com/us/products/smart-switches)

There is a [node](https://flows.nodered.org/node/node-red-contrib-tplink) available to control Tp-link kasa switches, the info page says " Under the hood, this uses [TP-Link Smart Home API](https://github.com/plasticrake/tplink-smarthome-api)."  
Someone has posted a [flow](https://flows.nodered.org/flow/091cd7d8862c1cafd0694f7c40680296) too. Perhaps that will give you some hints on connecting your flow with the switch.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 December 2021 20:30 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/72 "2021-12-20T20:30:30Z")

</div>

You may need a bit bigger difference.

If the difference is more than `9` the fan turns on.

If it is less than `9` it turns off....

I think you need to consider hysteresis.  
(Basically it is, for example, turning off when the difference is less than `8`)  
This gives the _program_ a range over which the program is active.

Otherwise it will (could) be turning on and off constantly.

---

<div class="post-metadata">

**Author:** ![connie](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@connie](https://discourse.nodered.org/u/connie)\
**Post date:** [21 December 2021 05:23 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/73 "2021-12-21T05:23:43Z")

</div>

Absolutely! I have experienced the on/off situation.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 December 2021 05:25 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/74 "2021-12-21T05:25:32Z")

</div>

Ok.... It can cause complications/confusion if not expected.

---

<div class="post-metadata">

**Author:** ![connie](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@connie](https://discourse.nodered.org/u/connie)\
**Post date:** [28 December 2021 06:27 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/75 "2021-12-28T06:27:45Z")

</div>

Thank you everyone for your help. I was able to get the automation of the ceiling fans using temperature difference to work successfully. I'll post the solution soon

---

<div class="post-metadata">

**Author:** ![DiverRich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diverrich/32/64523_2.png) [@DiverRich](https://discourse.nodered.org/u/DiverRich)\
**Post date:** [6 July 2024 20:52 UTC](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813/76 "2024-07-06T20:52:41Z")

</div>

Now that I've read all of this I'm curious what the solution was. 😉

[Previous page](https://discourse.nodered.org/t/automate-ceiling-fans-using-temperature-difference-between-sensors/54813.md?page=3)
