httpResponses no work  [Solved]

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

Moderator: leecollings

Post Reply
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

httpResponses no work

Post by Hydci »

Hello, I'm looking for some help I've tried several ways but I can not get the principle working and simple I open the url if the answer and False then I do an action if the answer and different from False I did another action thanking you in advance for the help

Code: Select all

return {
	on = {
		timer = {
        			'at 14:17'	                                    -- pour programmer la récurrence de la requête dans le temps 
		},
		httpResponses = {
			'False'                                                                   -- doit correspondre au  callback donné dans openURL command
		}
	},
	execute = function(dz, item)

		if (item.isTimer) then
			dz.openURL({
				url = 'http://domogeek.entropialux.com/schoolholiday/B/now',                                     
				method = 'GET',
				callback = 'False',
			})
		end

		if (item.isHTTPResponse == 'False') then
		dz.devices("vacances scolaires").switchOff()
        elseif (item.isHTTPResponse ~= 'False') then
		dz.devices("vacances scolaires").switchOn()
			end
		end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: httpResponses no work  [Solved]

Post by waaren »

Hydci wrote: Thursday 31 October 2019 14:26 Hello, I'm looking for some help I've tried several ways but I can not get the principle working and simple I open the url if the answer and False then I do an action if the answer and different from False I did another action thanking you in advance for the help
You use the HTPPResponse not as it meant to be used in dzVents.

Try it like this:

Code: Select all

scriptVar = 'schoolHoliday'

return 
{
    on = { timer = { 'at 14:50' },             -- pour programmer la récurrence de la requête dans le temps 
        
    httpResponses = { scriptVar }},   -- doit correspondre au  callback donné dans openURL command
    
    logging = { level = domoticz.LOG_DEBUG },  -- change to LOG_ERROR when everything works as expected

    execute = function(dz, item)
        _G.logMarker =  _G.moduleLabel 

        local schoolHolidayURL = 'http://domogeek.entropialux.com/schoolholiday/B/now'
        local vacancesScolaires = dz.devices("vacances scolaires")
        
        if not(item.isHTTPResponse) then
            dz.openURL({ url = schoolHolidayURL, callback = scriptVar })
        elseif item.ok then -- item isHTTPResponse
            dz.log('Response from ' .. schoolHolidayURL .. ' is ' .. item.data)
            if (item.data == 'False') then
                vacancesScolaires.switchOff()
            else
                vacancesScolaires.switchOn()
            end
        else
            dz.log('Response from ' .. schoolHolidayURL .. ' not OK ' .. item.data)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: httpResponses no work

Post by Hydci »

Thank you for your solution actually I understand better how I have to do, so I made another script starting from your model for the seasons and it works perfectly
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest