I'm trying to get this function to work; but it doesn't trigger due to some logic problem or other error. Someone who could help me out with this.
When I change the timer to every minute and turn on debug I only get the following information.
Code: Select all
Status: dzVents: Info: Nintendo: ------ Start external script: Nintendo.lua:, trigger: every minute
Status: dzVents: Debug: Nintendo: Processing device-adapter for $blink_blauw: Switch device adapter
Status: dzVents: Debug: Nintendo: Processing device-adapter for $blink_geel: Switch device adapter
Status: dzVents: Debug: Nintendo: Processing device-adapter for $Vloer-LED-B: Switch device adapter
Status: dzVents: Debug: Nintendo: Processing device-adapter for $Vloer-LED-Y: Switch device adapter
Status: dzVents: Info: Nintendo: ------ Finished Nintendo.lua
The actual script
Code: Select all
--[[
Nintendo
als de switch of wii langer dan 35 minuten aanstaat, dan de blauwe LED laten knipperen. Als dat apparaat uit is dan LED weer uitzetten.
]]--
return {
active = true,
on = {
devices = { 'Wii', 'N_Switch' },
timer = { 'every 5 minutes' },
},
logging = {
level = domoticz.LOG_ERROR, -- change to LOG_ERROR when script executes OK
-- domoticz.LOG_DEBUG
marker = 'Nintendo',
},
-- dzVents 2.4 functie:
execute = function(domoticz,item)
local blauwblink = domoticz.devices('$blink_blauw')
local geelblink = domoticz.devices('$blink_geel')
local blauw = domoticz.devices('$Vloer-LED-B')
local geel = domoticz.devices('$Vloer-LED-Y')
-- local deviceToCheck = domoticz.devices().forEach(function(devicesToCheck)
local devicesToCheck = { 'Wii', 'N_Switch' }
local thresholdx = 35
local Time = require('Time')
-- setup
if ( item.isTimer ) then
for i, deviceToCheck in pairs(devicesToCheck) do
-- local minuten = domoticz.devices(deviceToCheck).lastUpdate.minutesAgo
local minuten = Time(deviceToCheck.lastUpdate)
-- Actual check!
-- if ( deviceToCheck.active and minuten.minutesAgo > thresholdx ) then
if ( deviceToCheck.active and minuten.minutesAgo > thresholdx ) then
if ( blauw.active ) then
domoticz.log('De blauwe LED staat al aan!')
else
blauwblink.switchOn()
domoticz.log('De blauwe LED knippert...')
domoticz.notify("Domoticz", "De " .. domoticz.devices(deviceToCheck) .. "staat al meer dan 35 minuten aan", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , "telegram")
end
end
end
end
if ( item.isDevice and not item.active ) then
blauwblink.switchOff().checkFirst()
-- blauw.switchOff().checkFirst()
domoticz.log('De blauwe LED knippert niet meer!')
end
end
}