Node Red Extract Data From Payload

I am very new to this, I have a Owl Electric monitor that send UDP data out, the integration that used to read this no longer works, so I need to setup my own in node red. I have a UDP listen working and into Debug I see the UDP data. How do I pull out certain values from this to put into a sensor. E.g. Battery Voltage, Phase 1 power, Phase 2 Power, etc.

<electricity id='44371914BDB1' ver='2.0'><timestamp>1710102893</timestamp><signal rssi='-73' lqi='89'/><battery level='100%'/><channels><chan id='0'><curr units='w'>243.00</curr><day units='wh'>6866.33</day></chan><chan id='1'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='2'><curr units='w'>788.00</curr><day units='wh'>12200.66</day></chan><chan id='3'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='4'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='5'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan></channels><property><current><watts>243.00</watts><cost>5.29</cost></current><day><wh>6866.33</wh><cost>188.56</cost></day><tariff time='1710102893'><start>1710028800</start><curr_price>0.22</curr_price><block_limit>4294967295</block_limit><block_usage>5282</block_usage></tariff></property></electricity>

Use an XML node to convert it to a JSON object. Then you can reference the values in a sensor node.

Thank you, im very new to this, so how do i configure the node?

image

[{"id":"4616d54dab210904","type":"xml","z":"120358abd7c22d30","name":"","property":"payload","attr":"","chr":"","x":1006,"y":2704,"wires":[["a4f896ae8ea0e659"]]},{"id":"aeaeda44d759cc66","type":"inject","z":"120358abd7c22d30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<electricity id='44371914BDB1' ver='2.0'><timestamp>1710102893</timestamp><signal rssi='-73' lqi='89'/><battery level='100%'/><channels><chan id='0'><curr units='w'>243.00</curr><day units='wh'>6866.33</day></chan><chan id='1'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='2'><curr units='w'>788.00</curr><day units='wh'>12200.66</day></chan><chan id='3'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='4'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan><chan id='5'><curr units='w'>0.00</curr><day units='wh'>0.00</day></chan></channels><property><current><watts>243.00</watts><cost>5.29</cost></current><day><wh>6866.33</wh><cost>188.56</cost></day><tariff time='1710102893'><start>1710028800</start><curr_price>0.22</curr_price><block_limit>4294967295</block_limit><block_usage>5282</block_usage></tariff></property></electricity>","payloadType":"str","x":850,"y":2704,"wires":[["4616d54dab210904"]]},{"id":"a4f896ae8ea0e659","type":"debug","z":"120358abd7c22d30","name":"debug 168","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1174,"y":2704,"wires":[]}]

An easy to get the path of the property is to use the debug panel and click “copy path” button when you hover over the property.

image

Thank you, awesome so now I see the path to the object I want, how do I set this into a sensor to be visible in HA

So sorry is this is dumb :slight_smile:

Do you want individual sensors for each property or one sensor with attributes?

I need to make several induvial sensors please

image

and set the state to correct property

image

You are amazing, it is working

One last question, is there an easy way to then divide one of the sensor values by 1000? So I am getting 8284W and want to divide by 1000 to 8.28Kw :slight_smile:

Set the state type to J: expression, JSONata, and use something like

$round(payload.electricity.battery[0].$.level / 1000, 2)

I changed this line
payload.electricity.channels[0].chan[0].day[0]._

Thank you, so I set like this.
$round(payload.electricity.channels[0].chan[0].day[0]._ / 1000, 2)

But get this error.

The input message doesn’t have have a msg.payload.electricity.channels[0].chan[0].day[0]._ field

When a number is in quotes "6866.33" it is being sent as a string. Use $number() to convert it.

Make sure the spacing stays the same as what I posted.

$round($number(payload.electricity.channels[0].chan[0].day[0]._) / 1000, 2)

You are AMAZING

Thank you so much, that is working perfect

Life saver.