Page 1 of 1

httpResponses no work

Posted: Thursday 31 October 2019 14:26
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
}

Re: httpResponses no work  [Solved]

Posted: Thursday 31 October 2019 14:52
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
}

Re: httpResponses no work

Posted: Thursday 31 October 2019 16:30
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