Only String channel possible with Jsonpath?

Good morning

Received my Shelly 3EM today and as the Shelly binding is unusable (dunno why it is listed in the bindings then ;o) I use the HTTP binding to get the JSON via the Shelly API.

So when calling I get as Json returned (parts cut off):

    "emeters": [
            "current": 0.01,
            "is_valid": true,
            "pf": -0.19,
            "power": 0.0,
            "total": 0.0,
            "total_returned": 0.1,
            "voltage": 223.19

So the values I’m interested in (voltage, current and power) are returned as numbers…

But why do I have to define the channel as String?
When set as Number always UNDEF is returned…

But when set as String channel no analyze button is available and therefore no graph is created.

thanks in advance

Then something is wrong with your config, which we cannot see.
Your openhab.log may have something to say on the matter.
Remember that JSONPATH is an optional add-on.

The thing code looks like:

UID: http:url:150601194e
label: Shelly 3EM HTTP
thingTypeUID: http:url
  authMode: BASIC
  ignoreSSLErrors: false
  delay: 0
  stateMethod: GET
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
  - id: shelly3em_voltage_1
    channelTypeUID: http:number
    label: Shelly 3EM Voltage 1
    description: ""
    configuration: {}

This results in:

2022-11-10 12:30:10.683 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state 'UNDEF' with function '$.emeters[0].voltage' and format '%s'

Configuring as:

  - id: shelly3em_voltage_a
    channelTypeUID: http:string
    label: Shelly 3EM Voltage A
    description: ""
    configuration: {}

is fine…but since it is then a String it is not graphed…

Well…just saw that the Shelly binding does support the 3EM, just not the Pro 4PM, which I’m gonna reflash with esphome anyway…

Your problem is that you are using a profile.

A profile operates on the link between channel and Item.
In other words, the profile takes the final output from the channel and modifies it.
If you use a JSONPATH profile, then you must pass it the whole JSON string to work with, which of course means using a string type channel.
Should the profile result after processing be numeric, you may link to a Number type Item - the profile has done the conversion from channel-string to Item-number.

If you use a number type channel to pass the whole JSON, it is non-numeric, simply doesn’t fit, and you get UNDEF passed out of the channel and onwards to the profile.
JSONPATH profile cannot process “UNDEF” of course, and complains.

What people do is not use a profile at all.
The HTTP channel has built-in configuration for transformations, including JSONPATH. Its in the docs.
This allows processing before the channel passes the value along.
If JSONPATH can extract a numeric, you would use a number type channel and the output will be a number.

You may even add a unit at the channel, if you know the numeric is say expressed in volts, “V”, and link to an quantity type Item.

You’re not alone in getting drawn into using profiles, something about the GUI invites people into this trap every week.

1 Like