Node-red parse json

Hello everyone,

I trying to create a function with node-red, I reported below the JSON data that I can generate from a specific sensor, but, I’ve lot of difficulties to parse this message :frowning:

My goal is to read and store as an integer the 23.5 degree that coming from the sensor “sensor.termostato_salon_termostato_salon_temperature” [ take a look the part - THIS OBJECT / THIS SENSOR / THIS TEMPERATURE ]

someone could help me?

Thanks a lot

Luca

msg.payload : Object
object
entity_id: "sensor.termostato_salon_termostato_salon_temperature"
old_state: object
entity_id: "sensor.termostato_salon_termostato_salon_temperature"
state: "23.5"
attributes: object
context: object
last_changed: "2024-09-14T18:49:33.663Z"
last_updated: "2024-09-14T18:49:33.663Z"
timeSinceChangedMs: 5776116
new_state: object <----- THIS OBJECT
entity_id: "sensor.termostato_salon_termostato_salon_temperature" <-----THIS SENSOR
state: "23.5" <----- THIS TEMPERATURE
attributes: object
unit_of_measurement: "°C"
device_class: "temperature"
friendly_name: "Termostato_Salon Termostato_Salon Temperature"
context: object
id: "01J7RXWX6ZABXANJ67F1Y3Y9P1"
parent_id: null
user_id: null
last_changed: "2024-09-14T18:49:33.663Z"
last_updated: "2024-09-14T18:49:33.663Z"
timeSinceChangedMs: 5776116

This looks like the debug output from an event state or trigger node? New state/old state is usually in the data section.

image

The path would be data.new_state.state . You can also send just that value out of the triggering node using jsonata in the output section.

image

Using that msg.payload would = "23.5". Now because the number is wrapped in quotes, it is a string. To cast it to a number you would use the number function. $number() or $number($entity().new_state.state)