Switch node help

I’m attempting to use the payload from a temperature sensor as the property for a switch node. I also have a slider in Home Assistant that controls an input number in node red. I’m trying to take the payload form the input number and use it as the values for the switch node that the property is being checked against.

This is what I currently have

[{"id":"32bc9d642fe3ac62","type":"tab","label":"","disabled":false,"info":""},{"id":"65c768c9f86812da","type":"debug","z":"32bc9d642fe3ac62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":340,"wires":[]},{"id":"85ec2bf98594b7c0","type":"inject","z":"32bc9d642fe3ac62","name":"Inject Temp 33","props":[{"p":"payload.DS18B20.Temperature","v":"33","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":240,"y":380,"wires":[["18a840f7c09cf4f5","f72a0de7638ae0ac"]]},{"id":"6b68fe813853e5f4","type":"debug","z":"32bc9d642fe3ac62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":240,"wires":[]},{"id":"faab44569ca98d3d","type":"debug","z":"32bc9d642fe3ac62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":180,"wires":[]},{"id":"f259bb559d2c6102","type":"inject","z":"32bc9d642fe3ac62","name":"Inject Temp 25","props":[{"p":"payload.DS18B20.Temperature","v":"25","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":240,"y":200,"wires":[["faab44569ca98d3d","f72a0de7638ae0ac"]]},{"id":"18a840f7c09cf4f5","type":"debug","z":"32bc9d642fe3ac62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":380,"wires":[]},{"id":"98667477bce0f152","type":"server-state-changed","z":"32bc9d642fe3ac62","name":"","server":"8cd93e38.ec024","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.ds18b20_hi_fault","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload.input_number.ds18b20_hi_fault.set_point","propertyType":"msg","value":"","valueType":"entityState"}],"x":330,"y":280,"wires":[["c36c3ac896dcaa54","f72a0de7638ae0ac"]]},{"id":"c36c3ac896dcaa54","type":"debug","z":"32bc9d642fe3ac62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":360,"wires":[]},{"id":"f72a0de7638ae0ac","type":"switch","z":"32bc9d642fe3ac62","name":"","property":"payload.DS18B20.Temperature","propertyType":"msg","rules":[{"t":"lt","v":"payload.input_number.ds18b20_hi_fault.set_point","vt":"msg"},{"t":"gte","v":"payload.input_number.ds18b20_hi_fault.set_point","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":280,"wires":[["6b68fe813853e5f4"],["65c768c9f86812da"]]},{"id":"8cd93e38.ec024","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I am new to Node-Red and perhaps what I’m attempting to do isn’t possible.

You need to read the post on how to post code here.

There is a button at the top of the window when you are entering your post.
It is the </> button.
https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506/2

Node-red messages arrive at a node at different times so if you want to check the values of two different inputs (messages) then you need to 'join' them before comparing them.

You could use a join node

Or, if the slide is setting the temperature you wanted to get to, you could have three different flows.
FLOW 1: an inject connected to a change node. The inject is set to run when ever you deploy. the change node sets a flow variable (lets call it flow.setting) to an initial value.
FLOW 2: the slider sends a value to a change node which put it in flow variable (flow.setting).
FLOW 3: The sensor gets a reading and ends it to a switch node that checks the value against the flow variable (flow.setting). You could have three test 'greater than', 'equal' or 'less than'. You then send each output to more nodes that do what you want for that condition

There is a button at the top of the window when you are entering your post.
It is the </> button.

Found it and edited post, thanks.

Thanks, I will take a look at the join node and search for examples.

I currently have the set point hard coded in a different flow and it works. I was just trying to see if I could do it a different way for a project I'm considering in the future. I like the idea of having a set point that I can change from a ui.

Thanks zenofmud for point me in the right direction. I spent a day reading the documentation and playing around with the join node. It works perfectly for what I wanted to accomplish. I've actually improved some of my other flows using it.

2 Likes

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