How to use Node Red number inside another node

I have node red controlling my HVAC schedule, and I want to be able to change the preset temperatures from a dashboard.

I have this number node set up:

For the life of me, I can’t figure out the syntax to use that number when setting the temp here:

$number() is a function that casts a string to a number. To recall a value of an entity you would use the entities variable $entities() So if the entity winter_day_temp is a number entity you would use

$entities('number.winter_day_temp').state
1 Like

Thank you so much!

Now it’s saying it needs it as a float. Would it be better to cast the number to a float in that node? Or reconfigure the number itself as a float?

If the number is just for that, I’d change the number rather than converting it.

1 Like

I realized that I can put any garbage in for the entity name and I still get expects float error. I’m not sure if it’s getting a value at all.

I see that $entities is not an option it shows me:

Is there somewhere I can read the syntax for that?

The functions you see there are NR native functions. Home assistant nodes have additional functions available that do not show in that list. The following functions are only available in HA nodes.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata/#home-assistant-functions

Was this number created in HA? If so it would be input_number. If it was created in NR, do you have the NR companion in hacs installed? Does the entity show in devtools → states?

You appear to be putting your JSONata code inside of quotes. This will return a string rather than actually executing the JSONata function to return the entity state value. Since HA is expecting a number value, not a string, it will complain.

Mikefila has already provide the code, but to reiterate

In the Action node
in the Data field
where you have J: option selected (this is for JSONata)
you need:

{ "temperature": $entities('number.winter_day_temp').state }

When entering JSONata code in Node-RED (see the J: expression options) you will have the JSONata editor to use. This has some JSONata standard functions available and a test-bed, but does not have access to the HA state auto-complete, so you have to work out the ‘number.winter_day_temp’ yourself. What you are seeing is the default Node-RED Monaco editor working in default JavaScript mode, so un-helpfully providing a list of JS functions available (which they are not since this is JSONata and not JavaScript). Yes, you would think that someone deliberately set out to make all of this as unhelpful as they possibly could :laughing:

A seasonal message from the JSONata Appreciation Society:

Good will and peace to all, don’t overdo the festivities, and remember :-

JSONata is not Mustache templates, and it works in a different way.

1 Like