LUA script in dir clogs up log
Moderator: leecollings
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
LUA script in dir clogs up log
Hi all,
I have created a device script in the domoticz/script/lua directory.
I want to catch a set of contact sensors opening and then update a virtual switch with the overall status (i.e. House insecure). The aim is that i can dashboard the general house security status and see if someone has left a window open etc.
I've got the script working as a time script (checking device status every minute), but want to react quicker to a contact changing.
The only problem when converting to a device script is that it is triggered every few seconds when a new temperature reading comes in from one of the 12 or so temp devices i have. This then clogs the log with a "2018-05-13 21:51:57.586 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua" message every few seconds
Is there a way to either not have that message appear, or to not have the script trigger unless the devices im interested in change?
Thanks.
Running the latest Domoticz beta
I have created a device script in the domoticz/script/lua directory.
I want to catch a set of contact sensors opening and then update a virtual switch with the overall status (i.e. House insecure). The aim is that i can dashboard the general house security status and see if someone has left a window open etc.
I've got the script working as a time script (checking device status every minute), but want to react quicker to a contact changing.
The only problem when converting to a device script is that it is triggered every few seconds when a new temperature reading comes in from one of the 12 or so temp devices i have. This then clogs the log with a "2018-05-13 21:51:57.586 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua" message every few seconds
Is there a way to either not have that message appear, or to not have the script trigger unless the devices im interested in change?
Thanks.
Running the latest Domoticz beta
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: LUA script in dir clogs up log
You could convert your script to dzVents Lua and let it trigger only on the relevant devices. It does take some reading but the wiki is excellent and conversion is relatively simple.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA script in dir clogs up log
Ok thanks, I might try that. Yet another language to learn!waaren wrote:You could convert your script to dzVents Lua and let it trigger only on the relevant devices. It does take some reading but the wiki is excellent and conversion is relatively simple.

Sent from my iPhone using Tapatalk
- jvdz
- Posts: 2330
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA script in dir clogs up log
Sure, just make that change to line 12 of your script!

... oh wait, you didn't post any script and expect us to advise you in how to change it which is asking for a "stab in the dark".
Likely you are creating an indefinite loop by acting on a changed device and then change that device, or it is simply the case that a device is changed this often which triggers all devices scripts by design!. We would need to see the script to figure that out.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA script in dir clogs up log
Hi Jos,
Sorry, i thought (and not understanding how and when the device scripts are called or run, that i was just missing something obvious.
The script name is script_device_test.lua and the content is below. Normally the sensors all report back 'Closed', unless one is left Open.
commandArray = {}
local sensor1 = 'Front Door LR'
local sensor2 = 'Rear Door LR'
local sensor3 = 'Kitchen Window'
local sensor4 = 'Dining L Window'
local sensor5 = 'Dining R Window'
local sensor6 = 'Lounge R Window'
local sensor7 = 'Lounge F Window'
local alarm
local stext
stext = ""
alarm = "false"
commandArray = {}
if devicechanged[sensor1] == 'Open' then
alarm = "true"
stext = sensor1
print(sensor1 .. " Open")
end
if devicechanged[sensor2] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor2
print(sensor2 .. " Open")
end
if devicechanged[sensor3] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor3
print(sensor3 .. " Open")
end
if devicechanged[sensor4] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor4
print(sensor4 .. " Open")
end
if devicechanged[sensor5] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor5
print(sensor5 .. " Open")
end
if devicechanged[sensor6] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor6
print(sensor6 .. " Open")
end
if devicechanged[sensor7] == 'Open' then
alarm = true
stext = stext .. "-" .. sensor7
print(sensor7 .. " Open")
end
if alarm == 'false' then
commandArray['UpdateDevice'] = '1014|0|No Alert'
else
stext = "Alert-" .. stext
commandArray['UpdateDevice'] = '1014|4|'..stext
print("Alarm=" .. tostring(alarm))
end
return commandArray
Sorry, i thought (and not understanding how and when the device scripts are called or run, that i was just missing something obvious.
The script name is script_device_test.lua and the content is below. Normally the sensors all report back 'Closed', unless one is left Open.
commandArray = {}
local sensor1 = 'Front Door LR'
local sensor2 = 'Rear Door LR'
local sensor3 = 'Kitchen Window'
local sensor4 = 'Dining L Window'
local sensor5 = 'Dining R Window'
local sensor6 = 'Lounge R Window'
local sensor7 = 'Lounge F Window'
local alarm
local stext
stext = ""
alarm = "false"
commandArray = {}
if devicechanged[sensor1] == 'Open' then
alarm = "true"
stext = sensor1
print(sensor1 .. " Open")
end
if devicechanged[sensor2] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor2
print(sensor2 .. " Open")
end
if devicechanged[sensor3] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor3
print(sensor3 .. " Open")
end
if devicechanged[sensor4] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor4
print(sensor4 .. " Open")
end
if devicechanged[sensor5] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor5
print(sensor5 .. " Open")
end
if devicechanged[sensor6] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor6
print(sensor6 .. " Open")
end
if devicechanged[sensor7] == 'Open' then
alarm = true
stext = stext .. "-" .. sensor7
print(sensor7 .. " Open")
end
if alarm == 'false' then
commandArray['UpdateDevice'] = '1014|0|No Alert'
else
stext = "Alert-" .. stext
commandArray['UpdateDevice'] = '1014|4|'..stext
print("Alarm=" .. tostring(alarm))
end
return commandArray
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: LUA script in dir clogs up log
About the learning aspect... Not really !!gcaley wrote: ↑Monday 14 May 2018 0:07Ok thanks, I might try that. Yet another language to learn!waaren wrote:You could convert your script to dzVents Lua and let it trigger only on the relevant devices. It does take some reading but the wiki is excellent and conversion is relatively simple.
Sent from my iPhone using Tapatalk
From the dzVents wiki "And ... it is 100% Lua! So if you already have a bunch of event scripts for Domoticz, upgrading should be fairly easy."
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- jvdz
- Posts: 2330
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA script in dir clogs up log
No worries, I was just playing a little.

The thing to understand is that the eventsystem will run all script_device.xxxx.lua files each time when when any device is updated unless the "xxxxx"match a devicename, in which case only that specific device script is ran.
In your script you are having these lines:
Code: Select all
if alarm == 'false' then
commandArray['UpdateDevice'] = '1014|0|No Alert'
else
stext = "Alert-" .. stext
commandArray['UpdateDevice'] = '1014|4|'..stext
print("Alarm=" .. tostring(alarm))
end
My guess is you only want to apply that logic when the alarm text device need to change its text ...right?
Something like like this should avoid that and only update the text device when it needs changing:
Code: Select all
commandArray = {}
local sensor1 = 'Front Door LR'
local sensor2 = 'Rear Door LR'
local sensor3 = 'Kitchen Window'
local sensor4 = 'Dining L Window'
local sensor5 = 'Dining R Window'
local sensor6 = 'Lounge R Window'
local sensor7 = 'Lounge F Window'
local alarm = "false"
local stext = "No Alert"
commandArray = {}
if devicechanged[sensor1] == 'Open' then
alarm = "true"
stext = sensor1
print(sensor1 .. " Open")
end
if devicechanged[sensor2] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor2
print(sensor2 .. " Open")
end
if devicechanged[sensor3] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor3
print(sensor3 .. " Open")
end
if devicechanged[sensor4] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor4
print(sensor4 .. " Open")
end
if devicechanged[sensor5] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor5
print(sensor5 .. " Open")
end
if devicechanged[sensor6] == 'Open' then
alarm = "true"
stext = stext .. "-" .. sensor6
print(sensor6 .. " Open")
end
if devicechanged[sensor7] == 'Open' then
alarm = true
stext = stext .. "-" .. sensor7
print(sensor7 .. " Open")
end
-- only update Text device when text changed
if (otherdevices["Nane-of=Text-Device"] ~= stext) then
commandArray['UpdateDevice'] = '1014|4|'..stext
print("Alarm device updated to " .. tostring(alarm))
end
return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA script in dir clogs up log
Thanks for that. I’ll give it a try later on.jvdz wrote:No worries, I was just playing a little.
The thing to understand is that the eventsystem will run all script_device.xxxx.lua files each time when when any device is updated unless the "xxxxx"match a devicename, in which case only that specific device script is ran.
In your script you are having these lines:That means that with each device update in your setup you will always do an update for device 1014 and when the alarm == 'false' it will also print a line in the log each time the script is ran... which is endless as you case a device change each time.Code: Select all
if alarm == 'false' then commandArray['UpdateDevice'] = '1014|0|No Alert' else stext = "Alert-" .. stext commandArray['UpdateDevice'] = '1014|4|'..stext print("Alarm=" .. tostring(alarm)) end
My guess is you only want to apply that logic when the alarm text device need to change its text ...right?
Something like like this should avoid that and only update the text device when it needs changing:JosCode: Select all
commandArray = {} local sensor1 = 'Front Door LR' local sensor2 = 'Rear Door LR' local sensor3 = 'Kitchen Window' local sensor4 = 'Dining L Window' local sensor5 = 'Dining R Window' local sensor6 = 'Lounge R Window' local sensor7 = 'Lounge F Window' local alarm = "false" local stext = "No Alert" commandArray = {} if devicechanged[sensor1] == 'Open' then alarm = "true" stext = sensor1 print(sensor1 .. " Open") end if devicechanged[sensor2] == 'Open' then alarm = "true" stext = stext .. "-" .. sensor2 print(sensor2 .. " Open") end if devicechanged[sensor3] == 'Open' then alarm = "true" stext = stext .. "-" .. sensor3 print(sensor3 .. " Open") end if devicechanged[sensor4] == 'Open' then alarm = "true" stext = stext .. "-" .. sensor4 print(sensor4 .. " Open") end if devicechanged[sensor5] == 'Open' then alarm = "true" stext = stext .. "-" .. sensor5 print(sensor5 .. " Open") end if devicechanged[sensor6] == 'Open' then alarm = "true" stext = stext .. "-" .. sensor6 print(sensor6 .. " Open") end if devicechanged[sensor7] == 'Open' then alarm = true stext = stext .. "-" .. sensor7 print(sensor7 .. " Open") end -- only update Text device when text changed if (otherdevices["Nane-of=Text-Device"] ~= stext) then commandArray['UpdateDevice'] = '1014|4|'..stext print("Alarm device updated to " .. tostring(alarm)) end return commandArray
Sent from my iPhone using Tapatalk
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA script in dir clogs up log
Thanks for the previous help. I now just get a lot of the message below:
2018-05-15 13:06:07.131 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua
2018-05-15 13:06:09.818 (RXFCom 433) Temp + Humidity (Bathroom)
2018-05-15 13:06:09.833 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua
Which I guess means the device script is running every time any device changes (e.g. the temp devices). Is there a way to avoid this?
Thanks.
2018-05-15 13:06:07.131 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua
2018-05-15 13:06:09.818 (RXFCom 433) Temp + Humidity (Bathroom)
2018-05-15 13:06:09.833 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_test.lua
Which I guess means the device script is running every time any device changes (e.g. the temp devices). Is there a way to avoid this?
Thanks.
- jvdz
- Posts: 2330
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA script in dir clogs up log
That log entry can be disabled easily on regular use by simply going into the domoticz website, go into Setup/Settings and select the Other tab. Scroll down to the Event part and deselect the option "Log 'event script triggers"
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 6
- Joined: Monday 08 December 2014 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA script in dir clogs up log
Thanks, I’ll give that a go.jvdz wrote:That log entry can be disabled easily on regular use by simply going into the domoticz website, go into Setup/Settings and select the Other tab. Scroll down to the Event part and deselect the option "Log 'event script triggers"
Jos
Sent from my iPhone using Tapatalk
Who is online
Users browsing this forum: No registered users and 1 guest