Last active
October 16, 2020 16:25
-
-
Save mec-kon/5bd49d9167bb35106f7c387719df9e59 to your computer and use it in GitHub Desktop.
openhab mqtt configuration files for receiving temperature values and displaying the temperature and the time of receipt in openhab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String Test_Temperature_Str "Test String [%s]" {channel="mqtt:topic:test_temperature:test_temperature_channel"} | |
Number Test_Temperature "Temperature [%.2f °C]" <temperature> (Balcony, gTemperature) ["Temperature"] | |
DateTime Test_DateTime "last transmission [%1$tA, %1$tH:%1$tM]" <time> (Balcony, gTemperature) ["Temperature"] | |
Group Balcony "Balcony" <terrace> (Home) ["Outdoor"] | |
Group:Number:AVG gTemperature "Temperatur" <temperature> (Home) ["Temperature"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rule "Convert String to Item Number" | |
when | |
Item Test_Temperature_Str changed | |
then | |
// use the transformation service to retrieve the value | |
val temp_str = Test_Temperature_Str.state.toString | |
if(temp_str != "1000.00"){ | |
// post the new value to the Number Item | |
Test_Temperature.postUpdate(temp_str) | |
Test_DateTime.postUpdate(new DateTimeType()) | |
logInfo("temp", temp_str) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All you have to do to display a temperature value to openHab is to add a "Generic MQTT Thing" in the PaperUI of openHab and to add a channel to this ,which has the topic of the temperature sensor as "MQTT state topic"(e.g. "/home/balcony/temperature").
Note that the id of the "Generic MQTT Thing" and the id of the channel are the same as in the string "Test_Temperature_Str"(mqtt:topic:test_temperature:test_temperature_channel) .
You also need to add the default.items file to the /etc/openhab2/items folder and the temperature.rules file to the /etc/openhab2/rules folder.