# Controlling smart socket based on data change

**URL:** <https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244>\
**Category:** General\
**Created:** [2 March 2022 16:49 UTC](https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244 "2022-03-02T16:49:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JHScen](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@JHScen](https://discourse.nodered.org/u/JHScen)\
**Post date:** [2 March 2022 16:49 UTC](https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244/1 "2022-03-02T16:49:11Z")

</div>

I am trying to create a flow that turns a smart socket on and off based on the data that is received.

For example, if Temp \<=15 turn on and if temp \>=22 turn off.

I would also like to customise it further to only do it during certain times of day.

I have the data but am a bit stumped on where to go with it from there?

My thought was a function node, but up to this point cannot figure out how I would do it.

Any help or guidance would be greatly appreciated.

---

<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:** [2 March 2022 17:20 UTC](https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244/2 "2022-03-02T17:20:28Z")

</div>

You don't say how you receive temperature data, nor how you control the smart socket so I'll assume you use MQTT.

Something like this should work

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db121933e307cf7c9e944eb08238862b4bab383e.jpeg)

I used a simple logic gate node. No doubt it can be achieved without installing any custom nodes too.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [3 March 2022 02:38 UTC](https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244/3 "2022-03-03T02:38:47Z")

</div>

Yep or if you want to use custom nodes - then look at the [node-red-contrib-sun-position (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-sun-position)

It has a heap of nodes in there for time control - the one for you is within-time

Lets you compare the current time to a range of times/days and branch to one of two outputs depending on where the time is within the specific range or not.

You can just put that in front of @jbudd switch node above and you are good to go

Craig

---

<div class="post-metadata">

**Author:** ![JHScen](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@JHScen](https://discourse.nodered.org/u/JHScen)\
**Post date:** [3 March 2022 11:56 UTC](https://discourse.nodered.org/t/controlling-smart-socket-based-on-data-change/59244/5 "2022-03-03T11:56:34Z")

</div>

Thanks Craig - Shall have a look into this! Appreciate the suggestion!
