Can anybody help me?

Moderator: leecollings

Post Reply
nalayh
Posts: 2
Joined: Wednesday 24 February 2016 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Can anybody help me?

Post by nalayh »

Hi, I need help with a simple lua script. I wan't to do a script that turn off all lights (scene) when I turn on Security panel (arm away) and turn on one light when I deactivated security panel.
The first works fine but when I turn off the security panel doesn't happen.

this is the script:

commandArray = {}

local encendido

if (otherdevices['Security Panel'] == 'Arm Away') then
commandArray['Scene:ApagarLuces'] = 'On'
encendido = "Off"
print ("encendido: " .. encendido)

elseif (encendido == "Off") and (otherdevices['Security Panel'] == 'Normal') then
commandArray['Hab3 - Luz'] = 'On'
encendido = "On"
print ("encendido: " .. encendido)

end

return commandArray

On the other hand, I wan't to turn off light once time but with this script don't let me turn on any light when panel security is Arm Away, automatically turn off light.

Thank you very much

Regards
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: Can anybody help me?

Post by jvdz »

Local variables aren't saved as the script's life ends when done so you can't test encendido in that way.
Just create a script called: script_security_panel-changes.lua looking something like this:

Code: Select all

commandArray = {}
--
printlog('###', 'SecPanel: status changed to ' .. globalvariables['Security'])
if globalvariables['Security'] == 'Disarmed' then
   commandArray['Hab3 - Luz'] = 'On'
elseif globalvariables['Security'] == 'Armed Home' then

elseif globalvariables['Security'] == 'Armed Away' then
     commandArray['Scene:ApagarLuces'] = 'On'
end

return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
nalayh
Posts: 2
Joined: Wednesday 24 February 2016 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Can anybody help me?

Post by nalayh »

Thank you very much, now I have this error:

script_security_panel-changes.lua:3: attempt to call global 'printlog' (a nil value)

If I comment printlog line, works fine.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Can anybody help me?

Post by dannybloe »

Change

Code: Select all

printlog
to

Code: Select all

print
.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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: Can anybody help me?

Post by jvdz »

Yea sorry, I use a standard library with some extra functions and printlog is one of them. :)
So changing it to print() should fix the error like dannybloe indicated.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
seansco
Posts: 19
Joined: Tuesday 01 March 2016 20:51
Target OS: Linux
Domoticz version:
Contact:

Re: Can anybody help me?

Post by seansco »

This puts my system into a endless loop.
jvdz wrote:Local variables aren't saved as the script's life ends when done so you can't test encendido in that way.
Just create a script called: script_security_panel-changes.lua looking something like this:

Code: Select all

commandArray = {}
--
printlog('###', 'SecPanel: status changed to ' .. globalvariables['Security'])
if globalvariables['Security'] == 'Disarmed' then
   commandArray['Hab3 - Luz'] = 'On'
elseif globalvariables['Security'] == 'Armed Home' then

elseif globalvariables['Security'] == 'Armed Away' then
     commandArray['Scene:ApagarLuces'] = 'On'
end

return commandArray
Jos
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: Can anybody help me?

Post by jvdz »

seansco wrote:This puts my system into a endless loop.
Doubt that my posted script makes an endless loop unless you have made modifications.

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

Who is online

Users browsing this forum: No registered users and 1 guest