Convert 3 blockly scripts to 1 DZVents script  [Solved]

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

Moderator: leecollings

Post Reply
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Convert 3 blockly scripts to 1 DZVents script

Post by Jan Jansen »

The DZVents script looks like:

Code: Select all

return {
	on = {
		devices = {
			'Beveiliging',						-- dummy selector
			'Taglezer keuken',					-- dummy
			'Voordeur',						-- door sensor
			'Slaapkamer (voorzijde)',				-- door sensor
			'Woonkamer (voorzijde)',				-- door sensor
			'Keukendeur',						-- door sensor
			'Schuurdeur',						-- door sensor
		}
	},
	
	logging =
    {
        level = domoticz.LOG_ERROR, -- change to domoticz.LOG_DEBUG when somesthing is wrong
        marker = 'beveiliging',
    },
	
	execute = function(dz, item)
		local bev = dz.devices('Beveiliging')
		local tagkkn = dz.devices('Taglezer keuken')
		local aan = dz.devices('Beveiliging aan (led rood)')
		local uit = dz.devices('Beveiliging uit (led groen)')
		local buzkkn = dz.devices('Beveiliging buzzer keuken')
		local vd = dz.devices('Voordeur')
		local slpkmrvz = dz.devices('Slaapkamer (voorzijde)') 
		local wkvz = dz.devices('Woonkamer (voorzijde)')
		local kkn = dz.devices('Keukendeur')
		local schuur = dz.devices('Schuurdeur')
		local asinb = dz.devices('Alarmsignaal inbraak')
		local delay = 30					-- entry delay
		
		if bev.state == 'Thuis' then
		    dz.log('alarmMode "Thuis" geactiveerd',dz.LOG_FORCE)
		    aan.switchOn()
		    uit.switchOff()
		end
		if bev.state == 'Afwezig' then
		    dz.log('alarmMode "Afwezig" geactiveerd',dz.LOG_FORCE)
		    aan.switchOn().afterSec(30)		-- exit delay
		    uit.switchOff()
	    end
		if bev.state == 'Afwezig+' then
		    dz.log('alarmMode "Afwezig+" geactiveerd',dz.LOG_FORCE)
		    aan.switchOn().afterSec(30)		-- exit delay
		    uit.switchOff()
		end    
		if tagkkn == 'On' and bev.state ~= 'Uit' then
		    bev.switchSelector('Uit')
		end    
		if bev.state == 'Uit' then
		   dz.log('alarmMode "Uit" geactiveerd',dz.LOG_FORCE)
		   aan.switchOff()
		   uit.switchOn()
		   asinb.switchOff()
		   buzkkn.switchOff()
		end
		if (bev.state == 'Afwezig' or bev.state == 'Afwezig+') and (vd.state == 'On' or slpkmrvz.state == 'On' or wkvz.state == 'On') then
		    buzkkn.switchOn()   	-- All closed??
		end
		if bev.state == 'Thuis' and (vd.state == 'On' or slpkmrvz.state == 'On' or wkvz.state == 'On' or kkn.state == 'On' or schuur.state == 'On') then
		    dz.log('Inbraak!!! alarmMode "Thuis" geactiveerd',dz.LOG_FORCE)
		    dz.notify('Inbraak (thuis)',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
		    asinb.switchOn()
		end
	    if (bev.state == 'Afwezig' or bev.state == 'Afwezig+') and aan.state == 'On' and (vd.state == 'On' or slpkmrvz.state == 'On' or wkvz.state == 'On' or kkn.state == 'On' or schuur.state == 'On') then
		    buzkkn.switchOn()
		    if kkn.lastUpdate.secondsAgo > delay then
		    dz.log('Inbraak!!! alarmMode "Afwezig" geactiveerd',dz.LOG_FORCE)
		    dz.notify('Inbraak (Afwezig)',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
		    asinb.switchOn()
		    end
		end
		if bev.state == 'Uit' and asinb.state == 'On' then
		    asinb.switchOff()
		    dz.notify('Reset alarm','Alarminstallatie gereset',dz.PRIORITY_HIGH)
		end
	end
}
Maybe I want to cram too much into 1 script. The advantage is that 3 dummys can expire. Perhaps it can all be done much more efficiently. Suggestions are welcome.
Most of the script works as desired. There are 2 problems that I can't solve myself.
First:

Code: Select all

if tagkkn == 'On' and bev.state ~= 'Uit' then
		    bev.switchSelector('Uit')
This part does not work. When the Tag reader kitchen is activated, the selector switch does not respond. I tried bev.levelName instead of bev.state, no success.

Second:

Code: Select all

if (bev.state == 'Afwezig' or bev.state == 'Afwezig+') and aan.state == 'On' and (vd.state == 'On' or slpkmrvz.state == 'On' or wkvz.state == 'On' or kkn.state == 'On' or schuur.state == 'On') then
		    buzkkn.switchOn()
		    if kkn.lastUpdate.secondsAgo > delay then
		    dz.log('Inbraak!!! alarmMode "Afwezig" geactiveerd',dz.LOG_FORCE)
		    dz.notify('Inbraak (Afwezig)',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
		    asinb.switchOn()
		    end
		end
When the alarm is switched on and after activation of a door sensor, the buzzer is activated (desired). It is also desirable that the 2nd part is activated after 30 seconds. However, that does not happen.

Thanks in advance!
Jan
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Convert 3 blockly scripts to 1 DZVents script

Post by waaren »

Jan Jansen wrote: Monday 26 October 2020 20:25

Code: Select all

		if tagkkn == 'On' and bev.state ~= 'Uit' then
You probably want

Code: Select all

		if tagkkn.state == 'On' and bev.levelName ~= 'Uit' then
I don't understand what you try to do in the part with the second issue.

If you are debugging it helps to set level of logging to domoticz.LOG_DEBUG and add some dz.log('blabla I am here',dz.LOG_DEBUG) lines in those areas of the script that you want to investigate.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Convert 3 blockly scripts to 1 DZVents script [SOLVED]  [Solved]

Post by Jan Jansen »

@ waaren,

I have been staring too long at the 1st issue. I solved the second problem with an extra dummy.

Thanks for your support!

Regards
Jan
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest