Page 1 of 1
Power off switch after x time
Posted: Monday 02 May 2016 9:05
by Mazzokun
Hi, I'm a noob and i'm trying to power off a switch after X time
the built-in Off Delay option doesn't work, so i wrote a lua script for putting off the switch called "cancello" after 7 seconds:
Code: Select all
commandArray = {}
if (devicechanged['cancello'] == 'On') then
commandArray['cancello']='Off AFTER 7'
end
return commandArray
Is it correct?
I wrote it in the built-in section Setup>more>events and flagged as active but nothing happens.
So I put a copy in ~/domoticz/scripts/lua/script_time_sette.lua and wrote "script://script_time_sette.lua" into "On Action" setting of the switch but nothing happens.
So i tried writing "script://domoticz/scripts/lua/script_time_sette.lua" but nothing happens.
Where is the mistake?
Thank you for support

Re: Power off switch after x time
Posted: Monday 02 May 2016 10:36
by pj-r
RTFM
- Spoiler: show
- You should use device as trigger. Time based script will be triggered once a minute.
Remove the script from on action and rename it to "script_device_sette.lua" so it will be triggered when some device changes state.
Re: Power off switch after x time
Posted: Monday 02 May 2016 14:15
by Mazzokun
Ok, thank you very much
I've changed the name of script and the name of the switch and the name of the switch in the script ... error in log file:
Code: Select all
2016-05-02 14:09:22.929 User: Admin initiated a switch command
2016-05-02 14:09:22.936 EventSystem: Script event triggered: script_device_sette.lua
2016-05-02 14:09:22.930 (KmTronic) Lighting 2 (Cancello)
2016-05-02 14:10:00.478 Error: EventSystem: in script_device_sette.lua: [string "commandArray = {}..."]:2: attempt to index global 'devicechanged' (a nil value)
2016-05-02 14:11:00.493 Error: EventSystem: in script_device_sette.lua: [string "commandArray = {}..."]:2: attempt to index global 'devicechanged' (a nil value)
2016-05-02 14:12:00.008 Error: EventSystem: in script_device_sette.lua: [string "commandArray = {}..."]:2: attempt to index global 'devicechanged' (a nil value)
What is this??

Re: Power off switch after x time
Posted: Monday 02 May 2016 15:11
by pj-r
Look at the times.. you have still have your time based script somewhere launching once a minute.
Time based script doesnt have global variable called devicechanged what you are trying to use there..
Re: Power off switch after x time
Posted: Monday 02 May 2016 18:10
by Mazzokun
I have reinstalled Domoticz, added my 16 switch devices, and write the simple script.lua for that switch...
error log is the same
the weird thing is that also timers for others device doesn't work
where is my mistake?
Re: Power off switch after x time
Posted: Monday 02 May 2016 18:35
by jvdz
There is no need to reinstall domoticz. so what did you name your lua script and where is it stored?
Jos
Re: Power off switch after x time
Posted: Monday 02 May 2016 18:39
by SweetPants
If you used the build_in script editor, did you also change the script event type to 'device' instead of 'time' when you saved the script?
Re: Power off switch after x time
Posted: Monday 02 May 2016 23:53
by Mazzokun
Hi! This is the new log:
Code: Select all
2016-05-02 18:39:44.740 User: Admin initiated a switch command
2016-05-02 18:39:44.746 EventSystem: Script event triggered: script_device_sette.lua
2016-05-02 18:39:44.740 (KMTronic) Lighting 2 (Cancello)
2016-05-02 18:41:11.411 KMTronic: Serial Worker stopped...
2016-05-02 18:41:13.422 KMTronic: Using serial port: /dev/ttyUSB0
nothing happens...
Is there a way to send serial command with a script within domoticz? Because if i send HEX: FF 01 00 serial command the switch goes off..

Re: Power off switch after x time
Posted: Wednesday 04 May 2016 16:52
by Mazzokun
OK, kmtronic native support of devices broke times control..
As work-around I created dummy switches and used scripts with echo serial command into on action/off action field of every switch.

Re: Power off switch after x time
Posted: Thursday 05 May 2016 22:17
by Mazzokun
Fixed with last beta!
PERFECT