Using JSONPATH to convert temperature sensor data

Hi everyone,

  • Platform information:

    • Hardware: RASPI4B/4GB
    • OS: Raspberry OS
    • Java Runtime Environment: Zulu11
    • openHAB version: 3.0.1
  • Issue of the topic:
    I am just on my first stepts getting openhab3 running and doing something. What I got so far: I installed Mosquito to use it as an MQTT broker. I added it as thing. I configured my sensor (a sonoff TH16 running tasmota) to connect to the MQTT broker. I added it as “Generic MQTT Thing” with 2 channels (one for the switch (Switch) and one for the sensor data(String)). I created 2 items to be linked to the channels. The switching item is working like expected. It updates the status if switch is operated at the device and it is switching the device if operated in openhab. As the string item for the temperature is showing the full json object I already found out that I need to install the transformation addon JSONPath. So have done this and tried to convert this object:
    So I did it within the “Channel Link” by selecting the profile JSONPATH and added $.DS18B20.Temperature in the expression. It worked so far and I got the result 22.6 but now I want to add the unit “°C” and dont know how to add something to the final string.
    I also tried to use JSONPATH in the things channel but here the translation service is not found: [t.generic.ChannelStateTransformation] - Transformation service “JSONPATH for pattern $.DS18B20.Temperature” not found!
    Any idea how to solve the unit problem and getting the transformation service working in the things config?

So, two separate things here.

You say you have the JSONPATH Transformation Service installed, but the above log entry is saying you don’t. Can you show us that it is installed? Perhaps try uninstalling and reinstalling it.

For what reason? Just for display somewhere?

This tutorial is almost exactly what you’re doing, except I used a Sonoff Basic and added a DHT22 sensor myself. See if it helps with the setup, as it also shows how to add units for display…

Take care, transformation type and parameters can be formatted in different ways in various places in openHAB where they may be used. Sometimes its JSONPATH($.Light) , sometimes JSONPATH:$.Light

number type channels of MQTT binding can be assigned a unit of measurement, and should then be linked to a Number:xxx Item of appropriate type.

Today I tried again and JSONPATH is now working without change.
Now as am I am using a number type channel even the unit is added, thanks for the hint.