Code Advice: Only Enable 'Alarm' when no motion, stop trying after 3 minutes?

I’ve been using PLEG as my DIY alarm. So far, this is pretty good but the problem has been timing issues with motion, door closings, etc

I’d like the security modes (Away, Sleep, etc) to be set manually but the logic to be something like this…

  1. Away set manually to ON
  2. Check all Motion Sensors / Door Sensors, etc for the next 3 minutes.
  3. IF no sensors are tripped, enable “Away Mode”
  4. IF any sensors are tripped, do not set Away Mode and Send Alert (VeraAlerts) with the sensor(s) that are tripped.

Anyone do anything like this? Example code is highly appreciated!

What parts have you accomplished so far

Sent from my GT-N7100 using Tapatalk

[quote=“Aaron, post:1, topic:182280”]I’ve been using PLEG as my DIY alarm. So far, this is pretty good but the problem has been timing issues with motion, door closings, etc

I’d like the security modes (Away, Sleep, etc) to be set manually but the logic to be something like this…

  1. Away set manually to ON
  2. Check all Motion Sensors / Door Sensors, etc for the next 3 minutes.
  3. IF no sensors are tripped, enable “Away Mode”
  4. IF any sensors are tripped, do not set Away Mode and Send Alert (VeraAlerts) with the sensor(s) that are tripped.

Anyone do anything like this? Example code is highly appreciated![/quote]

I am more likely more a newb then you but atleast let me make a fool outofmyself for doing it the hard way.
I try a variant of RexBeckets example from the PLEG basics doc, (thanks rex btw they have helped me alot in understanding a bit more.)
So here i go, to get the string output i think you need to get into the vera template library stuff.
http://rts-services.com/VeraTemplates/
Which i at this point in time know nothing about, and here its getting a tad late so i cant indulge myself to much in it atm. (scrambled brain and no coffe)

Triggers:
ArmSw - manual alarm switch
Sens1
Sens2
SensN…

Conditions:
AnySensor - Sens1 or sens2 or … SensN
Alarm$Idle - Not ArmSw
Alarm$Armed - Alarm eq ‘Idle’ and ArmSw and !AnySens and (!AnySens; Now>03:00)
Alarm$Error - Alarm eq ‘Idle’ and ArmSw and AnySens and (AnySens; Now>03:00)

(i wont fill in the gaps after this this is where you do your alarm tripped or alerts conditions/actions)

Actions:

Alarm$Error - Run VeraAlert Profile with the message you want, possibly with the template output i mentioned above.
I gave it a 1minute glance so i might be totally wrong… dont know if it is possible to fetch only tripped ones though.
But here we go with my solution.

I would guess it would be something like:

 An error occurind while Arming the Alarm!! Sensor 1 in {Device([insert device number of sensor 1 here].room.name)} is {Device([INSERT DEVICE NUMBER HERE of sensor 1].service[urn:upnp-org:serviceId:SwitchPower1].Status) , Sensor N in {Device([insert device number of sensor N here].room.name)} are {Device([INSERT DEVICE NUMBER HERE of sensor N].service[urn:upnp-org:serviceId:SwitchPower1].Status) | Choose(0=OK, 1=Tripped, Other=Unknown)} . End of report! 

With the above you the following if sensor 1 in toolshed(example) was tripped and SensorN in basement(example) was not tripped.

Printout should be something like.
An error occurind while Arming the Alarm!! Sensor 1 in Toolshed is Tripped, Sensor N in Basement is OK . End of report!

I have no idea if your could do some sort output of devices with state 1 only. like a condistional printF of sorts… read my link and the MCV docs http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#variable:_devices

Good luck!
Atleast i learned something in the process i think.

Hey

I do something similar. Its still a work in progress, so I am currently only generating notifications when my home state multiswitch is changed, so I can track when each mode is set, but eventually I will have actions to send various alarms via VeraAlerts, auto-set my DSC alarm when away, etc. Essentially all the “modes” - sleep, alarm, away, vacation, etc - are all on a multiswitch called “Home State”. I have conditions to automatically set different alarms if we are asleep or away. It also detects when someone gets out of bed and goes downstairs, so it is wife and kid friendly and pretty much self governing. Still one or two bugs I am ironing out to make it completely reliable but its not far off. Hope it is of some help!

Triggers
Name Description
Armed Home State Switch 4 is turned on
Awake Home State Switch 5 is turned on
Away Home State Switch 2 is turned on
BathMotion Bathroom armed is tripped
BiFoldDoorLeft Bifold Doors Left is tripped
DiningMotion Dining Area is tripped
Disarmed Home State Switch 3 is turned on
DSCArmed Partition 1 is Armed
FrontDoorOpen Front Door is tripped
GrannyMode Home State Switch 8 is turned on
HallMotion Hallway armed is tripped
Home Home State Switch 1 is turned on
KidsBrMotion Kids Bedroom armed is tripped
LandingMotion Landing is tripped
LivingMotion Living Room is tripped
MainBrMotion Master Bedroom is tripped
Sleep Home State Switch 6 is turned on
Vacation Home State Switch 7 is turned on
Schedules
Name On Type On Time On Days Random On Delay Off After Type Off Time Off Days Random Off Delay
AlarmTimer Self ReTrigger None Interval 10:00 None
AutoAlarm Unknown None None None
SleepSchedule Weekly 22:00:00 1,2,3,4,5,6,7 None Weekly 03:00:00 1,2,3,4,5,6,7 None
Conditions
Name Repeat Expression
SleepAlarmSet No Sleep AND !UnsetSleepAlarm AND !AlarmTimer AND (Sleep;!AlarmTimer)
DownStairsMotion No LivingMotion OR HallMotion OR DiningMotion
UpstairsMotion No BathMotion OR LandingMotion OR KidsBrMotion OR MainBrMotion
KidsUp No Sleep AND LandingMotion AND (KidsBrMotion < 30) AND (KidsBrMotion;LandingMotion < 30)
ParentsUp No Sleep AND LandingMotion AND (MainBrMotion < 30) AND (MainBrMotion;LandingMotion < 30)
SomeoneGotUp No !SomeoneGotUp AND ((KidsUp and HallMotion and (KidsUp; DownStairsMotion < 120)) or (ParentsUp and HallMotion and (ParentsUp;DownStairsMotion < 120)))
NoMotion No !UpstairsMotion AND !DownstairsMotion
NoMotion2Hr No NoMotion AND (NoMotion; NOW > 2:00:00)
UnSetSleepAlarm No !Sleep OR FrontDoorOpen
SleepAlarmDetect No Sleep AND !ParentsUp AND !KidsUp AND (SleepAlarmSet AND ((DownstairsMotion @ 4 < 2:00) OR BiFoldDoorLeft))
AutoSleepDetect No !Sleep AND !Away AND !Vacation AND SleepSchedule AND ((DownstairsMotion;UpstairsMotion) AND (LandingMotion;MainBrMotion) AND (!DownstairsMotion; NOW > 20:00))
AutoAwayDetect No !GrannyMode AND !Sleep AND NoMotion2Hr AND !BifoldDoorLeft AND (UpstairsMotion;DownstairsMotion;FrontDoorOpen;NoMotion2Hr)
AwayAlarmSet No AutoAwayDetect AND !AlarmTimer
SleepIsSet No Sleep AND !AutoSleepDetect
GoodMorningParents No SomeoneGotUp AND ParentsUp AND (07:00:00;ParentsUp;SomeoneGotUp;10:00:00)
Actions
Actions for Condition: AutoAwayDetect
Device Actions:
Immediate
Device Action Arguments
VeraAlerts SendAlert Message=House is empty. Setting Alarm in 5 Minutes. To stop, double click hallway light switch Recipients=redbondc
Security and Home State Control StartTimer timerName=AlarmTimer intervalTime=5:00
Actions for Condition: AutoSleepDetect
Device Actions:
Immediate
Device Action Arguments
Home State SetStatus6 newStatus6=1
Security and Home State Control StartTimer timerName=AlarmTimer intervalTime=60
Actions for Condition: AwayAlarmSet
Device Actions:
Immediate
Device Action Arguments
Home State SetStatus2 newStatus2=1
Home State SetStatus4 newStatus4=1
Actions for Condition: GoodMorningParents
Device Actions:
Immediate
Device Action Arguments
Play 5 Kitchen PlayURI URIToPlay=FR:BBC Radio 4 Volume=25
Actions for Condition: SleepAlarmDetect
Device Actions:
Immediate
Device Action Arguments
VeraAlerts SendAlert Message=Possible Intruder Downstairs Recipients=redbondc
Actions for Condition: SleepAlarmSet
Device Actions:
Immediate
Device Action Arguments
Home State SetStatus4 newStatus4=1
VeraAlerts SendAlert Message=Setting sleep alarm Recipients=redbondc
Actions for Condition: SleepIsSet
Device Actions:
Immediate
Device Action Arguments
Security and Home State Control StartTimer timerName=AlarmTimer intervalTime=
Actions for Condition: SomeoneGotUp
Device Actions:
Immediate
Device Action Arguments
Home State SetStatus5 newStatus5=-1
Actions for Condition: UnSetSleepAlarm
Device Actions:
Immediate
Device Action Arguments
Home State SetStatus3 newStatus3=1

Borat,
This is fantastic! What bugs are you working out? When I get some time next week, I’m going to work on integrating your solution.

Hi Aaron

Mainly minor things, such as sometimes it does not detect my kids getting up. I think this is more a limitation of my sensors than of the PLEG, so I intend on adding some more logic to ensure they dont set off the sleep alarms when they get up, or i will fiddle with my DSC sensors. Not sure I have all the logic quite right yet for when the alarms are set, as currently when I set sleep I also get an alarm tripped message, so I think I have a timing or sequencing issue there. Otherwise its not far off, though I have a concern around intermittent LUA restarts at the moment, which may or may not be related to some of my PLEG. I have a suspicion it may be uPNP proxy so still troubleshooting, but if I find anything I can trace back to an issue here will let you know.
On the top of my to do list for this:

  1. Have a working script that checks all my sensors and will text me telling me which are tripped if there is an alarm. Just need to integrate it.
  2. Link to my DSC panel so that it auto-arms it when we are out
  3. Fire alarm linkage (from the DSC)
  4. Auto-detect false alarms.
  5. Build in additional occupancy checks using iphone locator or pings, or combination.
  6. Link with the Sonos and lights to really screw with a burglar’s head if they do get in when we are away… Am planning on all kinds of flashing lights and death metal at full blast lol
  7. Allow a few more actions to be triggered by my fibaro switches (I use the s2 scene controller to initiate different things)

Cheers