What is the cause of this error? Topic is solved

Moderator: leecollings

Post Reply
Masterscot
Posts: 12
Joined: Tuesday 29 January 2019 10:39
Target OS: Linux
Domoticz version:
Contact:

What is the cause of this error?

Post 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
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: What is the cause of this error?

Post 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.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: What is the cause of this error?

Post 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. :)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Masterscot
Posts: 12
Joined: Tuesday 29 January 2019 10:39
Target OS: Linux
Domoticz version:
Contact:

Re: What is the cause of this error?

Post 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.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: What is the cause of this error?

Post 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.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: What is the cause of this error?

Post 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!
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Masterscot
Posts: 12
Joined: Tuesday 29 January 2019 10:39
Target OS: Linux
Domoticz version:
Contact:

Re: What is the cause of this error?

Post by Masterscot »

Ah, I understand now.
Changed the option to 'device' and that fixed it. No more errors in the log.
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest