[SOLVED] Analyzing Temperature and Humidity in OpenHab

Hi all,

I’m using USB WDE1-2 receiver and some temperature and humidity sensors to analyze temperature and humidity in several rooms of my house.

I have a python script that waits for information from this receiver and then forwards the information via mqtt. These messages look like

$1;1;;18,4;21,3;;;;24,4;;;45;40;;;;31;;;;;;;;0;2018-12-27 16:28:clock1030:

This line contains temperature data (18.4 °C, 21.3 °C, 24.4 °C) and humidity data (45%, 40%, 31%) from three different sensors.

This means, when the data comes to OpenHab, it still had to be converted. Is this something that can and should be done within OpenHab or should I send the 6 values to 6 (three temperature and three humidity topics) different topics for each sensor?

If I can convert the data, can this be done within OpenHab and how should I persist the data?

Thanks and kind regards,

Dirk

I would suggest sending data in JSON format, so that a JSON transform can be used to extract data to an item. I copied the idea from this thread, which shows a python script to read miFlora sensors and sends them via MQTT. Then the item definition contains the JSON transform.
Lionello

1 Like

Yes that would be easier
Easier to maintain
Easier to monitor externally with an mqtt tool
Easier to convert inside openHAB
This is what MQTT is meant for

1 Like

Hi,

thanks for your responses!

@Lionello_Marrelli: Thanks for that hint! I tried to use this example from the wiki to get it work: JsonPath - Transformation Services | openHAB but it doesn’t yet work as expected.

@vzorglub: Thanks. Then I’ll create a topic for each of the six values. Nevertheless I’d like to send it as JSON, so I can also send the exact timestamp when the values were measured.

The json file I send from my python script to the topic /home/temperature_humidity looks like

{"temperature-living-room":24.2,"temperature-bedroom":35.7,"temperature-bathroom":22.3,"humidity-living-room":56.3,"humidity-bedroom":48.9,"humidity-bathroom":62.1}

In PaperUi I added /home/temperature_humidity to the mqtt topic state input field.

My default.items file looks like:

String Temperature_json "Temperature [JSONPATH($.temperature-living-room):%s °C]" <text> { channel="mqtt:topic:d12234dk:house-living-room-temperature" }
Number Temperature "Temperature [%.1f °C]"

My default.sitemaps file looks like:

sitemap default label="Home"
{
    Text item=Temperature
}

Additionally I added a temperature_humidity.rules file that looks like:

rule "Convert JSON to Item Type Number"
  when
    Item Temperature_json changed
 then
    // use the transformation service to retrieve the value
    val newValue = transform("JSONPATH", ".$.temperature-living-room", Temperature_json.state.toString)

    // post the new value to the Number Item
    Temperature.postUpdate( newValue )
 end

What I see in the OpenHab App when I select the “Home” sitemap is

Temperature - °C

Do you have any clue, what I do wrong?

Thanks and kind regards

Dirk

Why don’t you do this?

Number Temperature "Temperature [%.1f °C]" { channel="mqtt:topic:d12234dk:house-living-room-temperature" }

And add the transformation in the channel settings
JSONPATH:$.temperature-living-room

This way you don’t need a rule and you don’t need the string item
The Number item gets updated straight from the channel
You may need to delete the existing channel and create a new number channel with the same same

1 Like

Thanks a lot for your response. This makes definitely sense and was something I already tried. After your response, I tried it again.

I first of all deleted the channel and recreated it as “Number”. I added the topic in the state input field and in the "Incoming value transformation I added “JSONPATH:$.temperature-living-room” (I tried it wrapped by quotes and I tried it unwrapped). Then I saved and copied your item definition in my default.items file and deleted the *.rules file again.

When I look into the logs after a new json information was sent, I see:

2018-12-28 21:07:52.976 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service “JSONPATH for pattern $.temperature-living-room” not found!

2018-12-28 21:07:52.982 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload ‘{“temperature-living-room”:24.2}’ not supported by type ‘NumberValue’

Any idea what I’m still doing wrong?

Thanks and kind regards,

Dirk

You need to install the JSONPATH transformation in the paperUI

1 Like

Ooooooooohhhhhhhhhhhh… I installed it and now it works. Thanks a lot for your patience and sorry for my confusion!

Kind regards,

Dirk

Short update: I now can read humidity and temperature as I wanted it. There are some more points I want to realize:

  • Persist all the values in a database
  • Show the date / time the data was measured
  • Perhaps ensuring, that my Python script sending the data via MQTT is still running

But the first part I wanted is now working and I like OpenHab already. Even if I had some problems, I already learned a lot in a very short time. Good job all the developers and thanks a lot to the community that helped me a lot!