Notification script  [Solved]

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

Moderator: leecollings

User avatar
madpatrick
Posts: 659
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Notification script

Post by madpatrick »

Hi,

I've rebuild this script for my purpose, but just need one additional functionality.
When i'm switch on the alarm mode i'm still standing in the room and of course the PIR will be activated.
Is it possible to have a delay to give time to leave the room without making any dummy switches ?

This is my script so far

Code: Select all

local scriptVar = '-=# inbraak #=-'

return {
	on = {
		devices = {
			'Sensor - Achterdeur',                     -- door contact in de woonkamer
			'Sensor - Garagedeur',                     -- door contact in de garage
			'PIR Sensor',                              -- PIR Sensor
		}
	},
	
	ustomEvents =
        {
            scriptVar,
        },

	logging =
    {
        level = domoticz.LOG_DEBUG, 
        marker = '-=# inbraak #=-',
    },
	
	execute = function(dz, item)
	    local Achterdeur = dz.devices('Sensor - Achterdeur')
	    local Garagedeur = dz.devices('Sensor - Garagedeur')
	    local PIR = dz.devices('PIR Sensor')
	    local alarmmode = dz.devices('Alarm mode')
	    local lamp = dz.groups('Woonkamer')  -- Alle lampen in woonkamer
	            local delay = 10
	    
		if (Achterdeur.state == 'On' or Garagedeur.state == 'On' or PIR.state == 'On' ) and alarmmode.state == 'On' then
		                    dz.emitEvent(scriptVar).afterSec(delay)
		    lamp.switchOn()
		    --dz.log('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.LOG_DEBUG)
		    dz.log(item.name .. ' Alarm switched On',dz.LOG_DEBUG)
		    dz.notify('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
		end
 
	end
}
}
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification script

Post by waaren »

madpatrick wrote: Saturday 24 October 2020 10:45 Is it possible to have a delay to give time to leave the room without making any dummy switches ?
A solution could look like

Code: Select all

local scriptVar = '-=# inbraak #=-'

return
{
    on =
    {
        devices =
        {
            'Sensor - Achterdeur',                     -- door contact in de woonkamer
            'Sensor - Garagedeur',                     -- door contact in de garage
            'PIR Sensor',                              -- PIR Sensor
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        local Achterdeur = dz.devices('Sensor - Achterdeur')
        local Garagedeur = dz.devices('Sensor - Garagedeur')
        local PIR = dz.devices('PIR Sensor')
        local alarmMode = dz.devices('Alarm mode')
        local lamp = dz.groups('Woonkamer')  -- Alle lampen in woonkamer
        local delay = 10

        if (Achterdeur.state == 'On' or Garagedeur.state == 'On' or PIR.state == 'On' ) and alarmMode.state == 'On' then
            if alarmMode.lastUpdate.secondsAgo > delay then
                lamp.switchOn()
                --dz.log('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.LOG_DEBUG)
                dz.log(item.name .. ' Alarm switched On',dz.LOG_DEBUG)
                dz.notify('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
            else
                dz.log(item.name .. ' was activated but ' .. alarmMode.name .. ' was activated only ' .. alarmMode.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
            end
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 659
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Notification script

Post by madpatrick »

Thanks Waaren !.

Is it possible to change the logging ?
Now everytime when the alarmmode is not switched on and you walk across the PIR, you will see a log entry.
This will grow to much and makes no sense.

LOG

Code: Select all

[code]2020-10-24 17:34:33.651 Status: dzVents: Debug: -=# inbraak #=-: Processing device-adapter for Sensor - Garagedeur: Switch device adapter
2020-10-24 17:34:33.651 Status: dzVents: Debug: -=# inbraak #=-: Processing device-adapter for Alarm mode: Switch device adapter
2020-10-24 17:34:33.652 Status: dzVents: Debug: -=# inbraak #=-: Processing device-adapter for Woonkamer: Group device adapter
2020-10-24 17:34:33.652 Status: dzVents: Info: -=# inbraak #=-: ------ Finished Burglar
2020-10-24 17:35:00.541 Status: LUA: (Buienradar) Get data from Buienradar
[/code]

I've changed:

Code: Select all

--    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = scriptVar,
    },
But this gives not logging at all when the alarm get's triggered.
for example this line

Code: Select all

dz.log(item.name .. ' Alarm switched On',dz.LOG_DEBUG)
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.14b on Tab8" =-
User avatar
madpatrick
Posts: 659
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Notification script

Post by madpatrick »

I've changed it to LOG_INFO and now I see the log lines in the log.
Only it woud be nice to see it only when the alarm mode is ON
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification script

Post by waaren »

madpatrick wrote: Saturday 24 October 2020 18:52 I've changed it to LOG_INFO and now I see the log lines in the log.
Only it woud be nice to see it only when the alarm mode is ON

Code: Select all

local scriptVar = '-=# inbraak #=-'

return
{
    on =
    {
        devices =
        {
            'Sensor - Achterdeur',                     -- door contact in de woonkamer
            'Sensor - Garagedeur',                     -- door contact in de garage
            'PIR Sensor',                              -- PIR Sensor
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = scriptVar,
    },

    execute = function(dz, item)
        local Achterdeur = dz.devices('Sensor - Achterdeur')
        local Garagedeur = dz.devices('Sensor - Garagedeur')
        local PIR = dz.devices('PIR Sensor')
        local alarmMode = dz.devices('Alarm mode')
        local lamp = dz.groups('Woonkamer')  -- Alle lampen in woonkamer
        local delay = 10

        if alarmMode.state == 'On' then
            dz.log('alarmMode geactiveerd',dz.LOG_FORCE)
        end
        
        if (Achterdeur.state == 'On' or Garagedeur.state == 'On' or PIR.state == 'On' ) and alarmMode.state == 'On' then
            if alarmMode.lastUpdate.secondsAgo > delay then
                lamp.switchOn()
                --dz.log('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.LOG_FORCE)
                dz.log(item.name .. ' Alarm switched On',dz.FORCE)
                dz.notify('Inbraak (thuis)!!',item.name .. ' geactiveerd',dz.PRIORITY_HIGH)
            else
                dz.log(item.name .. ' was activated but ' .. alarmMode.name .. ' was activated only ' .. alarmMode.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
            end
        end
    end
}
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: Notification script

Post by Jan Jansen »

@Waaren,

Thanks for your support, it works as desired.
User avatar
madpatrick
Posts: 659
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Notification script

Post by madpatrick »

Hi,
I have the script running, but i like make the notification samrter when a doorsensor is activate.
Currently I've a message on my screen when a door is openend and also indicating which one.
I'm extenting the amount of doorsensors, so maybe it is easier to hanle the messaging and combined it in the script ?

Image

I've activating the message in custom.js and custom.css, but need to make a seperate message block for each sensor.
Now only 2 sensors, but will extend to 4-5 pcs

custom.js

Code: Select all

function handleMessage() {
   if (trigger_182 && trigger_188)
        Dashticz.setBlock('emptyblock1', { addClass: 'message4' });
   else if (trigger_182)
        Dashticz.setBlock('emptyblock1', { addClass: 'message2' });
   else if (trigger_188)
        Dashticz.setBlock('emptyblock1', { addClass: 'message3' });
   else
        Dashticz.setBlock('emptyblock1', { addClass: '' });
}
custom.css

Code: Select all

.warning2 {
  	visibility: visible;
}
.warning2:before {
  	content: "Alarm Activated";
	background: rgba(255,0,0,0.6) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
	font-size: 20px !important;
	visibility: visible;
	position: absolute;
	top: 15px;
	right: 15px;
	width: 200px;
	padding: 10px;
	text-align : center;
}

.message1 {
	background: rgba(255,255,0,0.3) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
}

.message2 {
  	visibility: visible;
}
.message2:before {
  	content: "Deur Erker Open";
	background: rgba(255,255,0,0.3) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
	font-size: 20px !important;
	visibility: visible;
	position: absolute;
	top: 15px;
	left: 15px;
	width: 200px;
	padding: 10px;
	text-align : center;
}

.message3 {
  	visibility: visible;
}
.message3:before {
  	content: "Deur Garage Open";
	background: rgba(255,255,0,0.3) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
	font-size: 20px !important;
	visibility: visible;
	position: absolute;
	top: 15px;
	left: 15px;
	width: 200px;
	padding: 10px;
	text-align : center;
}

.message4 {
  	visibility: visible;
}
.message4:before {
  	content: "Deur Erker en Garage Open";
	background: rgba(255,255,0,0.3) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
	font-size: 20px !important;
	visibility: visible;
	position: absolute;
	top: 15px;
	left: 15px;
	width: 200px;
	padding: 10px;
	text-align : center;
Is it possible to generate 1 block which will display the name of the sensor(s) ?
I believe the text is possible to generate for a variable : content : var(--name type-or-unit)
Or something like this
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.14b on Tab8" =-
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests