Subversion Repositories rld.domoticz

Rev

Blame | Last modification | View Log | Download

--[[ 
        script to get and decode settings 

]]--

local scriptVar = 'getSettings'
local uVarProgram = 'dzSensorTimeout'


return 
{
    on = 
    {
        timer = { 'every 30 minutes' , --- change to your liking
                },
        httpResponses = { scriptVar,  
                        },
    system = {
      'start'
    },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'Dz-Settings',
    },
    
    execute = function(dz, item)
        
        local settingsEncoded = 
            {
                ClickatellTo = true,
                HTTPPostContentType = true,
                HTTPURL = true,
                EmailUsername = true,
                EmailPassword = true,
                ClickatellAPI = true,
                HTTPPostContentType = true,
                IFTTTAPI = true,
                MyDomoticzPassword = true,
            }
        
        local function showSettings(t)
            for key, value in pairs(t) do
                if settingsEncoded[key] then 
                    value = dz.utils.fromBase64(value)
                end
                dz.log(key .. ': ' .. dz.utils._.str(value) )
            end
        end

        if item.isTimer or item.isDevice or item.isSystemEvent then
            settingsURL = dz.settings['Domoticz url'] .. '/json.htm?type=settings' 
            dz.openURL(
            {
                url = settingsURL,
                callback = scriptVar
            })
        elseif item.isJSON then    
            --showSettings(item.json)
            dz.variables(uVarProgram).set(item.json["SensorTimeout"])
            dz.log("Trying to get one value, SensorTimeout = " .. item.json["SensorTimeout"], dz.LOG_DEBUG)
        else
            dz.log('There was a problem handling' .. item.trigger, dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}