I’m a beginner working on a home automation project with DHT11 sensor. I have created a webserver with the values from the sensor using NodeMCU.
I’m unsure on how to get those values onto my Basic UI of openhab2.
items file
Group All
Group gGroundFloor (All)
Group GF_Living "Living Room" <video> (gGroundFloor)
Number TestTemperatureC "Temperature [%.1f C]" <temperature> (GF_Living) { http="<[http://192.168.1.13/:6000:REGEX(.*?<html>(.*?)</html>.*)]" }
Number TestTemperatureF "Temperature [%.1f F]" <temperature> (GF_Living) { http="<[http://192.168.1.13/:6000:REGEX(.*?<html>(.*?)</html>.*)]" }
Number TestHumidity "Humidity [%.1f %%]" <water> (GF_Living) { http="<[http://192.168.1.13/:6000:REGEX(.*?<html>(.*?)</html>.*)]" }
I dont understand what transformation rule I must use.
rules file
rule “Set room temperatures in C”
when
System started or
Time cron "5 * * * * ?"
then
val result = sendHttpGetRequest("http://192.168.1.13/celsiusTemp")
TestTemperatureC.postUpdate(result)
end
rule "Set room temperatures in F"
when
System started or
Time cron "5 * * * * ?"
then
val result = sendHttpGetRequest("http://192.168.1.13/fahrenheitTemp")
TestTemperatureF.postUpdate(result)
end
rule "Set room humidity"
when
System started or
Time cron "5 * * * * ?"
then
val result1 = sendHttpGetRequest("http://192.168.1.13/humidityTemp")
TestHumidity.postUpdate(result1)
end
My basic UI has labels of temperature and humidity but no values are getting updated from the url.
Should I configure my http binding differently?
Any help will be appreciated.
What is the content of the page http://192.168.1.13/:6000 exactly?
You don’t need the binding on the items because you are pulling the value with a cron rule
You could use the binding and then you would not need rules but I don’t know the exact content of the page you publish so I can’t help you with your transformation
Without the binding
The items should be:
Group gGroundFloor (All)
Group GF_Living "Living Room" <video> (gGroundFloor)
Number TestTemperatureC "Temperature [%.1f C]" <temperature> (GF_Living)
Number TestTemperatureF "Temperature [%.1f F]" <temperature> (GF_Living)
Number TestHumidity "Humidity [%.1f %%]" <water> (GF_Living)
The rules should be put together:
You also need to use a time out parameter in the sendHttpGetRequest action.
rule "Set room temperatures in F"
when
System started or
Time cron "5 * * * * ?"
then
var result = sendHttpGetRequest("http://192.168.1.13/celsiusTemp", 5000)
TestTemperatureC.postUpdate(result)
result = sendHttpGetRequest("http://192.168.1.13/fahrenheitTemp", 5000)
TestTemperatureF.postUpdate(result)
result = sendHttpGetRequest("http://192.168.1.13/Humidity", 5000)
TestHumidity.postUpdate(result)
end
You could also make use of the UoM (Units system) items
Group gGroundFloor (All)
Group GF_Living "Living Room" <video> (gGroundFloor)
Number:Temperature TestTemperatureC "Temperature [%.1f °C]" <temperature> (GF_Living)
Number TestTemperatureF "Temperature [%.1f °F]" <temperature> (GF_Living)
Number TestHumidity "Humidity [%.1f %%]" <water> (GF_Living)
rule:
rule "Set room temperatures in F"
when
System started or
Time cron "5 * * * * ?"
then
var result = sendHttpGetRequest("http://192.168.1.13/celsiusTemp", 5000)
TestTemperatureC.postUpdate(result)
Thread:sleep(200) // Wait for TestTemperatureC to be updated
TestTemperatureF.postUpdate(TestTemperatureC.state)
result = sendHttpGetRequest("http://192.168.1.13/Humidity", 5000)
TestHumidity.postUpdate(result)
end
BUT
I would recommend that you change your approach with the nodeMCU code from the source and use MQTT to publish the values to a broker (mosquitto is recommended) and use the MQTT binding in OH to get the values without rules.
I made all the changes you suggested. I’m still unable to get the values from the url.
Sadly, I’m required to use NodeMCU in this project. I know it’s easier with the mosquito broker.