Switch SmartPlug according to Humidity

Hey guys,
i´m really new in the Node-Red world and I need some help please.
I have constructed a Weather Station from an ESP8226, wich is successfully delivering the data in Node-Red.
I would like to switch my Smart Plug according to the Humidity in the room (there is a humidifier on the connected to it). For example if the humidity in the room is below 40% the Smart Plug should be ON. The Smart Plug accepts boolean True and False. I have tried it with switch and with an Injector and it works. Now I would like to figure it out how to turn it on and of according to the level of humidity.

Use the switch node to test the value then route the message to a change node to set the payload before sending it to the device.

1 Like

In addition to what @Steve-Mcl says, have a range. I.e. when humidity is less than 40 turn the plug on but don’t turn it off till it reaches 45 or 42. Have the off value away from the on value so yup don’t run into a state of it going off and on repeatably

1 Like

A conditional in the change node should get you true/false output based on humdity value. This uses a JSONata expression, you could do similar in a function node
e.g.

[{"id":"c202f2f3.ee146","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"35","payloadType":"num","x":160,"y":2400,"wires":[["e55b031e.79888"]]},{"id":"1c9ac260.e6e08e","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":160,"y":2460,"wires":[["e55b031e.79888"]]},{"id":"e55b031e.79888","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload < 40 ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":2420,"wires":[["1cd6b62b.b27a2a"]]},{"id":"1cd6b62b.b27a2a","type":"rbe","z":"8d22ae29.7df6d","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":500,"y":2420,"wires":[["c7a8c472.018348"]]},{"id":"c7a8c472.018348","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":2320,"wires":[]}]

I also added a rbe node, so to filter out repeated trues and falses.

1 Like

thanks a lot i used the Switch and change combination and it works perfectly.
Huge thanks you saved me a lot of time.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.