Function with payload + X

Hello
I'm new here and need a little help :frowning:

At node red, I do air conditioning automation.

I would like the air conditioning to turn on when the room temperature is higher by, for example, 2 than the currently set value.

currently I have a reading of temp = payload

If temp is>= Payload, it will turn on the climate.

I wish it was on an enable if >= payload "+2" degrees (or more/less).

How could I get it?

I have tried hystersis but it's not a good nod (or i cant set it)
i try too function (but probably is a wrong)

var payload = msg.payload; //get payload
payload = msg.payload + 2.0;
msg.payload = payload;
return msg;

I am counting on your help !

Likely the latter. Search the forum for hysteresis - @colin has posted many threads and helped tonnes of users with this topic.

i think the function is better for me. hystersis is more advanced. i need a really simple script.

I understand but for temperature control, hysteresis is definitely the way to go.

In the mean time, something to get you moving...

chrome_V1NCTVW9x0

[{"id":"4b0b1c007ea0da93","type":"inject","z":"6f3a24bd7ed7326b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"room/temperature","payload":"16","payloadType":"num","x":880,"y":1380,"wires":[["e120e68bf3917c41"]]},{"id":"41d0eef7162a2e69","type":"inject","z":"6f3a24bd7ed7326b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"room/temperature","payload":"19","payloadType":"num","x":880,"y":1420,"wires":[["e120e68bf3917c41"]]},{"id":"69527427be2a656b","type":"inject","z":"6f3a24bd7ed7326b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"room/temperature","payload":"23","payloadType":"num","x":880,"y":1460,"wires":[["e120e68bf3917c41"]]},{"id":"4f890478a14bba74","type":"inject","z":"6f3a24bd7ed7326b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"room/temperature","payload":"25","payloadType":"num","x":880,"y":1500,"wires":[["e120e68bf3917c41"]]},{"id":"710241db0e60e4e1","type":"inject","z":"6f3a24bd7ed7326b","name":"aircon settings (on at 26, off at 18)","props":[],"repeat":"","crontab":"","once":true,"onceDelay":"0.3","topic":"","x":920,"y":1280,"wires":[["7bc39a04d3a7292e"]]},{"id":"7bc39a04d3a7292e","type":"change","z":"6f3a24bd7ed7326b","name":"","rules":[{"t":"set","p":"high","pt":"flow","to":"26","tot":"num"},{"t":"set","p":"low","pt":"flow","to":"18","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":1280,"wires":[["08b36c60364ede98"]]},{"id":"a149dc02851d7925","type":"comment","z":"6f3a24bd7ed7326b","name":"set high and low values","info":"","x":860,"y":1240,"wires":[]},{"id":"e120e68bf3917c41","type":"change","z":"6f3a24bd7ed7326b","name":"store room_temp","rules":[{"t":"set","p":"room_temp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":1440,"wires":[["d22c9643ed96bb2e"]]},{"id":"d22c9643ed96bb2e","type":"link out","z":"6f3a24bd7ed7326b","name":"link out 17","mode":"link","links":["50c3c3e310290586"],"x":1315,"y":1440,"wires":[]},{"id":"08b36c60364ede98","type":"link out","z":"6f3a24bd7ed7326b","name":"link out 18","mode":"link","links":["50c3c3e310290586"],"x":1315,"y":1280,"wires":[]},{"id":"50c3c3e310290586","type":"link in","z":"6f3a24bd7ed7326b","name":"link in 10","links":["d22c9643ed96bb2e","08b36c60364ede98"],"x":785,"y":1640,"wires":[["45469485f49c576c"]]},{"id":"45469485f49c576c","type":"switch","z":"6f3a24bd7ed7326b","name":"high? low?","property":"room_temp","propertyType":"flow","rules":[{"t":"gt","v":"high","vt":"flow"},{"t":"lt","v":"low","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":930,"y":1640,"wires":[["3bb7ffaa7a26a528"],["00ec317796212dd6"],[]]},{"id":"3bb7ffaa7a26a528","type":"change","z":"6f3a24bd7ed7326b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"AIRCON ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":1620,"wires":[["c42a5b7bcb4cf41d"]]},{"id":"c42a5b7bcb4cf41d","type":"debug","z":"6f3a24bd7ed7326b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1330,"y":1660,"wires":[]},{"id":"00ec317796212dd6","type":"change","z":"6f3a24bd7ed7326b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"AIRCON OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":1660,"wires":[["c42a5b7bcb4cf41d"]]},{"id":"6fd5ec19cb2f07f2","type":"comment","z":"6f3a24bd7ed7326b","name":"Simulate temparature changes","info":"","x":890,"y":1340,"wires":[]},{"id":"c4b2e7242e1e308a","type":"comment","z":"6f3a24bd7ed7326b","name":"Control AIRCON","info":"","x":840,"y":1600,"wires":[]},{"id":"d156998b76450d1a","type":"inject","z":"6f3a24bd7ed7326b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"room/temperature","payload":"27","payloadType":"num","x":880,"y":1540,"wires":[["e120e68bf3917c41"]]}]

@Steve-Mcl, what is the tool you're using to make the tiny screen captures?

I use sharex (for windows only)

There are plenty of them around & has been covered on forum a few times. Search "animated gif" or "sharex" on the forum for other ideas :slight_smile:

1 Like

i think about it. but in hystersis aircontidioner will start about 26 (or other what i set).
if i make by my idea, with payload + x then i change temp in HA nodered will get value from payload and airconditioner will start by value in payload.

that demo above was NOT using hysteresis

Using pure node-red nodes (low-code, no functions, no hysteresis, something simple to get you started on a basic control). Simply set the high and low values you want and it will work as you describe

for me, the value of high and low varies depending on the choice of temperature from the drop-down list...

but i try with it. maybe i will do it ;-).

if anybody have idea with function payload +X send it please.

Yes, I understand that - so link these values to the flow.high and flow.low - I only used an inject because I dont have your values, I dont have your system, I dont have access to your HS server. - I simulated it.

image

thanks, i try with it for moment <3
first i go to eat breakfast :smiley:

This makes zero sense.

You have 3 values to consider.

  • Current Temperature
  • High point
  • Low point

You need all 3 values to be able to determine what to do.

So, use flow.xxxx to store them.

Then use change nodes to compare them

Then you can control the AIRCON

Pretty much as I wrote for you!

If you REALY REALY want to compare to xxx + 2 - then simply add 2 to the flow.high

hmm its really look good and work! :smiley: thanks.

Just to clarify the terminology here, hysteresis, in this context, is exactly what is being talked about, namely turning on the cooling a bit above a setpoint and turning it off again when it has reached a defined lower temperature. Whether it is done in a function node or in a node with hysteresis in the name is irrelevant, it is still hystersis.

var payload = msg.payload; //get payload
payload = msg.payload + 2.0;
msg.payload = payload;
return msg;

@Peres that should do exactly what you have asked for, adding 2 to msg,payload, though it can be simplified to

msg.payload = msg.payload + 2
return msg

or even further to

msg.payload += 2
return msg

Did it not work for you? If not then add debug nodes showing what is going into and out of the function node and show us the results.

this flow what Steve send me is really ok (thanks!!). But maybe i try to use +2 in another flow (if i will need). thanks a lot <3

ok i do it to my airconditioner.
have next problem....

if i set temp (on my selectable list) like ' set temp to 23' and i want to airconditioner is off less like 23 (22.99 or less) but start again if temp is about 24-25 (still is payload +2). and i cant to do it with this flow from Steve... if i make paylad + 2 then i have temp 23.02 (not 23+2 =25) just 23.02 :frowning:

Export your current flow so we can see what you have done.

[{"id":"72fdce8e1fab005b","type":"api-current-state","z":"17369459177ad140","name":"1","server":"497764a0.a9625c","version":3,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.ustawiona_temp_klima_sypialnia","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1130,"y":1780,"wires":[["e5ae592d3a93ce23"]]},{"id":"e5ae592d3a93ce23","type":"function","z":"17369459177ad140","name":"","func":"msg.payload += 2\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1280,"y":1780,"wires":[["dd18a6913a195641"]]},{"id":"dd18a6913a195641","type":"debug","z":"17369459177ad140","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1470,"y":1780,"wires":[]},{"id":"16b14a5c44198005","type":"inject","z":"17369459177ad140","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":940,"y":1780,"wires":[["72fdce8e1fab005b"]]},{"id":"497764a0.a9625c","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]