I’m trying to get some best practises for the following use case:
one “vibratoin” sensor on the letterbox lid
one “door” sensor on the letterbox door
So, if someone (delivery person) opens the letterbox to throw something in, the “vibration” sensor would go “ON”, so I can change state item to “letterbox full”.
If someone (we as a family) opens the letterbox and the door, both the “vibration” sensor and the “door” sensor would go “OPEN”.
So currently I’m using the following rules, but perhaps there’s some better solutions to this?
letterbox opened
configuration: {}
triggers:
- id: "1"
configuration:
itemName: ZigVibBrief_Vibration
state: ON
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "4"
configuration:
type: application/javascript
script: >-
/*
Someone opened the letterbox: presumably new mail/parcels
*/
if (items.getItem("ZigVibBrief_Vibration").state == "ON")
{
// Es wurde etwas reingeworfen
text = "Es wurde etwas in den Briefkasten geworfen.";
console.info("INFO Briefkasten: " + text);
items.getItem("ZigBrief_Einwurf").postUpdate("ON");
}
type: script.ScriptAction
letterbox emptied
letterbox door opened
configuration: {}
triggers:
- id: "1"
description: wenn Briefkasten wieder von uns geschlossen wird
configuration:
itemName: Zig_TuerBrief_Kontakt
state: CLOSED
previousState: OPEN
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >
/*
if someone emptied the letterbox, the door was open and then closed
*/
if (items.getItem("Zig_TuerBrief_Kontakt").state == "CLOSED") {
// Es wurde entleert und ist jetzt geschlossen, 5sec warten, dass eine evtl. "Vibration" des Briefkasten vorbei ist
java.lang.Thread.sleep(5000);
text = "Der Briefkasten wurde geleert.";
console.info("INFO Briefkasten: " + text);
items.getItem("ZigBrief_Einwurf").postUpdate("OFF");
}
type: script.ScriptAction
At least it works, but I think it’s a bit “dirty”? I don’t like that the “letterbox opened”-rule also fires, if someone empties it, because first you have to open it (vibration=ON), then you open the door (door=OPEN).
Is there some simple trick to delay both rule firings until it’s clear, that the letterbox was opened by a delivery person (no door=OPEN after ~5 secs) or us (door=OPEN within ~5 secs)?
Perhaps someone already has a solution for a similar use case?
Add a condition (but only if…) to the letterbox opened rule so it only runs when the letterbox is empty.
The first rule should have a condition to only run when ZibBrief_Einwurf is not ON.
I would use a sonic or similar range sensor to tell me when something is actually in the box, instead of using the doors as a proxy. But that only makes sense if you have power, as these sensors use a lot. But they can be made more power friendly by only coming on once every five minutes or so and take three or so readings before going back to deep sleep.
Looking at the code of your rules, your if statements in both rules are redundant and not needed at best, and might cause problems at worse. You already know ZigVibBrief_Vibration is ON because otherwise the rule would have never run. You also know that Zib_TuerBrief_Kontakt is CLOSED because otherwise the rule would have never run. So the if statements are unnecessary. They are testing for something you already know.
However, the problem comes in because there might be a timing problem. Let’s say the door is opened and closed very rapidly and for what ever reason there was some latency between the events occurring and the rules firing. That means when the first rule runs, it’s triggered by an ON event, but by the time the rule runs the Item has returned to OFF. Your if statement will then not run the code because the Item isn’t ON anymore, and you will completely miss this ON event. It will be as if the ON event never happened.
Sometimes doing something just in case can itself cause problems. For a more general and philosophical set of discussions, look up “Galileo’s Column”. In this case, the if statements are solving a non-existant problem but introducing a new problem.
'm using two (door) contact sensors, one for the lid, one for the door. With the lid it really depends on your letter box, if and how you can install a contact sensor there, but this really works very nicely.
oh. That’s correct! i doubled them just in case. but that brings me to another thought: I could combine both rules and just wait after a Vibration, if also the door opens up. As the “letterbox is full”-sign is definitely not time-critical, this would be enough.
So basically I have only one trigger (Vibration=ON) and then a pause in the rule, if additionally also door=OPEN. If both happened => someone emptied it, if only one happens => someone threw something in. (because there’s more than one delivery company bringing letters and parcels - it’s not a small letterbox, but in fact a small packet box so to speak, it could be opened multiple times before we empty it)
thanks for the food for thought - the final rule:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: ZigVibBrief_Vibration
state: ON
previousState: OFF
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: |
/*
wenn der Briefkasten geöffnet wurde gibts zwei Möglichkeiten:
* es wurde was eingeworfen (d.h. die Tür bleibt geschlossen)
* es wurde was rausgeholt (d.h. die Tür wird kurz danach geschlossen)
*/
var interval = 500;
var timeout = 10000;
var elapsed = 0;
var door = items.getItem("Zig_TuerBrief_Kontakt").state;
console.info("DEBUG Briefkasten: Der Deckel wurde geöffnet");
var check = setInterval(() => {
door = items.getItem("Zig_TuerBrief_Kontakt").state;
console.info("DEBUG Briefkasten: es wird geprüft bei " + elapsed);
if (door == "OPEN") {
clearInterval(check);
// Es wurde geöffnet und entleert
text = "Der Briefkasten wurde geleert.";
console.info("INFO Briefkasten: " + text);
items.getItem("ZigBrief_Einwurf").postUpdate("OFF");
} else {
elapsed += interval;
if (elapsed >= timeout) {
clearInterval(check);
// Es wurde "NUR" etwas reingeworfen
text = "Es wurde etwas in den Briefkasten geworfen.";
console.info("INFO Briefkasten: " + text);
items.getItem("ZigBrief_Einwurf").postUpdate("ON"); }
}
}, interval);
type: script.ScriptAction
I placed a vibration sensor (not on the lid, but under there somewhere, where you can’t reach without a key). When the lid is opened, there’s “vibration”.
also a simple door sensor, if you open the front with a key. to place the key, you have to open the lid (just as a delivery person would also)
but so, the rule is pretty neat now.
yes, as Rich said, there’s no guarantee, someone really placed something inside, you could just open the lid and close it - but for my use case it’ll do.
Some weight or sonic sensor would be more reliable, I do have some empty tube (don’t know if that’s the correct expression, some installed flexible tube, capable of placing some cables through it), but I guess the zigBee sensors will do just fine…
I would have thought that a contact sensor underneath the drop doors, also only accessible with a key, would also have been possible. Not necessarily to be constantly closed, but only temporarily closing the contact when the trap doors briefly open to let a parcel through; to indicate a delivery.
I’m just all for hardware hacks to allow for simple streamlined rules, but you got it working with vibration and a more complex rule as well, so that’s the important bit - that it is working
I use an IR transmitter/receiver pair with an integrated relay, when there is nothing in the mailbox the IR reaches the receiver and the relay is closed when there is a package or letter the IR gets cut off and the relay opens.
You do need to get voltage to the mailbox plus the relay wires.
that’s cool. I’m afraid a IR sensor (or weight sensor) won’t recognize some small postcards or even light letters, as the room inside the box is over 1meter high…
with red being the reed sensor, zigbee or whatever, and the very small green bit the magnet, not the usual ones that comes with most contact sensors, as they are generally quite large, but a strong neodymium magnet, which you can get in all shape, sizes and strengths - so a 20mmx10mmx1mm or similar, positioned on the bottom or side of the trap door, or even under its lip if it has one, should suffice.
Or even an optical contact sensor which uses IR light to measure the distance which gets triggered when the trap doors are open briefly - my Homematic contact sensors work like that, so not even a magnet required, only the IR contact sensor. So many contact possibilities there
But I really don’t want to persuade you to use a contact sensor, it’s just how I would go about it. Vibration, IR, ultrasonic distance sensor, weight sensor … are all viable alternatives
I tried, the schemes in the picture are somewhat simplified. The mechanism is not that near to the inner walls, but anyways… either way door sensor or vibration sensor cost both roughly the same and both deliver a boolean state in the end.
My notification strategy is that an expire timer is running for 20 sec when sensor 1 is closed. If sensor 2 is not triggered within this 20 seconds a “new mail” message is sent by telegram and the alexa show shows a picture with a parcel. If sensor 2 is triggered then openhab knows that the mailbox was emptied, clears the alexa message and sends a “postbox was emptied” by telegram.
that’s great, but I didn’t like having my sensors exposed like that!
but yeah, something like that is happening here also after someone threw new mail/packets in. Perhaps sometime in the future I’ll place a webcam inside to also send a picture to our “MagicMirror”, so you could also see, what has arrived… (which brings me to a new idea, sending a snapshot of the outside webcam at the time of opening to see, which delivery provider it was)
Maybe even better: create an animated gif (5 sec in my case) through the IPCamera binding, send it via Telegram or Pushover binding to a smartphone.
Animated gifs are not working with the openHAB Android app, though (don’t know about iOS)
Glad to finally see some focus on letterboxes here in the forum.
I‘ve been trying out multiple solutions over the past three years (so it’s fair to say I’ve tried out what works and what doesn’t) and can finally recommend my solution based on two IKEA Parasoll sensors.
I hope I’ll get around to take some pictures and add a small description in the next couple of days.
I experimented another approach using a Sensative Strips + Guard (zwave sensor). It works pretty well (I installed it 5 years ago) with the french normalized mailbox (it is thin enough to keep the mailbox normalized). It works both when the postman puts a package in the mailbox (by opening the door) and when he puts a letter through the lid (I cannot discriminate between the two).