lua script On FOR 1 minute
Moderator: leecollings
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
lua script On FOR 1 minute
Hi all,
I am running Domoticz v2.3598 on Ubuntu and finding the lua scripting 'On FOR n' doesn't appear to work:
if (devicechanged['LWSwitch'] == 'On') then
commandArray['Lamp']='On FOR 1'
end
I wondered if this was seconds and On FOR 60 doesn't work either.
Plus I tried " instead of ' just in case it is fussy.
Any clues?
Thanks a lot
Ian
I am running Domoticz v2.3598 on Ubuntu and finding the lua scripting 'On FOR n' doesn't appear to work:
if (devicechanged['LWSwitch'] == 'On') then
commandArray['Lamp']='On FOR 1'
end
I wondered if this was seconds and On FOR 60 doesn't work either.
Plus I tried " instead of ' just in case it is fussy.
Any clues?
Thanks a lot
Ian
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
-
- Posts: 192
- Joined: Monday 12 January 2015 23:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: FRANCE
- Contact:
Re: lua script On FOR 1 minute
Hi,
The wiki http://www.domoticz.com/wiki/LUA_commands said "FOR" is in minutes when the "AFTER" is in seconds.
a workaround may be to use "AFTER" ?
The wiki http://www.domoticz.com/wiki/LUA_commands said "FOR" is in minutes when the "AFTER" is in seconds.
a workaround may be to use "AFTER" ?
Code: Select all
commandArray[1]={['Relay1']='On'}
commandArray[2]={['Relay1']='Off AFTER 3'}
return commandArray
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
-
- Posts: 192
- Joined: Monday 12 January 2015 23:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: FRANCE
- Contact:
Re: lua script On FOR 1 minute
On second thought, personally I won't be confident with the "FOR" instruction because I don't know How it was designed in Domoticz , (consider that for working, the "on FOR" must assume that Domoticz knows the inverse state of each type of device (open / close, on/off...) For example if you send 2x ON command. The second last state is ON or OFF ?)
So I will really use AFTER with a little more logic :
So I will really use AFTER with a little more logic :
Code: Select all
if device changed then
if device value ==ON then send command OFF after XX seconds
(else nothing to do because the device value == off)
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Thanks a lot - I tried Off AFTER 7 seconds and it ignored it. I haven't put the device current state logic in yet but tried this from a known state.
Perhaps there is something wrong with the lua installation I have since I am running domoticz (from make file) on Ubuntu. The lua release is 5.2.2 as found in $HOME/domoticz/lua
Best regards and thanks again
Ian
Code: Select all
if (devicechanged['LWSwitch'] == 'On') then
commandArray['Lamp']='On'
commandArray['Lamp']='Off AFTER 7'
end
Best regards and thanks again
Ian
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: lua script On FOR 1 minute
It will ignore one as you are overriding the table entry "lamp" when you do it that way.It should look like this:
Jos
Code: Select all
if (devicechanged['LWSwitch'] == 'On') then
commandArray[1]={['Lamp']='On'}
commandArray[2]={['Lamp']='Off AFTER 7'}
end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Thanks Jos.
I tried that and it's still not working - pointing towards an lua issue perhaps...
I tried that and it's still not working - pointing towards an lua issue perhaps...
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
- nayr
- Posts: 354
- Joined: Tuesday 11 November 2014 18:42
- Target OS: Linux
- Domoticz version: github
- Location: Denver, CO - USA
- Contact:
Re: lua script On FOR 1 minute
There is more than one way to skin a cat, its more work but you can try a timer script as a work around.. I dont use the FOR and AFTER statements, I use timer scripts to cleanup after me, like so:
script_device_lwswitch.lua
script_time_lamp.lua
All my lighting has scripts like this, but with longer timeouts and without the user-variable logic.. just so people dont leave lights on since I have not got around to installing motion sensors yet. (closets/laundry rooms get like 10mins, bedrooms an hour, kitchen and work areas get several hours)
script_device_lwswitch.lua
Code: Select all
if (devicechanged['LWSwitch'] == 'On') then
commandArray['Lamp']='On'
commandArray['Variable:lamptriggered'] = tostring(1)
end
Code: Select all
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
if (otherdevices['Lamp'] == 'On') and (timedifference(otherdevices_lastupdate['Lamp']) >= 420) and (uservariables['lamptriggered'] == 1) then
commandArray['Lamp']='Off'
commandArray['Variable:lamptriggered'] = tostring(0)
print("Lamp was triggered by an event more than 7mins ago, time to turn it off.")
end
return commandArray
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: lua script On FOR 1 minute
Any more details on the "not working" bit?whiteduck wrote:Thanks Jos.
I tried that and it's still not working - pointing towards an lua issue perhaps...

Do you see anything in the domoticz log?
Maybe add some print() statements in the lua script to see if it gets fired and inside the "if" to see if it is true.
The output should also show up in the log.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Nayr - many thanks - nice alternative solution!
Jos - yeah sorry I was a bit vague - I added a print inside the if then but it doesn't get into the log file however the command is firing as seen in the log and by the fact the light comes on - it just doesn't go off after 30, 7 or any time combination
Jos - yeah sorry I was a bit vague - I added a print inside the if then but it doesn't get into the log file however the command is firing as seen in the log and by the fact the light comes on - it just doesn't go off after 30, 7 or any time combination

Code: Select all
2016-01-10 22:32:18.483 EventSystem: Script event triggered: /root/domoticz/scripts/lua/script_device_lwrf2.lua
2016-01-10 22:32:18.478 (RFXCOM) Lighting 5 (LWSwitch2)
2016-01-10 22:32:19.161 OpenZWave: Domoticz has send a Switch command! NodeID: 10 (0x0a)
Code: Select all
if (devicechanged['LWSwitch'] == 'On') then
print('Lamp On')
commandArray[1]={['Lamp']='On'}
commandArray[2]={['Lamp']='Off AFTER 30'}
end
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: lua script On FOR 1 minute
Did you put the script in the On or Off action field of the switch in stead of storing it in domoticz/scripts/lua and naming it script_device_abc.lua?
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 29
- Joined: Wednesday 25 December 2013 12:17
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: lua script On FOR 1 minute
I tested this with a motion sensor.
Works perfectly for me, light goes off after 1 minute.
Im on version V2.4123r
Code: Select all
commandArray = {}
if (devicechanged['Rörelse'] == 'On' and otherdevices['Hörnbord'] == 'Off') then
commandArray['Hörnbord']='On FOR 1'
end
return commandArray
Im on version V2.4123r
---
Gert
Gert
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Thanks Gert
Jos - no I have it in the lua directory… could this be the problem?
Jos - no I have it in the lua directory… could this be the problem?
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
- nayr
- Posts: 354
- Joined: Tuesday 11 November 2014 18:42
- Target OS: Linux
- Domoticz version: github
- Location: Denver, CO - USA
- Contact:
Re: lua script On FOR 1 minute
yes, it has to be in the scripts/lua folder with a specific filename to be called, if its not, ~/domoticz/scripts/lua/script_device_*.lua then its never going to get executed.
the lua folder @ ~/domoticz/lua is a source path, not a script path.
the lua folder @ ~/domoticz/lua is a source path, not a script path.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Thanks Nayr - I was replying to Jos asking:
Did you put the script in the On or Off action field of the switch in stead of storing it in domoticz/scripts/lua and naming it script_device_abc.lua?
It's getting executed - the issue is the FOR command doesn't appear to work
Thanks
Did you put the script in the On or Off action field of the switch in stead of storing it in domoticz/scripts/lua and naming it script_device_abc.lua?
It's getting executed - the issue is the FOR command doesn't appear to work
Thanks
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Everyone,
I realised I was being a bit of a muppet - really sorry - I had two very similar lua scripts and two similar LWRF switches - I was changing the wrong script!!! Thanks a lot for your help… now I am off to hide for a while.
I realised I was being a bit of a muppet - really sorry - I had two very similar lua scripts and two similar LWRF switches - I was changing the wrong script!!! Thanks a lot for your help… now I am off to hide for a while.
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
- nayr
- Posts: 354
- Joined: Tuesday 11 November 2014 18:42
- Target OS: Linux
- Domoticz version: github
- Location: Denver, CO - USA
- Contact:
Re: lua script On FOR 1 minute
Plebkac is the number one cause of issues here it seems 
Glad you got it figured out, editing a file you think is another file can become quite maddening.. I feel for yeh.

Glad you got it figured out, editing a file you think is another file can become quite maddening.. I feel for yeh.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
-
- Posts: 44
- Joined: Tuesday 25 March 2014 23:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Berkshire, UK
- Contact:
Re: lua script On FOR 1 minute
Time to merge the scripts since they control the same lamp!
Sorry to waste peoples time!
Sorry to waste peoples time!
Domoticz on Ubuntu 16.04 LTS VM
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
RFXCom USB transceiver
Aeon Labs V2 USB (Zwave)
Various HomeEasy, Oregon devices and sensors. Now using Z-Wave Fibaro FGMS-001, TKB TZ88Es
TP-Link IP310 Cameras
-
- Posts: 31
- Joined: Tuesday 03 November 2020 10:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: lua script On FOR 1 minute
My time was not wasted reading this post. This code snippet helped me to solve my problem.
Code: Select all
commandArray[1]={['Lamp']='On'}
commandArray[2]={['Lamp']='Off AFTER 30'}
Who is online
Users browsing this forum: No registered users and 1 guest