How to stop a running script.
Posted: Wednesday 04 March 2020 11:47
I have a Zigbee switch with multiple command.
I would like to have to script running at one command from the switch and stopped at a second command from the switch.
I tried to do that with setting an unsetting a data variable, but that does not work.
The initial script keeps on running until the lua 10 sec message in the Domoticz log.
This is my script.
I would like to have to script running at one command from the switch and stopped at a second command from the switch.
I tried to do that with setting an unsetting a data variable, but that does not work.
The initial script keeps on running until the lua 10 sec message in the Domoticz log.
This is my script.
Code: Select all
local socket = require 'socket'
return {
active = true,
-- active = false,
on = { devices = { 'SchakelaarEddy' } },
data = { Running = {initial=0} },
execute = function(dz, device)
Status = device.state
Level = dz.devices("Lamp Eddy").level
print('Device ' .. device.name .. ' Level: '.. Level .. ' Status:' .. Status)
if Status == 'On' then
dz.devices("Lamp Eddy").switchOn()
dz.devices("Lamp Eddy").dimTo(80)
elseif Status == 'Off' then
dz.devices("Lamp Eddy").switchOff()
dz.devices("Lamp Eddy").dimTo(0)
elseif Status == 'Up' then
dz.data.Running = 1
repeat
socket.sleep(0.5)
Level = Level + 10
if Level > 100 then
Level = 100
end
dz.devices("Lamp Eddy").dimTo(Level)
until dz.data.Running == 0
elseif Status == 'Down' then
dz.data.Running = 1
repeat
socket.sleep(0.5)
Level = Level - 10
if Level < 0 then
Level = 0
end
dz.devices("Lamp Eddy").dimTo(Level)
until dz.data.Running == 0
elseif Status == 'Stop' then
dz.data.Running = 0
end
end
}