Page 1 of 1
Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 13:52
by xHuubx
I have build a a garage door controller with the use of OpenGarage. Now I also added a Temperature and Humidity sensor. Every 10 minutes I would like to read out the values and store them in my Domticz, unfortunately I am not that experienced in using dzVents scripts in doing this..
OpenGarage has a API (
https://github.com/OpenGarage/OpenGarag ... I1.1.0.pdf) with this you can go to the url and the data is shown, this looks like:

- Schermafbeelding 2019-11-26 om 13.38.16.png (50.23 KiB) Viewed 1238 times
I tried:
Code: Select all
return {
on = {
timer = {
'every 10 minutes' -- just an example to trigger the request
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.178.16/jc',
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
local someValue = item.json.someValue -- just an example
-- update some device in Domoticz
domoticz.devices('myTextDevice').updateText(someValue)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
I created a dummy myTextDevice, but the reponse is Nill..
Can someone help me ?
Re: Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 15:24
by waaren
xHuubx wrote: ↑Tuesday 26 November 2019 13:52
I have build a a garage door controller with the use of OpenGarage. Now I also added a Temperature and Humidity sensor. Every 10 minutes I would like to read out the values and store them in my Domticz, unfortunately I am not that experienced in using dzVents scripts in doing this..
Happy to help but which information do you want in the virtual text device ?
Do you want the temperature and humidity in a virtual temp/hum sensor or separate or everything in the text device ?
So many questions and so few answers....

Re: Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 15:41
by xHuubx
Only the Temp and Humidity in a virtual temp/hum sensor would be great!
Re: Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 17:39
by waaren
xHuubx wrote: ↑Tuesday 26 November 2019 15:41
Only the Temp and Humidity in a virtual temp/hum sensor would be great!
Can you try this ?
Code: Select all
local scriptVar = 'garageData'
return
{
on =
{
timer =
{
'every 10 minutes'
},
httpResponses =
{
scriptVar
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when everything works as expected
marker = scriptVar,
},
},
execute = function(dz, item)
-- Enter your settings below this line
local garageURL = 'http://192.168.178.16/jc'
local temperatureHumidityDevice = dz.devices('garage') -- Change to name of your virtual temp / humidity device
-- No changes required below this line
local function humidityStatus(temperature, humidity) -- as used indz source
if humidity <= 30 then return dz.HUM_DRY
elseif humidity >= 70 then return dz.HUM_WET
elseif humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE end
return dz.HUM_NORMAL
end
if item.isTimer then
dz.openURL(
{
url = garageURL,
callback = scriptVar,
} )
elseif item.isHTTPResponse and item.ok then
if not(item.isJSON) then item.json = dz.utils.fromJSON(item.data) end
temperatureHumidityDevice.updateTempHum( rt.temp, rt.humid, humidityStatus( rt.temp, rt.humid ) )
else
dz.log('There was a problem handling the request; response is ' .. item.data, dz.LOG_ERROR)
end
end
}
Re: Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 19:25
by xHuubx
I tried your suggestion, now I get following error:

- Schermafbeelding 2019-11-26 om 19.23.45.png (111.56 KiB) Viewed 1205 times
Nil value.. I have set the interval on 1 minute to test it..
Re: Temp and Humidity OpenGarage
Posted: Tuesday 26 November 2019 20:26
by waaren
xHuubx wrote: ↑Tuesday 26 November 2019 19:25
I tried your suggestion, now I get following error:
Nil value.. I have set the interval on 1 minute to test it..
I made a small change. Please try again with this and if still not working share your json return from the browser and loglines as text in a code window.
Code: Select all
local scriptVar = 'garageData'
return
{
on =
{
timer =
{
'every 10 minutes'
},
httpResponses =
{
scriptVar
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when everything works as expected
marker = scriptVar,
},
},
execute = function(dz, item)
-- Enter your settings below this line
local garageURL = 'http://192.168.178.16/jc'
local temperatureHumidityDevice = dz.devices('garage') -- Change to name of your virtual temp / humidity device
-- No changes required below this line
local function humidityStatus(temperature, humidity) -- as used indz source
if humidity <= 30 then return dz.HUM_DRY
elseif humidity >= 70 then return dz.HUM_WET
elseif humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE end
return dz.HUM_NORMAL
end
if item.isTimer then
dz.openURL(
{
url = garageURL,
callback = scriptVar,
} )
elseif item.isHTTPResponse and item.ok then
if not(item.isJSON) then item.json = dz.utils.fromJSON(item.data) end
rt = item.json
temperatureHumidityDevice.updateTempHum( rt.temp, rt.humid, humidityStatus( rt.temp, rt.humid ) )
else
dz.log('There was a problem handling the request; response is ' .. item.data, dz.LOG_ERROR)
end
end
}
Re: Temp and Humidity OpenGarage [Solved]
Posted: Tuesday 26 November 2019 20:47
by xHuubx
It worked!! this is awesome!
The log:

- Schermafbeelding 2019-11-26 om 20.45.53.png (131.01 KiB) Viewed 1193 times
And the sensor data in Domoticz:

- Schermafbeelding 2019-11-26 om 20.44.37.png (72.28 KiB) Viewed 1193 times
Great job waaren, thx again!