bug in Security panel or error in my script normally the last  [Solved]

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

bug in Security panel or error in my script normally the last

Post by pvklink »

I want to take action based on the state/change of the Security Panel.
When i try to read the value of item.name i get an error.

error
2021-02-13 13:18:16.925 Error: dzVents: Error: (3.1.4) An error occurred when calling event handler DZ_security_panel
2021-02-13 13:18:16.925 Error: dzVents: Error: (3.1.4) .../scripts/dzVents/generated_scripts/DZ_security_panel.lua:23: attempt to concatenate a nil value (field 'name')

script

Code: Select all

-- dit script alleen bij handmatige device acties bij 
    -- AB (alarm scripts aanroepen, zit allemaal in alarm script
    -- handmatige acties op het software Panel, deze heeft zelf al een uitloop vertraging en beeps alleen thuis wordt niet aan/uit gezet
    
local Panelname = 'Domoticz Security Panel'
return {
    on = {  devices = {Panelname,'$remote_arm*','$remote_disarm*'},
        },
        
    execute = function(dz,item,info)
    _G.logLevel = dz.helpers.get_logtype(dz)    -- dz.log('debug test',dz.LOG_DEBUG) this will only make it to the log when LOG_DEBUG is set  AND dz.log('blabla',dz.LOG_FORCE) -- this will allways make it tp the log
    _G.logMarker = _G.moduleLabel                   -- marker wordt scriptnaam
    local messageTable = {}
    -- HIER START DE EXECUTIE

    local securityPanel = dz.devices(1728)          -- security panel
    local Notify = true                             -- wel/niet notify naar ontvangers bij een alarm
    local Notifiers = 'pvkmobiel,redminote7_mvk'    -- ontvanger van een pushbericht
    --local Notifiers = 'pvkmobiel'                   -- ontvanger van een pushbericht
    local Durtimer_inloop = 25                      -- na hoeveel seconden moet de knop worden uitgezet

    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 1:',10)   
    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 2:' .. 'Item:' .. item.name .. ' State:' .. item.state,10)   --secpanel:' .. securityPanel.state .. ' cfg'

--[[



    if item.name == Panelname then  -- alleen handmatige acties op paneel

        if (item.state == 'Armed Away') then
            
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 3:',10)   --secpanel:' .. securityPanel.state .. ' cfg'

            dz.devices('Alarm').switchSelector('Arm_away')



            --dz.devices('Thuis').switchOff().afterSec(Durtimer_inloop)

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: ARMED AWAY...',10) 
            --if Notify   then dz.notify('HUISALARM: is AAN:AWAY','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER) end    -- dz.PRIORITY_LOW, dz.PRIORITY_MODERATE, dz.PRIORITY_NORMAL, dz.PRIORITY_HIGH, dz.PRIORITY_EMERGENCY

        elseif (item.state == 'Armed Home') then
            dz.devices('Alarm').switchSelector('Arm_home')

            --dz.devices('Thuis').switchOn()

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: ARMED HOME...',10) 
            --if Notify   then dz.notify('HUISALARM: is AAN:HOME','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER)    end

        elseif (item.state == 'Disarmed') then
            dz.devices('Alarm').switchSelector('Disarm')

            --dz.devices('Thuis').switchOn()

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: DISARMED...',10) 
            --if Notify   then dz.notify('HUISALARM: is UIT','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER)     end

        else
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: Onbekende status...',30) 

        end

    elseif (dz.helpers.matchesWildCardedString(dz,item.name, '$remote_arm*')) and (item.lastUpdate.secondsAgo > 8) then -- was <8
        if dz.devices('Alarm_cfg').state ~= 'uit' then  
            dz.devices('Alarm').switchSelector('Arm_away')    -- speelt alleen geluid af in node-red is nieuw moet aangezet worden omdat armaway geen geluid aanzet of te laat
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' ARM geactiveerd...',10) 

        else
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' ARM niet geactiveerd, ALARM CFG staat OFF...',10) 
        end

    elseif (dz.helpers.matchesWildCardedString(dz,item.name, '$remote_disarm*')) and (item.lastUpdate.secondsAgo > 8) then -- was <8 
        dz.devices('Alarm').switchSelector('Disarm')
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' DISARM geactiveerd...',10) 
        
    end
 ]]--
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: bug in Security panel or error in my script normally the last

Post by waaren »

pvklink wrote: Saturday 13 February 2021 13:24 I want to take action based on the state/change of the Security Panel.
When i try to read the value of item.name i get an error.
To locate where the error occcurs can you change

Code: Select all

	execute = function(dz,item,info)

to

Code: Select all

logging = 
	{
		level = domoticz.LOG_DEBUG,
		marker = 'Check item',
	},
	
	execute = function(dz,item,info)
	
	dz.log(item, dz.LOG_DEBUG)

and check again?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: bug in Security panel or error in my script normally the last

Post by pvklink »

i know which part gives the error...
When the security panels changes it activates this script/
This scripts handles more than this security panel devices so i use item.name to check which device changes...

It seems that when security panel activates this script it does not have the property item.name!

I did a test by splitting this script, a script for each device so dont have to use the item.name for my securitypanel, but strange it is!
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: bug in Security panel or error in my script normally the last

Post by pvklink »

I split my script, so it reacts one device, in this case the securitypanel.
I turned debug on and yes, it cant handle item.name!
this line
dz.log('testpvk' .. item.name, dz.LOG_DEBUG)
gives this error

2021-02-13 15:17:20.968 Status: dzVents: Info: Handling events for: "Domoticz Security Panel", value: "Disarmed"
2021-02-13 15:17:20.968 Status: dzVents: Info: ------ Start internal script: DZ_alarm_security_panel: Security: "Domoticz Security Panel"
2021-02-13 15:17:20.969 Status: dzVents: Info: ------ Finished DZ_alarm_security_panel
2021-02-13 15:17:20.969 Error: dzVents: Error: (3.1.4) An error occurred when calling event handler DZ_alarm_security_panel
2021-02-13 15:17:20.969 Error: dzVents: Error: (3.1.4) ...ts/dzVents/generated_scripts/DZ_alarm_security_panel.lua:15: attempt to concatenate a nil value (field 'name')

Dont know this is a bug, i suggested that each device gives an item.name

Code: Select all

-- dit script alleen bij handmatige device acties bij het software Panel, deze heeft zelf al een uitloop vertraging en beeps alleen thuis wordt niet aan/uit gezet
-- security panel device werkt niet met item.name or item.state, daarom in een eigen script gezet

local Panelname = 'Domoticz Security Panel'
return {
    on = {  devices = {Panelname},
        },
        
    execute = function(dz,item,info)
    _G.logLevel = dz.helpers.get_logtype(dz)    -- dz.log('debug test',dz.LOG_DEBUG) this will only make it to the log when LOG_DEBUG is set  AND dz.log('blabla',dz.LOG_FORCE) -- this will allways make it tp the log
    _G.logMarker = _G.moduleLabel                   -- marker wordt scriptnaam
    local messageTable = {}
    -- HIER START DE EXECUTIE

dz.log('testpvk' .. item.name, dz.LOG_DEBUG)

    local securityPanel = dz.devices(1728)          -- security panel
    local Notify = true                             -- wel/niet notify naar ontvangers bij een alarm
    local Notifiers = 'pvkmobiel,redminote7_mvk'    -- ontvanger van een pushbericht
    --local Notifiers = 'pvkmobiel'                   -- ontvanger van een pushbericht

    if (securityPanel.state == 'Armed Away') then
        dz.devices('Alarm').switchSelector('Arm_away')

    elseif (securityPanel.state == 'Armed Home') then
        dz.devices('Alarm').switchSelector('Arm_home')

    elseif (securityPanel.state == 'Disarmed') then
        dz.devices('Alarm').switchSelector('Disarm')

    else
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: Onbekende status...',30) 

    end

    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: bug in Security panel or error in my script normally the last

Post by waaren »

pvklink wrote: Saturday 13 February 2021 15:02 i know which part gives the error...
It might be known to you but it is not so obvious to me.
I assume you post this on the forum to ask if someone can help to determine if it is an issue in your script or something else. I am happy to do that but to give the right answers it helps if you share what you see in the log when adding the lines I posted earlier.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: bug in Security panel or error in my script normally the last

Post by pvklink »

ok, excuses!

Here the original script with the debug options you suggested

Code: Select all

-- dit script alleen bij handmatige device acties bij 
    -- AB (alarm scripts aanroepen, zit allemaal in alarm script
    -- handmatige acties op het software Panel, deze heeft zelf al een uitloop vertraging en beeps alleen thuis wordt niet aan/uit gezet
    
local Panelname = 'Domoticz Security Panel'
return {
    on = {  devices = {Panelname,'$remote_arm*','$remote_disarm*'},
        },
        
    logging = 
	{
		level = domoticz.LOG_DEBUG,
		marker = 'Check item',
	},
	
	execute = function(dz,item,info)
	
	dz.log(item, dz.LOG_DEBUG)
    _G.logLevel = dz.helpers.get_logtype(dz)    -- dz.log('debug test',dz.LOG_DEBUG) this will only make it to the log when LOG_DEBUG is set  AND dz.log('blabla',dz.LOG_FORCE) -- this will allways make it tp the log
    _G.logMarker = _G.moduleLabel                   -- marker wordt scriptnaam
    local messageTable = {}
    -- HIER START DE EXECUTIE

    local securityPanel = dz.devices(1728)          -- security panel
    local Notify = true                             -- wel/niet notify naar ontvangers bij een alarm
    local Notifiers = 'pvkmobiel,redminote7_mvk'    -- ontvanger van een pushbericht
    --local Notifiers = 'pvkmobiel'                   -- ontvanger van een pushbericht
    local Durtimer_inloop = 25                      -- na hoeveel seconden moet de knop worden uitgezet

    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 1:',10)   
    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 2:' .. 'Item:' .. item.name .. ' State:' .. item.state,10)   --secpanel:' .. securityPanel.state .. ' cfg'

--[[



    if item.name == Panelname then  -- alleen handmatige acties op paneel

        if (item.state == 'Armed Away') then
            
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', 'CHECKPOINT: 3:',10)   --secpanel:' .. securityPanel.state .. ' cfg'

            dz.devices('Alarm').switchSelector('Arm_away')



            --dz.devices('Thuis').switchOff().afterSec(Durtimer_inloop)

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: ARMED AWAY...',10) 
            --if Notify   then dz.notify('HUISALARM: is AAN:AWAY','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER) end    -- dz.PRIORITY_LOW, dz.PRIORITY_MODERATE, dz.PRIORITY_NORMAL, dz.PRIORITY_HIGH, dz.PRIORITY_EMERGENCY

        elseif (item.state == 'Armed Home') then
            dz.devices('Alarm').switchSelector('Arm_home')

            --dz.devices('Thuis').switchOn()

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: ARMED HOME...',10) 
            --if Notify   then dz.notify('HUISALARM: is AAN:HOME','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER)    end

        elseif (item.state == 'Disarmed') then
            dz.devices('Alarm').switchSelector('Disarm')

            --dz.devices('Thuis').switchOn()

            --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: DISARMED...',10) 
            --if Notify   then dz.notify('HUISALARM: is UIT','HUISALARM_CENTRALE',dz.PRIORITY_HIGH,'',Notifiers,dz.NSS_PUSHOVER)     end

        else
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' HOME SECURITY: Onbekende status...',30) 

        end

    elseif (dz.helpers.matchesWildCardedString(dz,item.name, '$remote_arm*')) and (item.lastUpdate.secondsAgo > 8) then -- was <8
        if dz.devices('Alarm_cfg').state ~= 'uit' then  
            dz.devices('Alarm').switchSelector('Arm_away')    -- speelt alleen geluid af in node-red is nieuw moet aangezet worden omdat armaway geen geluid aanzet of te laat
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' ARM geactiveerd...',10) 

        else
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' ARM niet geactiveerd, ALARM CFG staat OFF...',10) 
        end

    elseif (dz.helpers.matchesWildCardedString(dz,item.name, '$remote_disarm*')) and (item.lastUpdate.secondsAgo > 8) then -- was <8 
        dz.devices('Alarm').switchSelector('Disarm')
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AFSTANDSBEDIENING: ' .. item.name .. ' DISARM geactiveerd...',10) 
        
    end
 ]]--
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

end
}

The errors: ( i get these when i disarm the security panel on the gui/userinterface)

Code: Select all

 2021-02-13 20:39:49.910 Status: dzVents: Info: Handling events for: "Domoticz Security Panel", value: "Armed Away"
2021-02-13 20:39:49.911 Status: dzVents: Info: Check item: ------ Start internal script: Bug_secpanel: Security: "Domoticz Security Panel"
2021-02-13 20:39:49.911 Status: dzVents: Debug: Check item: {["isTimer"]=false, ["state"]="Armed Away", ["dump"]=function, ["isSystem"]=false, ["isDevice"]=false, ["isGroup"]=false, ["isShellCommandResponse"]=false, ["isHTTPResponse"]=false, ["isCustomEvent"]=false, ["isHardware"]=false, ["baseType"]="security", ["isSecurity"]=true, ["isScene"]=false, ["isVariable"]=false}
2021-02-13 20:39:49.912 Status: dzVents: Debug: Check item: Processing device-adapter for logtype: Switch device adapter
2021-02-13 20:39:49.912 Status: dzVents: Info: ------ Finished Bug_secpanel
2021-02-13 20:39:49.912 Error: dzVents: Error: (3.1.4) An error occurred when calling event handler Bug_secpanel
2021-02-13 20:39:49.912 Error: dzVents: Error: (3.1.4) ...oticz/scripts/dzVents/generated_scripts/Bug_secpanel.lua:31: attempt to concatenate a nil value (field 'name') 
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: bug in Security panel or error in my script normally the last  [Solved]

Post by waaren »

pvklink wrote: Saturday 13 February 2021 20:42 Here the original script with the debug options you suggested
OK. That explains why you get this error.

Code: Select all

["isDevice"]=false, 
["isSecurity"]=true, ["state"]="Armed Away", 
The script is triggered because you entered the name of the security panel in the devices = section but when dzVents process it, it does recognize it is in fact a security object and do not pass the device attributes in the 2nd parm of the execute function.

dzVents does have a separate on = security section for this object-type.

Code: Select all

on =
        security =
        {
            domoticz.SECURITY_ARMEDAWAY,
            domoticz.SECURITY_ARMEDHOME,
            domoticz.SECURITY_DISARMED,
        },
    
If you really must have the device attributes of the security panel in item
(Plese note you already have them in the table securityPanel) you could do something like

Code: Select all

    execute = function(dz,item,info)

        dz.log(item, dz.LOG_DEBUG)
    
        local securityObject = item
        local item = dz.devices(1728)
    
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: bug in Security panel or error in my script normally the last

Post by pvklink »

ahh, learned again!
No i want to use domoticz/dzvents the proper way, so i will the play with security options and change all my scripts where i use security options...
thanks again!

I do have another strange thing with a selector switch, that loses events, a new post?
It s more a general question ...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: bug in Security panel or error in my script normally the last

Post by waaren »

pvklink wrote: Saturday 13 February 2021 22:13 I do have another strange thing with a selector switch, that loses events, a new post?
It s more a general question ...
Yes best to do this in separate topic.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: bug in Security panel or error in my script normally the last

Post by pvklink »

with the suggested on security, i can deleted this script with the error ! :-)
Case closed and learned again...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest