switch with variable and delay
Posted: Sunday 06 October 2019 10:43
I have a switch that triggered a variable.
The switch works the variable go from 0 to 1
The only problem is that the switch is not working from another script
the variable switch
The alarm switch
and now the script that give a error on the switch on local alarmswitch = domoticz.devices('Alarm_On')
So my second question is the alarm voordeur.
I want to put a delay of 5 sec before the script is started.
Let say we go out and set alles uit living at 18.00
then we come back at midnight the alarm will be triggerd.
Then i need 5 sec to put the switch off that set the variable to 0 so the alarm is disabled.
The we go to sleep set alles uit living and the variable will be set to 1
The switch works the variable go from 0 to 1
The only problem is that the switch is not working from another script
the variable switch
Code: Select all
return
{
active = true,
on = { devices = { 'Alarm_On' }},
execute = function(domoticz,switch)
local varalarm = domoticz.variables('VarAlarm')
if switch.state == "On" then domoticz.variables('VarAlarm').set(1)
elseif switch.state == "Off" then domoticz.variables('VarAlarm').set(0)
end
end
}Code: Select all
return
{
active = true,
on = { devices = { 'Voordeur' }},
execute = function(domoticz,voordeur)
local alarm = domoticz.devices('Alarm')
local varalarm = domoticz.variables('VarAlarm')
if voordeur.active and domoticz.time.matchesRule('at 23:30-06:00') and varalarm.value == 1 then
alarm.cancelQueuedCommands()
alarm.switchOn().checkFirst()
alarm.switchOff().afterSec(60)
end
end
}Code: Select all
return {
on = {
devices = {"Alles_Uit_Living"}},
execute = function(dz,item)
local myScene = 1
local alarmswitch = domoticz.devices('Alarm_On')
dz.log('Name of dz.scenes(myScene): "' .. dz.scenes(myScene).name .. '"',dz.LOG_FORCE )
if item.state == "On" then
dz.scenes(myScene).switchOn()
alarmswitch.switchOn()
item.switchOff().afterSec(3).silent()
else
dz.scenes(myScene).switchOn()
end
end
}Code: Select all
2019-10-06 10:38:08.762 Status: User: Admin initiated a switch command (7/Alles_Uit_Living/On)
2019-10-06 10:38:08.861 Status: dzVents: Info: Handling events for: "Alles_Uit_Living", value: "On"
2019-10-06 10:38:08.861 Status: dzVents: Info: ------ Start internal script: Alles_Uit_Living: Device: "Alles_Uit_Living (Controller)", Index: 7
2019-10-06 10:38:08.861 Status: dzVents: Error (2.4.19): An error occured when calling event handler Alles_Uit_Living
2019-10-06 10:38:08.861 Status: dzVents: Error (2.4.19): ...z/scripts/dzVents/generated_scripts/Alles_Uit_Living.lua:7: attempt to index global 'domoticz' (a nil value)
2019-10-06 10:38:08.861 Status: dzVents: Info: ------ Finished Alles_Uit_Living I want to put a delay of 5 sec before the script is started.
Let say we go out and set alles uit living at 18.00
then we come back at midnight the alarm will be triggerd.
Then i need 5 sec to put the switch off that set the variable to 0 so the alarm is disabled.
The we go to sleep set alles uit living and the variable will be set to 1