In addition and to be complete for the script, I want to get notified on my phone as well. For this i was thinking of sending me an e-mail, else it makes no sense to blink the lights

So this script is a kind of mini alarm, but suggestions are welcome to improve.
So far nothing special i assume, besides the fact that im just a beginner with dzEvents and still learning. I made a start, with help of other scripts on this forum, but it still doesn't do what i needs to do.. and I hope that someone can help me out on this.
In the past I normally worked with Blockly for all of my scripts and i'm known to Domoticz for several years, so i'm not a total noob. For that moment Blockly was sufficient but now I also want to make me more comfortable with dzEvents.
I'm using the following sensors:
- Door sensor - Doorsensor13
- Phone status (based on Wifi ping) - Phone1
- Phone status (based on Wifi ping) - Phone2
- Lamp1 - YeeLight_Roomname1
- Lamp2 - YeeLight_Roomname2
- Dummy Switch (details below) - Dummy
Code: Select all
If
Doorsensor = Open and Phone1 = off and Phone2 = off
Do
Write to log "Door open"
Send email with subject: Door Open and message: Lorem Ipsum to: [email protected]
Set scene: Alarm = On (To change to color to red)
Set Yeelight_Roomname off after 1 seconds
Set Yeelight_Roomname on after 2 seconds
Set Yeelight_Roomname off after 3 seconds
Set Yeelight_Roomname on after 4 seconds
Set Yeelight_Roomname off after 5 seconds
(And so on)
Else if
Deursensor = Closed
Set scene: Alarm = Off (To change to color to back to neutral)
Set Yeelight_Roomname off
As you can understand i don't want to flash to lights only 3 times (as the scripts above describes) but i want to scare the bruglar (if any..).
In addition, i also want to play a sound on my Google Nest Mini (for example an Siren sound).
To make the script neighbourhood proof, I don't want to play the sound 24/7 when i'm for example at holiday. To make it clear what i want:
- When the door is open and i'm not at home
- I want to flash the lights based on a scene for 5 minuts and play a sound for 5 minuts
- After 5 minuts the lights goes off and sounds goes off
- If door is still open after 10 minuts
- Then flash the lights based on a scene for 5 minuts (no sound this time!)
- After 5 minuts the lights goes off
- Then flash the lights based on a scene for 5 minuts
The Dummy Switch is for example in case of a false alarm so i can turn i manually off myself from any location or when my parants/friends or anyone needs to enter the garage when im not at home.
Ok let's stop talking and let me show you the script so far... (what is far from complete, yet)
Code: Select all
return
{
on =
{
timer =
{
'every minute',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Door alert',
},
execute = function(dz, timer)
local flashRepeats = 5
dz.log('======================== ', dz.LOG_DEBUG)
dz.log('======================== ', dz.LOG_DEBUG)
dz.log('======================== ', dz.LOG_DEBUG)
dz.log('Door trigger started ' .. timer.trigger, dz.LOG_DEBUG)
local Door sensor = dz.devices('Doorsensor13')
local Lamp1 = dz.devices('YeeLight_roomname1')
local Lamp2 = dz.devices('YeeLight_roomname2')
local Phone1 = dz.devices('Phone1')
local Phone2 = dz.devices('Phone2')
local Dummy Switch = dz.devices('Dummy')
if (Doorsensor13.state == 'Open' and Doorsensor13.lastUpdate.minutesAgo > 1) then
dz.log('Door trigger: Door is open, blink lights... ', dz.LOG_DEBUG)
--dz.notify('Door alert', 'Doorsensor13 is more then 5 minuts open!', dz.PRIORITY_HIGH)
--first turn off the lights if they are on
YeeLight_roomname1.switchOff().checkFirst()
YeeLight_Roomname2.switchOff().checkFirst()
for i = 1, (flashRepeats * 2), 2 do
dz.log('Now scheduling lights on after ' .. i .. ' seconds... ', dz.LOG_DEBUG)
YeeLight_Roomname1.switchOn().afterSec(i)
YeeLight_Roomname2.switchOn().afterSec(i)
dz.log('Now scheduling lights off after ' ..( i + 1) .. ' seconds... ', dz.LOG_DEBUG)
YeeLight_Roomname1.switchOff().afterSec(i + 1)
YeeLight_Roomname2.switchOff().afterSec(i+1)
end
-- restore On state when state was active before script started
if YeeLight_Roomname1.active then YeeLight_Roomname1.switchOn().afterSec(flashRepeats * 2 + 2) end
if YeeLight_Roomname2.active then YeeLight_Roomname2.switchOn().afterSec(flashRepeats * 2 + 2) end
end
end
}
- There is no connection between phone status or dummy switch
- The lights does not flash for 5 minuts, but only 5 times ofc i can count the 5 times = 5 seconds, but isn't there an easier way? Or is it better to count the timing and set amount of flash to 300 times (5 minutes x 60 seconds)
- The lights does not goes to a specific scene
- There is no sound option (I found this topic (https://domoticz.com/forum/viewtopic.php?t=24698) but i don't get the sound working at all, but skip the sound in that case for now to make the progress easier, perhaps i need to make a new topic for that)