How to read data in OH3 from mqtt

I have problem with reading data from mqtt.
I’m using mqtt on other things but on this new thing I can’t get it work.

I Can see in mosquitto something like this:

openhabian@openHABianDevice:~ $ mosquitto_sub -h ........ -u openhabian -P ....... -t home/energa

{"used": 11560.42, "produced": 7144.999}

In OH3 i set MQTT state topic: home/energa
and incoming value transformations to: JSONPATH:$.used

but even after this my item has “-” value…

Can you show us this mystery Thing, Channel and Item? Perhaps a wrong Item or Channel type?

You have a typo in the transformation. You need a period “.” between $ and “used”

1 Like

Yes, You are right, but this is only because I tried everything. But even with or without “.” nothing changes…

Note that small thing configuration edits may not get picked up immediately. When you have edited to your best guess, restart the binding or OH.

It’s really helpful to us that when possible you post the contents of the code tab in code fences rather than screen shots.

code goes here

If at first you don’t succeed, simplify. What if you remove the transformation entirely? Do you get the full JSON sent to the Item? (you may need to create a new text Channel and String Item to do this experiment). Then gradually build back up.

First add the transformation and verify that works.

Then go back to the Number Channel and make the configuration exactly the same and verify that works. Only then add back the UoM and Delta Value.

Be sure to watch openhab.log and events.log the whole time for errors.

The text channel and string item doesn’t change also…

here is Thing code:

UID: mqtt:topic:5aa2c65a64:Licznik_energa
label: Licznik Energa
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:5aa2c65a64
  - id: Energa_zuzycie
    channelTypeUID: mqtt:number
    label: Energa Zużycie
    description: ""
      stateTopic: home/energa
      transformationPattern: JSONPATH:$.used
      unit: kWh
  - id: Energa_produkcja
    channelTypeUID: mqtt:number
    label: Energa Produkcja
    description: ""
      unit: kWh
      formatBeforePublish: "%.4f"
      stateTopic: home/energa
      transformationPattern: JSONPATH:$.produced
  - id: test1
    channelTypeUID: mqtt:string
    label: test1
    description: ""
      stateTopic: home/energa

in logs there is nothing about this mqtt.

I have made DEBUG logs and faund this:

2022-03-10 14:03:33.664 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state '7172.23 kWh' with function '$.produced' and format '%s'

2022-03-10 14:03:33.669 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state '11582.656' with function '$.used' and format '%s'

Somewhere, you have applied a profile to a link(s) between a channel and an Item.

If you are doing JSONPATH transformations in the channel, you probably do not want a transformation profile as well. Set that to default.