Comparing Strings to numbers in Wait node?

I wonder if someone can help me here - I have a temperature value which for some reason, is a string. In some nodes I can force it to act as a number (and I have done so in the flow below to be able to add 2 to it)
Essentially I want my towel rail to go off when the temperature is increased by two

The problem seems to be that the wait node never triggers, presumably because my now number is not equal to the string it's being compared to.

I'm not clear on how I can either revert the stored flow variable to be a string, or use the string as a number in the wait node... can anyone advise?
Maybe there is a better way to do this than the wait node that I'm missing!?

Any help appreciated :slight_smile:

[{"id":"795593744ea3239b","type":"trigger-state","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"Bathroom Towel Rail Turns On","server":"3aa13fed.bf745","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["switch.shelly1_f4cfa276b8a6"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":1040,"y":660,"wires":[["d40a4d86259c5273"],["b648b7279de430d9"]]},{"id":"d40a4d86259c5273","type":"api-current-state","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"UFH Thermostat Temp","server":"3aa13fed.bf745","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ufh_true_temperature","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1320,"y":640,"wires":[["543c5e039b066342"]]},{"id":"543c5e039b066342","type":"change","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"flow.thermostat-temp","rules":[{"t":"set","p":"themostat-temp","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"target-thermostat","pt":"flow","to":"$sum([msg.payload,2])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1560,"y":640,"wires":[["9c694a0dc0f7605f","9f4faefa777dafc5"]]},{"id":"b648b7279de430d9","type":"change","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"},{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":720,"wires":[["9f4faefa777dafc5"]]},{"id":"9f4faefa777dafc5","type":"ha-wait-until","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"UFH Thermo hits 2deg more","server":"3aa13fed.bf745","version":3,"outputs":1,"entities":{"entity":["sensor.ufh_true_temperature"],"substring":[],"regex":[]},"property":"state","comparator":"is","value":"target-thermostat","valueType":"flow","timeout":"0","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"x":1520,"y":700,"wires":[["836ce44f4b9584f2"]]},{"id":"836ce44f4b9584f2","type":"api-call-service","z":"9dddcfaf9cc3bc8a","g":"cfcae76508526628","name":"Turn off Bathroom Towel Rail","server":"3aa13fed.bf745","version":7,"debugenabled":false,"action":"switch.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.shelly1_f4cfa276b8a6"],"labelId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_off","x":1800,"y":700,"wires":[[]]},{"id":"9c694a0dc0f7605f","type":"change","z":"9dddcfaf9cc3bc8a","name":"Target","rules":[{"t":"set","p":"payload","pt":"msg","to":"target-thermostat","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1690,"y":580,"wires":[["b531620e410bb22c"]]},{"id":"b531620e410bb22c","type":"debug","z":"9dddcfaf9cc3bc8a","name":"debug 105","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1830,"y":580,"wires":[]},{"id":"d5fd4a8b5c9dfe6f","type":"inject","z":"9dddcfaf9cc3bc8a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1320,"y":500,"wires":[["1418a9f00a77793e"]]},{"id":"1418a9f00a77793e","type":"api-current-state","z":"9dddcfaf9cc3bc8a","name":"","server":"3aa13fed.bf745","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ufh_true_temperature","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","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1590,"y":500,"wires":[[]]},{"id":"3aa13fed.bf745","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"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","enableGlobalContextStore":true}]

Before you save it to the flow context, insert a Function node containing

msg.payload = Number(msg.payload)
return msg

Which will convert it to a number.

It's not clear from your post why you want to revert from a number to a string. Is it a Home Assistant thing that numbers are usually held as strings?

I would think the best approach is to make it a number at the earliest opportunity and keep it that way.

If the node "UFH Thermo hits 2deg more" requires a string, use a filter node instead.

I think that @vaderag misstyped. I think he/she wants it be a number always.

Looks like I need to be a bit clearer... yeah, realistically NodeRed always seeing it as a number would be best for my usage
The only reason I was considering getting it back to a string is for the compare to work

Currently this fails, and my assumption is because state is string and flow.target-thermostat is number

I'm not certain that there is any way for the wait node to use UFH True Temperature state as a number - I need it linked to that entity and not the payload so changing it to a number before isn't going to work

Other nodes have an option to treat it differently


which is what I have done to be able to calculate the value +2 in the flow variable

This is actually the opposite of what is needed, but similarly wont work because the payload needs to be a number for my calculation to work

I thought that would work with flow.target-thermostat as a String as well, but seems not as the function node doesn't like it :frowning:

I can't comment on how to use the HA nodes as I don't use HA (few here do).

However, I have already shown how to convert it to a Number in a function node (that will also work if it is already a number). Any time you want to convert it to a string (if not already one) then you can use

// convert payload to string if not already one
if (typeof msg.payload != "string") {
  msg.payload = msg.payload.toString()
}
return msg

[Edit] Personally I would make it always a number and use a core node-red node for doing the comparison. The Switch node for example.

Thanks. I agree - I'm not really sure why these numeric values come through as strings in the first place but given there doesn't seem to be a way to alter it at the point of compare I don't think I really have a choice but to use a string...
I've now got it implemented with conversion to number and then flipping it back to string - seems to work (will give it a genuine test shortly)

Instead of recalling the flow variable directly, you can use jsonata.

Also worth mentioning context storage is set to memory only by default. I suggest changing it to file to avoid losing values if you haven't already.