Mqtt transformation issues

Good evening.

I am slowly approaching my goal, but unfortunately I have not yet reached it. I have searched various forums and websites, but there is no way that I have really found 100%. Most solutions use Tasoma for reading/transmitting, but I can’t use imho.

About my problem:
I have set up a small weather station based on a RPI Zero W with Pimoroni Enviro (sensors: BME280, LTR-559 & noise sensor) and send the data via MQTT to my broker. There .json data arrives. The connection also works. I have tested this with a MQTT.fx client.

Since I am still quite new in the whole automation topic, I can’t find out how to get displayable values for my OH2 from the .json values. It seems that I need the JSONPATH Transformation Binding, which I have also installed via the PaperUI.

Can someone please explain to me step by step what is necessary? I am just at the end of my Latin. I thank you very much.

What have you tried that failed? The volunteers here help you achieve your goal. We ndo not provide complete solutions like a Help Desk.

Show us exactly your:

  • Thing configuration
  • Item configuration
  • MQTT Topic
  • JSON message
1 Like

openHAB version & MQTT binding version would be appropriate too.

Hej folks, please excuse me for not creating a forum conform request. I have already read several documentations and just did not know what to do. I definitely do not expect complete soultions, because I want to learn something.
To your questions:

That is what I tried to describe above. I tried to transform my generated .json data to display it in OH. Unfortunately the command did not work or something is missing.

Although, as written above, I have already read various documentations, I did not know until now that I had to create a Thing configuration. So far I have only created a MQTT Generic Thing and tried to link my values via a channel.

Number   Sensor_MasterTemperature    "Temperatur [%.1f °C]"   <temperature> (gSensorTemperature)  { mqtt="<[broker:enviroplus/kinderzimmer/thermometer:state:JSONPATH($.BME280.Temperature)]" }
Number   Sensor_MasterHumidity       "Luftfeuchtigkeit [%.1f %%]"   <humidity>    (gSensorHumidity)     { mqtt="<[broker:enviroplus/kinderzimmer/thermometer:state:JSONPATH($.BME280.Humidity)]" }
Number   Sensor_MasterPressure       "Luftdruck [%.1f bar]"  <pressure>    (gSensorPressure)     { mqtt="<[broker:enviroplus/kinderzimmer/thermometer:state:JSONPATH($.BME280.Pressure)]" }
Number   Sensor_MasterLight          "Lux [%.1f lx]"  <light>    (gSensorLight)     { mqtt="<[broker:enviroplus/kinderzimmer/thermometer:state:JSONPATH($.LTR559.Light)]" }
enviroplus/kinderzimmer/thermometer

from the SSH console
The JSON message, which is displayed at the end in the MQTT Client, is located between the curly brackets {}

broker: 192.168.178.24
client_id: raspi-00000000fd34758f
port: 1883
topic: enviroplus/kinderzimmer/thermometer

Press Ctrl+C to exit!

RPi serial: 00000000fd34758f
Wi-Fi: connected

MQTT broker IP: 192.168.178.24
connected OK
{'temperature': 11, 'pressure': 630, 'humidity': 134, 'lux': 0, 'serial': '00000000fd34758f'}                                                                                        
mid: 1
{'temperature': 18, 'pressure': 980, 'humidity': 67, 'lux': 0, 'serial': '00000000fd34758f'}                                                                                        
mid: 2
{'temperature': 18, 'pressure': 980, 'humidity': 68, 'lux': 0, 'serial': '00000000fd34758f'}                                                                                        
mid: 3

openHAB 2.5.10-1 (Release Build)

binding-mqtt - 2.5.10

I hope I have provided all the necessary data so far? What kind of information must the thing contain?

Thanks for your support.

If this is the full JSON message:

{'temperature': 11, 'pressure': 630, 'humidity': 134, 'lux': 0, 'serial': '00000000fd34758f'}                                                                                        

Then it looks like you only need to use the following for your JSONPATH transformation:

JSONPATH:$.pressure

For Incoming Value Transformation

Although I’m slightly confused about the three JSON messages you show - are they at different times? Different sensors?

Note also that your Items are using v1 MQTT binding configuration, but it looks like you’re using the V2 MQTT binding. See here for how to set that up:

These are different times. A new value is sent every 5 seconds.

I’ll try this in the next days. Thanks!

1 Like

Haha! Your temperature increased by 7 degrees C in 5 seconds?! Let me know what heating system you use - I’ll buy it tomorrow!! :wink:

1 Like

No, if I let the script continue, it will normalise. Only the first value always falls out of line. Could it be due to the delay?
Just look at the humidity. 100% is the maximum there and the script spits out 134%. :wink:

Haha, yes! You’re in an underwater fire for 5 seconds!

Hello @hafniumzinc,

i have now tried to configure my things and items using your example. Unfortunately it doesn’t create a thing using the .things configuration.

My thing configuration:

Bridge mqtt:systemBroker:openHAB  [ host="192.168.0.1", port="1883", secure=false, username="openhabian", password="mypasswd"]
{
Thing topic thermometer "Thermometer" {
Channels:
    Type number : temperature  "Temperatur"           [ stateTopic="enviroplus/kinderzimmer/thermometer", transformationPattern="JSONPATH:$.temperature"]
    Type number : pressure     "Luftdruck"            [ stateTopic="enviroplus/kinderzimmer/thermometer", transformationPattern="JSONPATH:$.pressure"]
    Type number : humidity     "Luftfeuchtigkeit      [ stateTopic="enviroplus/kinderzimmer/thermometer", transformationPattern="JSONPATH:$.humidity"]
    Type number : lux          "Beleuchtungsstärke"   [ stateTopic="enviroplus/kinderzimmer/thermometer", transformationPattern="JSONPATH:$.lux"]
    }
}

My item configuration

Number temperature "Temperatur"          { channel="mqtt:topic:openHAB:mything:temperature" }
Number pressure    "Luftdruck "          { channel="mqtt:topic:openHAB:mything:pressure" }
Number humidity    "Luftfeuchtigkeit"    { channel="mqtt:topic:openHAB:mything:humidity" }
Number lux         "Beleuchtungsstärke"  { channel="mqtt:topic:openHAB:mything:lux" }

How do I still get the units (°C, %, hPa, lx) in my view?

Thanks for your help.

How do you know? What do the logs say when you try to save the Things file?

I see no new Thing in my PaperUI. I thought a new Thing is created with the file?

Unfortunately this does not say anything. I save the Thing in the directory /srv/openhab2-conf/things with the title thermometer.things
I’ve created the file with sudo nano thermometer.things
Is there another command with which I can test the file?

What is openHAB installed on, and how did you install it?

I installed from apt, and my configurations are stored in /etc/openhab2/

Your folder location doesn’t seem to match any of those on this page:

I installed openHAB with a pre-configured SD-card image on a Raspberry Pi and then updated via openhabian-config.

I can just see that my configurations are also stored in the folder /etc/openhab2/things as well. However, the documentation also says that my other folder is not wrong.
Anyway, the thing is unfortunately not created and I don’t know the reason.

I am a bit confused, because until now all manually created items or things were created. Also the Items shown above are created normally. Only this one Thing is not created.

Assuming your Thing file is stored in the correct location, have you tried restarting openHAB?

Thank you very much. My problem is finally solved. I can display it in my PaperUI.

OK, you’ve just experienced the annoying bug with Things files!

What I do, instead of restarting openHAB, is deliberately corrupt the Things file (remove a {, for example), then save. openHAB will complain and unload the Things. Then, restore the Things file (put the { back in) and re-save: you should see the logs load up the Things again!