Switch bigger than and smaller then error

Hi

I'm trying to do a min and max wether temp and save it in context.
However, the < and > doesn't work for me. I have to change them to the oppesite every time I do a deploy, which seems odd.


[{"id":"b9f8c315fe199fcf","type":"inject","z":"f6979629ded1c46f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"15","payloadType":"str","x":670,"y":1660,"wires":[["719937969e2861ec"]]},{"id":"bacb940ede194665","type":"inject","z":"f6979629ded1c46f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":670,"y":1700,"wires":[["719937969e2861ec"]]},{"id":"e527cca3e2104614","type":"inject","z":"f6979629ded1c46f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"str","x":670,"y":1620,"wires":[["719937969e2861ec"]]},{"id":"719937969e2861ec","type":"switch","z":"f6979629ded1c46f","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"maxUdetemp","vt":"global"},{"t":"lt","v":"minUdetemp","vt":"global"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":1660,"wires":[["4c359675b0a54f8b"],["9532226a94731b21"]]},{"id":"4c359675b0a54f8b","type":"change","z":"f6979629ded1c46f","name":"set maxUdetemp","rules":[{"t":"set","p":"maxUdetemp","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":1640,"wires":[["7f57aa94169ca9a0"]]},{"id":"9532226a94731b21","type":"change","z":"f6979629ded1c46f","name":"set minUdetemp","rules":[{"t":"set","p":"minUdetemp","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":1680,"wires":[["1bfee80d9961ec20"]]}]

Is this a known issue?

Not sure what you are trying to do.
In your flow maxUdtemp and minUdtemp have no initial value, so the switch will never work
For testing purposes I've re-wired your flow.

Screen Shot 05-06-22 at 10.22 PM

1 Like

It does, but it's not shown here.

Every night at 00.00 it resets it with values beyond what's reasonable.
So like -100 for max and +100 for min, so when the first value comes from the temperature sensor outside, it rewrites it.

Is the payload arriving at your switch a number or a string?
Do your change nodes set global.maxUdetemp to a number or a string?

OK - I understand a bit better now.
I think you are trying to create what's called a min/max thermometer that records the min and max values over a period of time. And as you said, resets at midnight.
There are various ways to implement this along the lines you mentioned.
e.g. Setting min and max to extreme values in the opposite direction. (-100 for max. +100 for min).
I should have some spare time later today to build a flow for you.

Here's a flow, using function nodes, for you to try out.
Screen Shot 05-07-22 at 07.05 AM

[{"id":"9a435485d72b6c41","type":"inject","z":"b26cfb785d3f2be6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":180,"y":80,"wires":[["b3eb1cba48b58c4e"]]},{"id":"0045fd0523446256","type":"function","z":"b26cfb785d3f2be6","name":"","func":"let min = global.get(\"minUdetemp\");\nlet max = global.get(\"maxUdetemp\");\n\nif (msg.payload < min) {\n    global.set(\"minUdetemp\", msg.payload);\n}\nif (msg.payload > max) {\n    global.set(\"maxUdetemp\", msg.payload);\n}\n\n// This is for testing\nnode.status({text:\"Max is = \"+ global.get(\"maxUdetemp\") + \" Min is = \" + global.get(\"minUdetemp\")});\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":360,"wires":[[]]},{"id":"718bfdd1cc38e442","type":"inject","z":"b26cfb785d3f2be6","name":"Reset initial conditions","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":210,"y":160,"wires":[["b3eb1cba48b58c4e"]]},{"id":"e71a4e156df77549","type":"inject","z":"b26cfb785d3f2be6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"15","payloadType":"num","x":180,"y":360,"wires":[["0045fd0523446256"]]},{"id":"f8e97dc92c19522b","type":"inject","z":"b26cfb785d3f2be6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":180,"y":400,"wires":[["0045fd0523446256"]]},{"id":"9b3334c897540ff2","type":"inject","z":"b26cfb785d3f2be6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":180,"y":320,"wires":[["0045fd0523446256"]]},{"id":"b3eb1cba48b58c4e","type":"function","z":"b26cfb785d3f2be6","name":"","func":"global.set(\"minUdetemp\", 100);\nglobal.set(\"maxUdetemp\", -100);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":80,"wires":[[]]},{"id":"c3ac15df42a9b8dd","type":"comment","z":"b26cfb785d3f2be6","name":"Set this inject node to 'Repeat at a specific time'","info":"","x":260,"y":200,"wires":[]}]
1 Like

It arrives as a string, could that be the culprit?
If so, how do I change a number written in a string to a number?

EDIT: I found a way

Thanks, I'll give it a try.
I'm more a logic guy, so a look in to how it can be done I a function node is always learning. :+1:t3:

Video of the error.
If it's due to it being a string, I feel stupid.

If it does turn out that's the problem, no need to feel stupid. We have all done it!

Handling value types (Int, string, Array) is probably the biggest cause of frustration once a user progresses from basic drag and drop logic building. It can be a nightmare and usually does require digging into that most scary of nodes, the function node...And once there, it's not always easy to get the syntax right, especially for a new non-coding user...

Perhaps there is scope for an intelligent built-in node that analyses the data passing through and gives the user the option to transform the data into the format needed for the next step in the flow...?

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