Temp and Humidity OpenGarage  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
xHuubx
Posts: 5
Joined: Monday 28 December 2015 13:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Temp and Humidity OpenGarage

Post 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
Schermafbeelding 2019-11-26 om 13.38.16.png (50.23 KiB) Viewed 1236 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..

Code: Select all

2019-11-26 13:51:00	nil
Can someone help me ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temp and Humidity OpenGarage

Post 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.... :D
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
xHuubx
Posts: 5
Joined: Monday 28 December 2015 13:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temp and Humidity OpenGarage

Post by xHuubx »

Only the Temp and Humidity in a virtual temp/hum sensor would be great!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temp and Humidity OpenGarage

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
xHuubx
Posts: 5
Joined: Monday 28 December 2015 13:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temp and Humidity OpenGarage

Post by xHuubx »

I tried your suggestion, now I get following error:
Schermafbeelding 2019-11-26 om 19.23.45.png
Schermafbeelding 2019-11-26 om 19.23.45.png (111.56 KiB) Viewed 1203 times
Nil value.. I have set the interval on 1 minute to test it..
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temp and Humidity OpenGarage

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
xHuubx
Posts: 5
Joined: Monday 28 December 2015 13:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temp and Humidity OpenGarage  [Solved]

Post by xHuubx »

It worked!! this is awesome!
The log:
Schermafbeelding 2019-11-26 om 20.45.53.png
Schermafbeelding 2019-11-26 om 20.45.53.png (131.01 KiB) Viewed 1191 times
And the sensor data in Domoticz:
Schermafbeelding 2019-11-26 om 20.44.37.png
Schermafbeelding 2019-11-26 om 20.44.37.png (72.28 KiB) Viewed 1191 times
Great job waaren, thx again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest