I am testing this for a few months and like a charm.
I want to create a virtual presence sensor that indicates the presence of mail in my mailbox. My mailbox is on my house door, just attached to it. And the flap or door to leave the mail is the same to take it out. I thought to do something simple:
If the mailbox opens and the door is not being open after or before during X amount of second, this means someone drop content into the mailbox (well could be a thief, but well, let's keep the problem statement simple
This X amount of second of seconds, let's call them TheOffsetTime
- 1 Hubitat
- 2 contact sensors. One attaches to the door, and another connects to the mailbox.
- The Rule Machine app.
The first step, create the virtual presence sensor. Pick your favorite name. This sensor presence is great for your dashboards.
After that, let's move to the Rule Machine.
So I create a global variable on the RULE MACHINE
last_time_front_door_action (number) it will store the last time the door was open in seconds
I create rule ( SetLastTimeFrontDoorOpen) the only thin that it does is to set the variable
now() in seconds.
I create a second rule (Mailbox) with 2 local_variable
time_mailbox_open_with_offset(number). It will store the time where the mailbox was open minus the
TheOffsetTime. just a trick to make the condition simple.
is_time_in_range(boolean). This is to simplify the condition, probably not needed, but I can access the rule in the future and see what happened the last time.
The code of the rule:
I get the time in seconds and populate the variable
now() - 60 (a minute)
I wait for a minute so someone can open the door during that time
is_time_in_range variable to be able to make the following condition:
time_mailbox_open_with_offset is higher than
is_time_in_range is true
Else "I have a mail"
Depending on the value of
is_time_in_range I send the notification and set the virtual presence of the sensor
But better to check the next image.
As a cherry on the top. I create a virtual switch and share it with the google home that I use in a routine on my google home, "Hey google, Do I have any letter?" and when this switch is activated with this routine. I send a message to my google home to reply with the value of the present sensor.
And for fun: I set the sensor outside the mailbox. I am using a zigbee sonoof that is pretty bulky. So I took it from the box and created a smaller box (with a poker card ) And the magnet also outside the box.
I checked different articles before starting to code anything.
I may learn how to create apps inside hubitat and move this into an app.