DZvents and security

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

DZvents and security

Post 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?
User avatar
waltervl
Posts: 5735
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: DZvents and security

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post by remko2000 »

Yes it's buildin securitypanel.

I'm looking at this scripthttps://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
Kedi
Posts: 569
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: DZvents and security

Post 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
}

Logic will get you from A to B. Imagination will take you everywhere.
HvdW
Posts: 599
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: DZvents and security

Post 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.
Bugs bug me.
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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?
Kedi
Posts: 569
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: DZvents and security

Post by Kedi »

Instead of the 'SECURITY_ARMED_AWAY' use 'Armed Away'
Logic will get you from A to B. Imagination will take you everywhere.
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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.
Kedi
Posts: 569
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: DZvents and security

Post by Kedi »

Replace the _ with a space. Ofcourse only on the right place.
Logic will get you from A to B. Imagination will take you everywhere.
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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
}
pikassent
Posts: 16
Joined: Saturday 03 December 2022 16:26
Target OS: Linux
Domoticz version: 2024.4b
Location: Spain
Contact:

Re: DZvents and security

Post by pikassent »

Hi,

Please, try:

Code: Select all

...
if (device.state == domoticz.SECURITY_ARMEDAWAY) then
...
Kedi
Posts: 569
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: DZvents and security

Post 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
}


Logic will get you from A to B. Imagination will take you everywhere.
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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?
HvdW
Posts: 599
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: DZvents and security

Post by HvdW »

Of course. Adding a value to a variable is done with =
Comparing values is done with == , >=, <= and ~=
Bugs bug me.
Kedi
Posts: 569
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: DZvents and security

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: DZvents and security

Post by DewGew »

Take a lock at my script. Alot of useful ideas.
https://github.com/DewGew/ideAlarm
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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.
User avatar
waltervl
Posts: 5735
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: DZvents and security

Post by waltervl »

change line
execute = function(dz, item)
in
execute = function(domoticz, item)

and
security.state=
in
item.state=
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: DZvents and security

Post 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')
User avatar
waltervl
Posts: 5735
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: DZvents and security

Post 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!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest