Power off switch after x time

Moderator: leecollings

Post Reply
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Power off switch after x time

Post 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 :D
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: Power off switch after x time

Post by pj-r »

RTFM :lol: ;)
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.
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: Power off switch after x time

Post 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?? :oops:
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: Power off switch after x time

Post 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..
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: Power off switch after x time

Post 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 :o :(
the weird thing is that also timers for others device doesn't work :|
where is my mistake?
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Power off switch after x time

Post by jvdz »

There is no need to reinstall domoticz. so what did you name your lua script and where is it stored?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
SweetPants

Re: Power off switch after x time

Post 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?
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: Power off switch after x time

Post 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.. :idea:
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: Power off switch after x time

Post 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. :)
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: Power off switch after x time

Post by Mazzokun »

Fixed with last beta!
PERFECT
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest