Rule OpenHAB

Hello everyone.
In my OpenHAB system I have:
esp8266 from DS18B20, which publishes the temperature in topic esp32-2
esp32 from BME280 which publishes in esp32 tea
I also have an esp32 with display topics to which the LCD1602 HG44780 display is connected, which contains in one line the displayed temperature from the eso32-2 DS18B20 topic and in the second line the temperature from BME280 in the esp32 topic.
Then to get information about how it is controlled for 5 seconds and for another 5 seconds the current time and data, just like for “DisplayMode 1” in tasmota and to keep it running like this forever.
I’m new to rules for OpenHAB, so I’m asking for a solution, I’ll be analyzing the proposed code and asking questions.
Sorry for my English, I’m a beginner at it.

Welcome to the openHAB community!
start here

then read this

you may also find this interesting

When you say “publishes the temperature in topic esp32-2” it implies you are publishing to a MQTT broker. Assuming that’s the case I do something similar and the following should get you started. I use file file definitions but I’m confident the same thing can be accomplished using the UI.

All of the data is published to MQTT in JSON, for example:

{ "Attic": { "humidity": "37", "temperature": "66" } }

First you will need to install the MQTT binding in OpenHAB. Next create a .things file that defines a bridge to your MQTT broker. Mine looks like this, you will need to change the host= to the IP address of your MQTT broker and also change (or remove) the username= and password=.

Bridge mqtt:broker:MqttBroker [ 
       host="192.168.0.5", 
       port="1883", 
       secure=false,
       username="MyMqttUserid", password="MyMqttPassword",
       clientID="OpenHab"]
{
    Thing topic AtticThing "Attic " {
    Channels:
        Type number : humidity     "Humidity"      [stateTopic="attic/status",transformationPattern="JSONPATH:$.Attic.humidity"]
        Type number : temperature  "Temperature"   [stateTopic="attic/status",transformationPattern="JSONPATH:$.Attic.temperature"]
    } 
}

The .items file contains

Number AtticHumidity                 "Attic Humidity [%d]"              {channel="mqtt:topic:MqttBroker:AtticThing:humidity"}  
Number:Temperature AtticTemp         "Attic Temperature [%.0f %unit%]"  {channel="mqtt:topic:MqttBroker:AtticThing:temperature"}

Hope this helps!
Jim

Thank you for the links and tips. That’s not exactly what I mean, I already have items and things in the files, I mean the rules file.

Hello again. I worked a bit on the rules in openhab and now I know more. But please give me a hint as to why I should write a rule like this:

rule "TIME"
when
    Time cron "0/1 * * * * ?"
then
    val currentTime = now.toString("HH:mm")
    val mqttActions = getActions("mqtt","mqtt:broker:broker")
    mqttActions.publishMQTT("cmnd/display/displaytext","[z]"  +currentTime)
end

I see the date and time on the display, I would like to see only the time.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.