What type of node do I need?

I'm fairly new to NR
I have an MQTT input in the form:
object
endpoint: object
serial_number: "a4c138101b95ec05"
payload: object
temperature: object
temperature: 18.209999
I've created a number 'helper' in Home Assistant. I think it's just a float.
If I try to sent that payload to my helper I get an error:

Call-service error. required key not provided @ data['value']

I'm guessing I just need to parse the object and extract the value and then change it to say data: value

What nodes would you guys use to extract that number?

Edited to add: The formatting I put in disappeared on post.

I don't use HA, but I think its a change node you are looking for ?

Yes, unfortunately that makes it impossible to give you a straight answer. To post code or data in the forum you have to use the </> button. It wraps the code between two lines each containing 3 back ticks.

The debug node has a "Copy path" button at the right of your data. Use a change node to move this path (msg.payload.temperature.temperature, or whatever) to msg.payload.

What is a "Number helper?"
Home assistant does seem weird :confused: the phrase "call-service" gives no hint what it does

Thanks, I will experiment with a change node later. I don’t think I even looked at that node.

Yes the documentation for helpers is quite poor. I use “toggle” helpers and they are just booleans that can easily be displayed in the dashboard. This is my first experiment with numbers. I’m not even sure it’s a float and not an integer. There are more types of “helper” than basic data types so their must be some overlap. I think they maybe display differently but I haven’t experimented.

Any idea what this means:
Call-service error. required key not provided @ data['value']

With a change node I now have the number in msg.payload. Thanks to your tip I found it was at "payload.payload.temperature.temperature". Never would have guessed there were 2 payloads but still get an error. Have tried moving it to msg.payload.data
Maybe it is a string that looks like a float and I need to change it?

Are you sure that doesn't look right ?

No, I know nothing about Home Assistant.

If it is a string the debug output will show the value in quotes eg "27.908"

You built the message somehow, somewhere in your code. Maybe read up about json/javascript objects and take control of your software :stuck_out_tongue:

Assuming your MQTT input is in a JSON format and the payload structure looks like:
{
"endpoint": {
"serial_number": "a4c138101b95ec05"
},
"payload": {
"temperature": 18.209999
}
}

You can use the following nodes in Node-RED:

  1. Use an MQTT input node to receive the MQTT messages.

  2. Add a JSON node to parse the incoming payload. Set the "Property" field to payload if the MQTT payload is stored in the payload property.

  3. Add a Change node to extract the temperature value. Set it up as follows:
    Set msg.payload to msg.payload.temperature.

  4. Use a Home Assistant Out node to send the extracted value to your number helper. Set the "Action" to "Call Service," select your Home Assistant service, and configure the "Service Data" to send the value to your number helper.

Thanks, I actually have it figure out, but the post of the solution and my reply thanking them has disappeared so it looks like I am still stuck.
Turned out I had to format it with a “‘value’:msg.payload” in the last node after shuffling the data around with a change node because the number was in msg.payload.payload.temperature.temperature. Essentially it couldn’t see the number where it was and needed it to be called value rather than temperature

No I don’t build the message. It’s an MQTT in node and there has been no coding at any point. And the key was just changing the numbers name to “value” rather than just sending a number in to that node. That was the only thing needed to make it work.

Glad you got it sorted out, well done.

I don't understand your explanantion "it needed to be called value rather than temperature" but certainly msg.payload.payload.temperature.temperature is a bit unusual.

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