How to properly parse returned JSON array

Tags: #<Tag:0x00007f617bd88748> #<Tag:0x00007f617bd88590>

Hi,

I have problem with JSONpath transformation. I build 3-phase energy meter based on Tasmota and PZEM004T.

The telemetry from MQTT looks like:

tele/sonoff35/SENSOR {"Time":"2020-05-24T18:28:31","ENERGY":{"TotalStartTime":"2020-05-24T18:28:28","Total":49.044,"Yesterday":1.943,"Today":9.842,"Period":1,"Power":[70,55,165],"ApparentPower":[146,354,196],"ReactivePower":[128,350,106],"Factor":[0.48,0.15,0.84],"Frequency":[50,50,50],"Voltage":[239,239,238],"Current":[0.611,1.485,0.824]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.5},"TempUnit":"C"}

I use MQTT v1 binding and my definition of items look like:

Number Sonoff_3phase_Meter_Voltage_L1 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage[0])],
                        <[broker:stat/sonoff35/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage[0])]" }

And I am unable to parse Voltage and others from L1. I get error:

2020-05-24 18:29:12.272 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'Sonoff_3phase_Meter_Voltage_L1'

The same applies to other tripled objects. I do not have problem to get Total energy an so on…

Can anybody tell me howto to transform this JSON?

Are you using a rule to do this? You haven’t shown one here…

You should also get off of the v1 binding, as it’s not long for this earth.

No, I’m not using rules… It is made in items file:

<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage[0])]

When I use JSONPATH for total:

<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Total])

it’s working.

I know I should migrate to v2…

Experimenting in rules can be useful when trying to get a transformation working.


val rawjson = '{"Time":"2020-05-24T18:28:31","ENERGY":{"TotalStartTime":"2020-05-24T18:28:28","Total":49.044,"Yesterday":1.943,"Today":9.842,"Period":1,"Power":[70,55,165],"ApparentPower":[146,354,196],"ReactivePower":[128,350,106],"Factor":[0.48,0.15,0.84],"Frequency":[50,50,50],"Voltage":[239,239,238],"Current":[0.611,1.485,0.824]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.5},"TempUnit":"C"}'

var results = transform("JSONPATH", "$.ENERGY.Total", rawjson)
logInfo("test", "simple " + results)

results = transform("JSONPATH", "$.ENERGY.Voltage", rawjson)
logInfo("test", "array " + results)

results =  transform("JSONPATH", "$.ENERGY.Voltage.[0]", rawjson)
logInfo("test", "element " + results)

output

2020-05-26 13:36:27.102 [INFO ] [.eclipse.smarthome.model.script.test] - simple 49.044
2020-05-26 13:36:27.106 [INFO ] [.eclipse.smarthome.model.script.test] - array [239, 239, 238]
2020-05-26 13:36:27.111 [INFO ] [.eclipse.smarthome.model.script.test] - element 239

According to https://jsonpath.com/ all three formulas are correct:
$.ENERGY.Voltage.[0]
$.ENERGY.Voltage.0
$.ENERGY.Voltage[0]

When I use: $.ENERGY.Voltage.[0] I got error like this (the same is with $.ENERGY.Voltage.0):

2020-05-26 16:32:52.699 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
2020-05-26 16:32:52.699 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
2020-05-26 16:32:52.700 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
2020-05-26 16:32:52.700 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

Now my items looks like:

Number Sonoff_3phase_Meter_Voltage_L1 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage.[0])],
                        <[broker:stat/sonoff35/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage.[0])]" }

Don’t care. You’re using the openHAB JSONPATH Transformation service, not JSONPATH. It has limitations, like only ever returning a single string.

Which of your two different topics is failing now, do you know? What’s the payload of that? We’ve only seen the one example.

You’ll probably save yourself hours by temporarily creating a String Item to hold the whole payload, then play with it in a rule.

1 Like

Ok.

I think that I find the problem…

I move my test items to another file (rest are commented):

Number test1 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage.[0])]" }
Number test2 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage.0)]" }
Number test3 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage[0])]" }

Errors:


2020-05-26 18:47:25.958 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonoff2.items'

==> /opt/openhab/userdata/logs/events.log <==
2020-05-26 18:47:25.966 [vent.ItemStateChangedEvent] - test1 changed from NULL to 237.0

==> /opt/openhab/userdata/logs/openhab.log <==
2020-05-26 18:47:26.991 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff2.items'
2020-05-26 18:47:32.758 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: Invalid path '$.ENERGY.Voltage.0' in '{"Time":"2020-05-26T18:47:32","ENERGY":{"TotalStartTime":"2020-05-26T18:47:21","Total":69.225,"Yesterday":10.070,"Today":8.053,"Period":0,"Power":[65,76,165],"ApparentPower":[141,267,200],"ReactivePower":[125,256,113],"Factor":[0.46,0.28,0.82],"Frequency":[50,50,50],"Voltage":[237,237,237],"Current":[0.595,1.129,0.845]},"DS18B20":{"Id":"0015232FE7EE","Temperature":25.9},"TempUnit":"C"}'
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

==> /opt/openhab/userdata/logs/events.log <==
2020-05-26 18:47:32.762 [vent.ItemStateChangedEvent] - test3 changed from NULL to 237

And from karaf console it looks like the syntax of:

  • $.ENERGY.Voltage.[0]

and

  • $.ENERGY.Voltage[0]

are correct:

openhab> smarthome:items list test*
test3 (Type=NumberItem, State=237, Label=Napięcie L1:, Category=voltage, Groups=[gSonoffVoltage, gSonoffMeasurement])
test1 (Type=NumberItem, State=237, Label=Napięcie L1:, Category=voltage, Groups=[gSonoffVoltage, gSonoffMeasurement])
test2 (Type=NumberItem, State=NULL, Label=Napięcie L1:, Category=voltage, Groups=[gSonoffVoltage, gSonoffMeasurement])

The problem is that I want to update value from two MQTT topic. When I change test1 definition to:

Number test1 "Napięcie L1: [%d V]" <voltage> (gSonoffVoltage, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage.[0])],
                        <[broker:stat/sonoff35/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage.[0])]" }

and remove other (test2 and test3) it’s stop working:

2020-05-26 18:58:59.818 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonoff2.items'

==> /opt/openhab/userdata/logs/events.log <==
2020-05-26 18:58:59.826 [vent.ItemStateChangedEvent] - test1 changed from NULL to 238.0

==> /opt/openhab/userdata/logs/openhab.log <==
2020-05-26 18:59:00.831 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff2.items'
2020-05-26 18:59:02.763 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]



2020-05-26 18:59:12.717 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

The MQTT looks like:

tele/sonoff35/STATE {"Time":"2020-05-26T19:01:22","Uptime":"2T21:47:00","UptimeSec":251220,"Heap":25,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":2,"Wifi":{"AP":1,"SSId":"atomix","BSSId":"BC:26:C7:E1:66:61","Channel":1,"RSSI":72,"Signal":-64,"LinkCount":2,"Downtime":"0T00:00:09"}}
tele/sonoff35/SENSOR {"Time":"2020-05-26T19:01:22","ENERGY":{"TotalStartTime":"2020-05-26T19:01:12","Total":69.296,"Yesterday":10.070,"Today":8.124,"Period":0,"Power":[80,101,170],"ApparentPower":[137,390,210],"ReactivePower":[112,377,124],"Factor":[0.58,0.26,0.81],"Frequency":[50,50,50],"Voltage":[238,238,238],"Current":[0.576,1.641,0.882]},"DS18B20":{"Id":"0015232FE7EE","Temperature":25.8},"TempUnit":"C"}


tele/sonoff35/STATE {"Time":"2020-05-26T19:01:32","Uptime":"2T21:47:10","UptimeSec":251230,"Heap":25,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":2,"Wifi":{"AP":1,"SSId":"atomix","BSSId":"BC:26:C7:E1:66:61","Channel":1,"RSSI":68,"Signal":-66,"LinkCount":2,"Downtime":"0T00:00:09"}}
tele/sonoff35/SENSOR {"Time":"2020-05-26T19:01:32","ENERGY":{"TotalStartTime":"2020-05-26T19:01:27","Total":69.297,"Yesterday":10.070,"Today":8.125,"Period":1,"Power":[83,100,170],"ApparentPower":[142,384,209],"ReactivePower":[115,370,122],"Factor":[0.58,0.26,0.81],"Frequency":[50,50,50],"Voltage":[238,238,238],"Current":[0.595,1.611,0.878]},"DS18B20":{"Id":"0015232FE7EE","Temperature":25.8},"TempUnit":"C"}

I just remove the second topic. But this syntax (with two topic) works for i.e. total energy:

Number Sonoff_3phase_Meter_Total_Energy "Całkowite zużycie energii: [%.3f kWh]" <power> (gSonoffTotalEnergy, gSonoffMeasurement)
                { mqtt="<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Total)],
                        <[broker:stat/sonoff35/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Total)]" }

There is no error on Sonoff_3phase_Meter_Total_Energy .

I think its solved my problem. But I don’t know why it doesn’t work.

Like I said: when I remove the second topic it’s start to work:

==> /opt/openhab/userdata/logs/events.log <==
2020-05-26 19:07:32.723 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Voltage_L1 changed from NULL to 237
2020-05-26 19:07:32.724 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Power_L1 changed from NULL to 79
2020-05-26 19:07:32.724 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ReactivePower_L1 changed from NULL to 110
2020-05-26 19:07:32.724 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ApparentPower_L1 changed from NULL to 136
2020-05-26 19:07:32.725 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Factor_L1 changed from NULL to 0.58
2020-05-26 19:07:32.727 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Current_L1 changed from NULL to 0.572
2020-05-26 19:07:32.727 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Voltage_L2 changed from NULL to 238
2020-05-26 19:07:32.728 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Power_L2 changed from NULL to 32
2020-05-26 19:07:32.728 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ReactivePower_L2 changed from NULL to 279
2020-05-26 19:07:32.728 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ApparentPower_L2 changed from NULL to 281
2020-05-26 19:07:32.729 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Factor_L2 changed from NULL to 0.12
2020-05-26 19:07:32.729 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Current_L2 changed from NULL to 1.182
2020-05-26 19:07:32.729 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Voltage_L3 changed from NULL to 238
2020-05-26 19:07:32.730 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Power_L3 changed from NULL to 166
2020-05-26 19:07:32.730 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ReactivePower_L3 changed from NULL to 108
2020-05-26 19:07:32.730 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_ApparentPower_L3 changed from NULL to 198
2020-05-26 19:07:32.730 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Factor_L3 changed from NULL to 0.84
2020-05-26 19:07:32.731 [vent.ItemStateChangedEvent] - Sonoff_3phase_Meter_Current_L3 changed from NULL to 0.831

This topic -

is not the same topic as this -

Confident it has the same payload?

No, payloads are different. But MQTT topics are also different:

Payload for:

<[broker:tele/sonoff35/SENSOR:state:JSONPATH($.ENERGY.Voltage.[0])]

is

tele/sonoff35/SENSOR {"Time":"2020-05-26T21:00:32","ENERGY":{"TotalStartTime":"2020-05-26T21:00:21","Total":69.986,"Yesterday":10.070,"Today":8.814,"Period":0,"Power":[142,89,241],"ApparentPower":[223,322,309],"ReactivePower":[172,309,193],"Factor":[0.64,0.28,0.78],"Frequency":[50,50,50],"Voltage":[237,237,237],"Current":[0.940,1.356,1.302]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.1},"TempUnit":"C"}

Payload for

<[broker:stat/sonoff35/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage.[0])]

is

stat/sonoff35/STATUS8 {"StatusSNS":{"Time":"2020-05-26T21:00:37","ENERGY":{"TotalStartTime":"2020-05-26T21:00:21","Total":69.986,"Yesterday":10.070,"Today":8.814,"Power":[142,86,241],"ApparentPower":[223,318,310],"ReactivePower":[172,306,195],"Factor":[0.64,0.27,0.78],"Frequency":[50,50,50],"Voltage":[237,237,237],"Current":[0.940,1.338,1.311]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.1},"TempUnit":"C"}}

Okay, here’s rhe rules experiment with the information supplied

val sensor = '{"Time":"2020-05-26T21:00:32","ENERGY":{"TotalStartTime":"2020-05-26T21:00:21","Total":69.986,"Yesterday":10.070,"Today":8.814,"Period":0,"Power":[142,89,241],"ApparentPower":[223,322,309],"ReactivePower":[172,309,193],"Factor":[0.64,0.28,0.78],"Frequency":[50,50,50],"Voltage":[237,237,237],"Current":[0.940,1.356,1.302]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.1},"TempUnit":"C"}'
var results = transform("JSONPATH", "$.ENERGY.Voltage.[0]", sensor)
logInfo("test", "sensor " + results)

val status8 = '{"StatusSNS":{"Time":"2020-05-26T21:00:37","ENERGY":{"TotalStartTime":"2020-05-26T21:00:21","Total":69.986,"Yesterday":10.070,"Today":8.814,"Power":[142,86,241],"ApparentPower":[223,318,310],"ReactivePower":[172,306,195],"Factor":[0.64,0.27,0.78],"Frequency":[50,50,50],"Voltage":[237,237,237],"Current":[0.940,1.338,1.311]},"DS18B20":{"Id":"0015232FE7EE","Temperature":24.1},"TempUnit":"C"}}'
results = transform("JSONPATH", "$.StatusSNS.ENERGY.Voltage.[0]", status8)
logInfo("test", "status8 " + results)

producing

2020-05-26 20:56:12.506 [INFO ] [.eclipse.smarthome.model.script.test] - sensor 237
2020-05-26 20:56:12.508 [INFO ] [.eclipse.smarthome.model.script.test] - status8 237

What I was trying to clumsily highlight earlier was that in places you refer to three different topics tele/sonoff35/STATE, tele/sonoff35/SENSOR and sometimes stat/sonoff35/STATUS8.
Be sure you’re looking at the right one.