Page 1 of 1

What is the cause of this error?

Posted: Thursday 20 January 2022 18:54
by Masterscot
Lua newbie here.
The script works but generates every minute an error in the log. Not sure why.

This error:
2022-01-20 18:45:00.931 Error: EventSystem: in Achterdeurbel_trigger: [string "-- ..."]:8: attempt to index a nil value (global 'devicechanged')

Is generated bij this script:
--
-- Script Achterdeurbel
-- Start shellscript bij het activeren van de achterdeurdeurbel voor het afspelen van geluid op squeezebox spelers
--

commandArray = {}

if (devicechanged['Deurbelknop_achter'] == 'On') then
if (otherdevices['Silence'] == 'Off') then
print("** Deurbel achterdeur geactiveerd **")
os.execute('/home/vincent/domoticz/scripts/sqalert.sh "kitchen" Ding-dong.mp3 Deurbel_achterdeur.mp3 40')
os.execute('/home/vincent/domoticz/scripts/sqalert.sh "bathroom" Ding-dong.mp3 Deurbel_achterdeur.mp3 40')
os.execute('/home/vincent/domoticz/scripts/sqalert.sh "livingroom" Ding-dong.mp3 Deurbel_achterdeur.mp3 40')
end
end

return commandArray

Re: What is the cause of this error?

Posted: Friday 21 January 2022 8:51
by jannl
I guess this is a time script? Since it produces an error every minute?

You are sure the name 'Deurbelknop_achter' is exactly the same?

Remember that if in lua every script has a commandArray, it gets very slow. Better is to create a sort of container script that calls the seperate scripts or use dzVents, which in a way does that for you. But this is not what causes your problem.

Re: What is the cause of this error?

Posted: Friday 21 January 2022 10:20
by jvdz
As @jannl states, just change the TRIGGER option to Device in stead of ALL as that will also run on Time events and that doesn't contain the devicechanged array for obvious reasons. :)

Re: What is the cause of this error?

Posted: Friday 21 January 2022 11:28
by Masterscot
Thanks for your reaction.
That's the funny thing. The error is seen every minute in the log, but the script only runs when the Door bell (Deurbelknop_achter) is pushed. The second device (Silence) is a 'normal' toggle switch in Domoticz, which prevents the os.execute script to run at times when everything should be quiet.
@jvdz, I do not understand exactly what you propose. Can you be a little more specific?
Again thanks and sorry for my noobness.

Re: What is the cause of this error?

Posted: Friday 21 January 2022 11:53
by jannl
How do you know the script only runs when the doorbell is pushed?
Put a print statement in front of the first 'if' to check this

The error messages suggests otherwise.

Re: What is the cause of this error?

Posted: Friday 21 January 2022 12:14
by jvdz
Masterscot wrote: Friday 21 January 2022 11:28 @jvdz, I do not understand exactly what you propose. Can you be a little more specific?
Again thanks and sorry for my noobness.
Did you create the script in the internal Event Editor? There you have this option at the right top!

Re: What is the cause of this error?

Posted: Friday 21 January 2022 14:54
by Masterscot
Ah, I understand now.
Changed the option to 'device' and that fixed it. No more errors in the log.
Thanks!