Blame | Last modification | View Log | Download
-- local device id's, only used in this scriptlocal cDevAnyoneHome = 158local cVirtTimer = 186local cDevSunPower = 173local cDevTuya = 184-- local constantslocal cMinSinPower = 9999 -- Watt/m2local cHysSinPower = 9999 -- Watt/m2-- domoticz user variablesuVarOverride = 'dmLampjesBoom_Override'return {on = {devices = {cDevAnyoneHome, cVirtTimer, cDevSunPower, cDevTuya},timer = {},variables = {},scenes = {},groups = {},security = {},httpResponses = {},customEvents = {},system = {}},logging = {--level = domoticz.LOG_DEBUG + domoticz.LOG_INFO,level = domoticz.LOG_ERROR,marker = "Tuya-Lampjes"},execute = function(domoticz, triggeredItem)-- domoticz.log('event file Tuya-152')-- check if device is turned on manual, if so just set Overrideif (triggeredItem.isDevice and triggeredItem.id == cDevTuya) then--commandArray['Variable:dmTuya152_Override']= tostring(((domoticz.devices(cDevTuya).active) and 1 or 0))domoticz.log('trigger is Tuya device: ' .. tostring(((domoticz.devices(cDevTuya).active) and 1 or 0)))--commandArray['Variable:dmTuya152_Override']= tostring(123)domoticz.variables(uVarOverride).set(((domoticz.devices(cDevTuya).active) and 1 or 0))end-- remove override if virtual timer changesif (triggeredItem.isDevice and triggeredItem.id == cVirtTimer) then--commandArray['Variable:dmTuya152_Override']= tostring(((domoticz.devices(cDevTuya).active) and 1 or 0))domoticz.log('trigger is virtual Tuya timer: ' .. tostring(((domoticz.devices(cVirtTimer).active) and 1 or 0)))domoticz.variables(uVarOverride).set(0) -- turn override offendlocal lOverRide = (domoticz.variables(uVarOverride).value ~= 0)local lTimerOn = domoticz.devices(cVirtTimer).activelocal lSunPowerOff = (tonumber(domoticz.devices(cDevSunPower).state) > (cMinSinPower+cHysSinPower)) and true or false --var = false and 20 or 30 return 30local lSunPowerOn = (tonumber(domoticz.devices(cDevSunPower).state) < cMinSinPower) and true or false --var = false and 20 or 30 return 30local lAnyoneHome = domoticz.devices(cDevAnyoneHome).activelocal lDeviceOn = domoticz.devices(cDevTuya).activedomoticz.log('Sun power: ' .. tostring(domoticz.devices(cDevSunPower).state))domoticz.log('lOverRide, lTimerOn, lAnyoneHome, lSunPowerOn, lSunPowerOff: ' .. tostring(lOverRide) .. ', ' .. tostring(lTimerOn) .. ', ' .. tostring(lAnyoneHome) .. ', ' .. tostring(lSunPowerOn) .. ', ' .. tostring(lSunPowerOff))-- only change state of device if there is no overrideif not lOverRide then-- turn device on, if it is offif(lTimerOn and lSunPowerOn and lAnyoneHome) then-- turn device ondomoticz.devices(cDevTuya).switchOn().silent()end-- turn device off if there is no overrideif(not lTimerOn or lSunPowerOff or not lAnyoneHome) thendomoticz.devices(cDevTuya).switchOff().silent()endendend}