Page 1 of 2
DZvents and security
Posted: Monday 19 February 2024 11:40
by remko2000
When I switch my security panel to ' armed away' I want a dummy switch also switch ' on' and visa versa. I als want a mqtt message to switch a led.
I made this script but it doens't work the way I want.
Code: Select all
return
{ on = { security = { domoticz.SECURITY_DISARMED, domoticz.SECURITY_ARMEDAWAY } },
execute = function(domoticz, device)
if (device.state == 'SECURITY_ARMEDAWAY') then
domoticz.devices('Dummy Beveiliging').switchOn()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.name)
else
domoticz.devices('Dummy Beveiliging').switchOff()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.name)
end
end
}
If I now switch my security panel to ' armed away' it directly switch back to disarmed and if I switch 'Dummy Beveiliging' to ' on' it also directly switch back to off. What I'm doing wrong?
Re: DZvents and security
Posted: Monday 19 February 2024 13:19
by waltervl
Check this script for a reference:
https://www.domoticz.com/forum/viewtopic.php?t=40467
By the way, 'my security panel" is that an external hardware device or the build in Domoticz security panel? As the domoticz.SECURITY_DISARMED is based on the Domoticz security panel. see wiki
https://www.domoticz.com/wiki/Security#Security_Panel
Re: DZvents and security
Posted: Monday 19 February 2024 14:46
by remko2000
Yes it's buildin securitypanel.
I'm looking at this script
https://www.domoticz.com/forum/viewtopic.php?t=40467: but it's very advanced.
My script works, but it doesn't handle the statuses properly yet......
I've been trying for a while now, but unfortunately I haven't gotten any further
Re: DZvents and security
Posted: Monday 19 February 2024 15:10
by Kedi
It might be this line:
Code: Select all
if (device.state == 'SECURITY_ARMEDAWAY') then
Use this script to find the state name.
Code: Select all
return {
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
execute = function(domoticz, security, info)
domoticz.log('Security was triggered by ' .. security.trigger..' / '.. security.state, domoticz.LOG_INFO)
end
}
Re: DZvents and security
Posted: Monday 19 February 2024 15:32
by HvdW
I'd change the else into:
Code: Select all
if (device.state ~= 'SECURITY_ARMEDAWAY') then
and just use 'SECURITY_ARMEDAWAY' as trigger for the script.
Re: DZvents and security
Posted: Monday 19 February 2024 15:36
by remko2000
The statename gives:
2024-02-19 15:29:40.642 Status: dzVents: Info: ------ Start internal script: Script #1: Security: "Armed Away", trigger: "Armed Away"
2024-02-19 15:29:40.642 Status: dzVents: Info: Security was triggered by Armed Away / Armed Away
2024-02-19 15:29:40.642 Status: dzVents: Info: ------ Finished Script #1
(
If I change the script to:
Code: Select all
return
{ on = { security = { domoticz.SECURITY_DISARMED, domoticz.SECURITY_ARMED_AWAY } },
execute = function(domoticz, device)
if (device.state == 'SECURITY_ARMED_AWAY') then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.state)
else
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.state)
end
end
}
Still the same behaviour......is my if/else statement wrong?
Re: DZvents and security
Posted: Monday 19 February 2024 15:39
by Kedi
Instead of the 'SECURITY_ARMED_AWAY' use 'Armed Away'
Re: DZvents and security
Posted: Monday 19 February 2024 16:01
by remko2000
Code: Select all
return
{ on = { security = { domoticz.Disarmed, domoticz.Armed_Away } },
execute = function(domoticz, device)
if (device.state == 'Armed_Away') then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.state)
else
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.state)
end
end
}
I changed it but now I see nothing into my log.
Re: DZvents and security
Posted: Tuesday 20 February 2024 15:28
by Kedi
Replace the _ with a space. Ofcourse only on the right place.
Re: DZvents and security
Posted: Tuesday 20 February 2024 17:56
by remko2000
If I do that I get an error:
2024-02-20 17:55:27.692 Error: dzVents: Error: (3.1.8) error loading module 'testbeveil4' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/testbeveil4.lua':
2024-02-20 17:55:27.692 ...moticz/scripts/dzVents/generated_scripts/testbeveil4.lua:2: '}' expected near 'Away'
Code: Select all
return
{ on = { security = { domoticz.Disarmed, domoticz.Armed Away } },
execute = function(domoticz, device)
if (device.state == 'Armed Away') then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.state)
else
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.state)
end
end
}
Re: DZvents and security
Posted: Tuesday 20 February 2024 18:55
by pikassent
Hi,
Please, try:
Code: Select all
...
if (device.state == domoticz.SECURITY_ARMEDAWAY) then
...
Re: DZvents and security
Posted: Wednesday 21 February 2024 10:09
by Kedi
It should be
Code: Select all
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
and the 'if' should be
Code: Select all
execute = function(dz, security, info)
if security.isSecurity then
if domoticz.security == 'Armed Away' then
At least this works with me.
This is the example script from domoticz
Code: Select all
return {
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
execute = function(domoticz, security, info)
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
}
Re: DZvents and security
Posted: Wednesday 21 February 2024 15:12
by remko2000
THX, I try this:
Code: Select all
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
execute = function(dz, security, info)
if security.isSecurity then
if domoticz.security = 'Armed Away' then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
else
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
end
}
}
I get an error
2024-02-21 15:12:17.854 ...moticz/scripts/dzVents/generated_scripts/testbeveil4.lua:6: unexpected symbol near '='
Two times if...then, is that right?
Re: DZvents and security
Posted: Wednesday 21 February 2024 15:18
by HvdW
Of course. Adding a value to a variable is done with =
Comparing values is done with == , >=, <= and ~=
Re: DZvents and security
Posted: Wednesday 21 February 2024 19:46
by Kedi
And in your case change
Code: Select all
execute = function(dz, security, info)
in
Code: Select all
execute = function(domoticz, security, info)
Otherwise you will get the next error.
Perhaps invest some time in learning dzVents.
Re: DZvents and security
Posted: Wednesday 21 February 2024 19:52
by DewGew
Take a lock at my script. Alot of useful ideas.
https://github.com/DewGew/ideAlarm
Re: DZvents and security
Posted: Thursday 22 February 2024 15:23
by remko2000
I tried to adjust the script with al the suggestions. I tried to make the script as short and simple as possible
I now get rid of the error messages when I save the script but if I switch my security on (armed away) I get:
2024-02-22 15:22:03.581 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler testbeveil5
2024-02-22 15:22:03.581 Error: dzVents: Error: (3.1.8) ...moticz/scripts/dzVents/generated_scripts/testbeveil5.lua:6: attempt to index a nil value (global 'security')
Archhhh (I'm getting a little desperate)
Code: Select all
return {
on = {
security = { domoticz.SECURITY_DISARMED, domoticz.SECURITY_ARMEDAWAY }
},
execute = function(dz, item)
if security.state == domoticz.SECURITY_ARMEDAWAY then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
elseif security.state == domoticz.SECURITY_DISARMED then
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
end
}
All that needs to happen is that a dummy switches along with the security panel. So I only want to use armed away and disarmed.
Re: DZvents and security
Posted: Thursday 22 February 2024 15:40
by waltervl
change line
execute = function(dz, item)
in
execute = function(domoticz, item)
and
security.state=
in
item.state=
Re: DZvents and security
Posted: Friday 23 February 2024 16:15
by remko2000
that helps enormously. The script now works, but still gives an error and when I switch my alarm on, it seems to fluctuate between on/off for a few seconds before it actually switches. Quite special. What could this be?
This is my script so far:
Code: Select all
return {
on = {
security = { domoticz.SECURITY_DISARMED, domoticz.SECURITY_ARMEDAWAY }
},
execute = function(domoticz, item)
if item.state == domoticz.SECURITY_ARMEDAWAY then
domoticz.devices('Beveiliging buttonplus schakelen').switchOn()
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
elseif item.state == domoticz.SECURITY_DISARMED then
domoticz.devices('Beveiliging buttonplus schakelen').switchOff()
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
end
}
The error:
2024-02-23 16:14:22.284 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler testbeveil5
2024-02-23 16:14:22.284 Error: dzVents: Error: (3.1.8) ...moticz/scripts/dzVents/generated_scripts/testbeveil5.lua:11: attempt to index a nil value (global 'security')
Re: DZvents and security
Posted: Friday 23 February 2024 17:29
by waltervl
Let me give you a hint to debug this:
error: testbeveil5.lua:11: attempt to index a nil value (global 'security')
So in line 11 of your script the value of global (=attribute) 'security is nil ('=empty).
In line 11 you see the attribute security:
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
as 'security' is not defined in the top of your script it is of course empty.
What you probably want is the trigger which is 'part of the 'item' from statement 'execute = function(domoticz, item)'
So you have to change the 'security.trigger' statement into 'item.trigger'.
As you have them also in the other branch of the if statement you have to change this 2 times in your script!