Letter Drop Notification

I would like to share with the community a simple solution on how to detect when a letter is dropped into the mailbox.
I would also like to share my excitement about the new rules engine, it’s amazing compared to “old” DSL.

here my HW setup:

I have some classical EU letter mailbox:

I added a HomeMatic Wireless Door/Window Sensor, optical inside the mailbox:


Contact	MailDrop  	"Mail Drop [MAP(op-cls.map):%s]" 	<contact>     	{ channel="homematic:HM-Sec-SCo:3014F711A0001F58A992FB22:OEQ0394182:1#STATE"}

Group:String gTTSMsg "Alexa TTS Group"
Group:Dimmer gTTSMsgVol "Alexa TTS Group Volume"
Group:Dimmer:MIN gALXMsgVol "Alexa Group Volume"

String LivingRoomAlexaTTS "Living Room Alexa TTS"  (gTTSMsg) {channel="amazonechocontrol:echo:1d4fd2ef:G090L9096434075W:textToSpeech"}
Dimmer LivingRoomAlexaTTSVolume "Living Room Alexa TTS Volume" (gTTSMsgVol) {channel="amazonechocontrol:echo:1d4fd2ef:G090L9096434075W:textToSpeechVolume"}
Dimmer LivingRoomAlexaVolume "Living Room Alexa TTS Volume" (gALXMsgVol) {channel="amazonechocontrol:echo:1d4fd2ef:G090L9096434075W:textvolume"}

String StudyRoomAlexaTTS "Study Room Alexa TTS"  (gTTSMsg) {channel="amazonechocontrol:echo:1d4fd2ef:G090L91072320ULE:textToSpeech"}
Dimmer StudyRoomAlexaTTSVolume "Study Room Alexa TTS Volume" (gTTSMsgVol) {channel="amazonechocontrol:echo:1d4fd2ef:G090L91072320ULE:textToSpeechVolume"}
Dimmer StudyRoomAlexaVolume "Study Room Alexa TTS Volume" (gALXMsgVol) {channel="amazonechocontrol:echo:1d4fd2ef:G090L91072320ULE:volume"}

and finally the python code:

from core.triggers import ItemStateChangeTrigger
from core.log import logging, LOG_PREFIX
from core.rules import rule
from core.jsr223.scope import events, items
from threading import Timer
from core.actions import Mail, Pushover

log = logging.getLogger(LOG_PREFIX + ".letterdrop.log")          

triggers = []
triggers.append(ItemStateChangeTrigger("MailDrop", "OPEN", "CLOSED", "DROPSTART").trigger)
triggers.append(ItemStateChangeTrigger("MailDrop", "CLOSED", "OPEN", "DROPFINISHED").trigger)
@rule("Letter Drop Rule)", description="This Rule monitors dropiing letters into the bin")
class iCloudRule(object):
    def __init__(self):
        self.triggers = triggers
        self.drop_in_timer = None

    def push(self, msg):

    def say(self, msg):
        events.sendCommand("gTTSMsgVol", str(items["TTSVolume"]))
        events.sendCommand("gTTSMsg", msg)

    def mail(self, msg):
        Mail.sendMail("me@gmx.ch", u"Postfach ", msg)
        Mail.sendMail("her@gmail.com", msg)    

    def letterStuck(self):
        msg = "Brief steckt in der Postfachklappe"

    def dropStart(self):
        self.drop_in_timer = Timer(3, lambda: self.letterStuck())
    def dropFinished(self):
        msg = "Brief in Postfach geworfen"

        if self.drop_in_timer != None:
        log.info('*** dropFinished ***')
    def execute(self, module, inputs):
        act = str(inputs["module"]).split("_")[0]

        if act == "DROPSTART":
        elif act == "DROPFINISHED":

I would like point out how amazing the class decoration is and how it allows to separate the trigger definition and also add name to the trigger, which could be used inside the execute in order to react based on the trigger.


That’s a really elegant solution. I love your placement of the sensor.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.