Looking for design pattern to handle rules based on presence state

Hi all,

I have a pretty simple presence detection which is set if my front door is locked or not. My question is not how to set the presence state but I would like to know what others use to handle their rules based on the presence state.

So far I have a simple switch which indicates if I am present or not. In my rules which are affected by this I include the state of the switch. I have the feeling this is getting a bit cluttered and I am going to loose the overview. I would like to know if there is a smarter way to handle rules based on the presence.

NoTechi

I don’t see that as bad. I personally use a string that gets updated with “Home” or “Away” by the iphone detection script: iPhone Presence Detection with hping3 and ARP

I then check if the string equals what I’m looking for in my rules. Basically the same, you just check if the switch is on or off instead.

I’ve done the same thing with my alarm. A switch for arm/disarm (on/off) I use it in a rule when alarm disarmed and it’s not day (I also have a day/night switch) then turn on some lights for 15 mins

I monitor 4 states: home, away, sleep, vacation and have rules act on those. You could use the Time Of Day design pattern by @rlkoshak

Do you manually set sleep or do you have a method for determining sleep?

Currently I set sleep as manual through a dedicated wall switch or 443 MHz remote. But I could use the TimeOfDay item from the example as well.

In the future I could also automate this by monitoring turning on and then off the lights in the bedrooms after a specific time at night. But since this is prone to error , false positives, I don’t think that is feasible.

Yeah, short of the manual method… none of the rest of those are slam dunks. Unless you are VERY regimented, time based or light and time based rules would be buggy. Oh well… some day I’ll come up with a reliable bed occupancy setup.

I am thinking of (if it’s even possible) one rule monitoring the presence state and depending on the state execute specific rules just for that state instead of having each rule handle alll possible states. That way I would have a clear structure of the rules themself (vacation, @home, gone,…) … on the other hand I might have to repeat the core rule functionality in each presence state rule. Well I gona give it some more thoughts :slight_smile:

NoTechi

Perhaps there is a smartwatch app that you wear to bed that reports sleep.

I’m not seriously considering this, but there are zwave bed sensors:

https://www.e-domotica.com/nl/producten/alarmeren/em6648-e-domotica-z-wave-bedsensor

(not available through the english version of the site)

Well I have an apple watch already. Having to take that off and put on a different watch would be worse than just pushing a button on my night stand. My apple watch has to charge sometime so I can’t wear it all night.

That’s one crazy box spring. Also, that’s $619 USD. That’s a little over the top. I could build something for FAR less than that based on arduino or esp.

@NoTechi, it really depends on your needs. I suggest that you engineer a solution based on exactly what you’re looking for. For example, if your door lock switch is accurate enough for your needs to determine whether you are present, just use that in your rules and it should work just fine.

If you’re finding that you use a combination of items together often, it might be worthwhile to create a virtual item or items which is managed based on the input of your lock switch. For example, say you also have a bedroom light that you keep on when you’re awake. You could create an Item IsBedTime (or whatever you feel it should be named). Then create a rule which takes your presence switch and bedroom light states as triggers. If you are present and the light is off, change the IsBedTime state to ON.

By using this method, you can start by using your individual items in any rules you have. Then, if you find that the rules are getting difficult to understand, you can create virtual items that represent common states you would see. You can do this whenever you feel you need to, there is no rigid requirement for determining when to use this method.