Page 1 of 1

Cannot change Alarm state in LUA script

Posted: Thursday 08 February 2018 16:12
by SayHi
Hi All,

I made a dummy switch(name: SetSecurity) to toggle the alarm status. It triggers the LUA script, but it doesn't really work. It seems tot change the "otherdevices['Domoticz Security Panel'" to normal state, but will not set the status. It seems not to remember....
What am i doing wrong?

Tnx



commandArray = {}

print("______________________________________________________________")
print(otherdevices["Domoticz Security Panel"])

if (devicechanged['SetSecurity'] == 'On') then
print('Wanna arm:')
print(otherdevices["Domoticz Security Panel"])
otherdevices['Domoticz Security Panel'] = 'Arm Home'
print(otherdevices["Domoticz Security Panel"])

end
if (devicechanged['SetSecurity'] == 'Off') then
print('Wanna disarm:')
print(otherdevices["Domoticz Security Panel"])
otherdevices['Domoticz Security Panel'] = 'Normal'
print(otherdevices["Domoticz Security Panel"])
end
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
--Arm Home

return commandArray


2018-02-08 16:01:33.888 User: XXXXinitiated a switch command (1388/SetSecurity/Off)
2018-02-08 16:01:34.009 dzVents: Device based event fired on 'SetSecurity', value 'Off'
2018-02-08 16:01:34.019 dzVents: All based event fired
2018-02-08 16:01:34.025 dzVents: ______________________________________________________________
2018-02-08 16:01:34.025 dzVents: Arm Home
2018-02-08 16:01:34.025 dzVents: Wanna disarm:
2018-02-08 16:01:34.025 dzVents: Arm Home
2018-02-08 16:01:34.025 dzVents: Normal
2018-02-08 16:01:34.025 dzVents: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2018-02-08 16:01:34.026 (DummyHardware) Lighting 2 (SetSecurity)
2018-02-08 16:01:52.793 User: XXXXinitiated a switch command (1388/SetSecurity/On)
2018-02-08 16:01:52.907 dzVents: Device based event fired on 'SetSecurity', value 'On'
2018-02-08 16:01:52.917 dzVents: All based event fired
2018-02-08 16:01:52.924 dzVents: ______________________________________________________________
2018-02-08 16:01:52.924 dzVents: Arm Home
2018-02-08 16:01:52.924 dzVents: Wanna arm:
2018-02-08 16:01:52.924 dzVents: Arm Home
2018-02-08 16:01:52.924 dzVents: Arm Home
2018-02-08 16:01:52.924 dzVents: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2018-02-08 16:01:52.925 (DummyHardware) Lighting 2 (SetSecurity)
2018-02-08 16:02:00.506 dzVents: Time based event fired
2018-02-08 16:02:00.513 dzVents: All based event fired

https://snag.gy/dpIt7D.jpg

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 14:27
by SayHi
Did another try today, but did not succeed :oops: ... anybody?

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 14:28
by emme
it is NOT 'Normal'
it is 'Disarm'

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 15:54
by SayHi
Hi Emme,

Thank you for your reply.
Disarm isn't working either. The value of otherdevices["Domoticz Security Panel"] is "Normal" if i use the Panel with a code.
That's why I was using "Normal".

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 16:18
by SayHi
mmm, cannot insert image :oops:

Link image of different states of the varable:

https://pasteboard.co/H7LK93n.jpg

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 17:09
by emme
I'm quite sure it should be 'Disarm'
do Arm Home and Arm Away work as they are supposed to?
is the panel name correct?

Are you using a linux based hardware?

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 17:43
by jvdz
emme wrote: Thursday 15 February 2018 17:09 I'm quite sure it should be 'Disarm'
Correct! the command to get the state to Normal/DIsarmed is "Disarm".

Jos

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 18:02
by SayHi
I'm indeed on a Raspberry Pi. Does that make a difference?

The screenshot above is a when i Arm/disarm manualy with a code in de security panel.

But setting it to Disarm doesn't make a difference. It's like it doesn't rememeber it after I leave the Lua script

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 18:18
by emme
uh oh.... I think I got it!
print(otherdevices["Domoticz Security Panel"])
otherdevices['Domoticz Security Panel'] = 'Disarm'
print(otherdevices["Domoticz Security Panel"])

please note that the second print will STILL display Armed Home... the commandarray is executed at the end of the script so, you will see Armed Home, but if tyou check the log you should see Normal!!!

the script runs correctly (except tha tyou have to issue Disarm and not Normal) but you cannot get the right state

Re: Cannot change Alarm state in LUA script

Posted: Thursday 15 February 2018 18:22
by emme
this is the same script in dzVents

Code: Select all

return {
	on = {
		devices = { 'SetSecurity' },
	},
	logging = {
        level = domoticz.LOG_INFO,
        marker = '[SET SECURITY]'
        },
	execute = function(dz, device)
	    dz.log('______________________________________________________________')
	    local secPanel = dz.devices('Domoticz Security Panel')
        dz.log('Actual security State ==> '..secPanel.state)
        
        if device.state == 'On' and secPanel.state:gsub(1,3) ~= 'Arm' then
            dz.log('Wanna arm!')
            secPanel.armHome()
        elseif device.state == 'On' and secPanel.state:gsub(1,3) == 'Arm' then
            dz.log('Wanna Disarm!')
            secPanel.disarm()
        end 
        dz.log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
    end
}
I have only added a second check to arm/disarm only in case the system is not already armed/disarmed

Re: Cannot change Alarm state in LUA script

Posted: Sunday 18 February 2018 15:06
by SayHi
emme wrote: Thursday 15 February 2018 18:18 uh oh.... I think I got it!
print(otherdevices["Domoticz Security Panel"])
otherdevices['Domoticz Security Panel'] = 'Disarm'
print(otherdevices["Domoticz Security Panel"])

please note that the second print will STILL display Armed Home... the commandarray is executed at the end of the script so, you will see Armed Home, but if tyou check the log you should see Normal!!!

the script runs correctly (except tha tyou have to issue Disarm and not Normal) but you cannot get the right state
Thank you for thinking along with me!
But... the second print is displaying it correct:
2018-02-08 16:01:34.025 dzVents: Arm Home
2018-02-08 16:01:34.025 dzVents: Wanna disarm:
2018-02-08 16:01:34.025 dzVents: Arm Home
2018-02-08 16:01:34.025 dzVents: Normal
2018-02-08 16:01:34.025 dzVents: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

it display's "normal", but it seems not to remember the state.

Really don't understand... I will do a new install on another rasp....

Re: Cannot change Alarm state in LUA script

Posted: Sunday 18 February 2018 16:17
by SayHi
Yeah, got it....

ok here goes:

The status of "Security Panel" when disarmed is "Normal"

To change the state of Security Panel, set it to "Disarm"

I used otherdevices['Security Panel'] = 'Normal' and otherdevices['Security Panel'] = 'Disarm'
But they didn't work. Set the status with commandArray, not otherdevices

commandArray['Security Panel'] = 'Disarm' Works like a charm!