Easy Mailbox Notifications in Home Assistant

What’s up Smart Homers, my name’s Aaron. This article is the written version of a video I just did showing how I easily set up mailbox notifications in Home Assistant. These include phone notifications, audio notifications, and dashboard notifications.

Every day when I get home from work, I check the mailbox for mail, never knowing if someone else already picked it up or if we even got any. The plan for this project was to put a contact sensor on my mailbox so that I could be notified when mail arrives.

For this project I used a Zooz ZSE41 contact sensor with waterproof case, an Aeotec Z-Wave repeater, and a few other household items.

Choosing the Right Sensor

Because of the distance from my Home Assistant hub to my mailbox, I was limited in what type of sensor I could use. This distance, almost 80 feet, forced me to look for a sensor that could reach all the way out to the mailbox, which in my case meant a wired sensor, a WiFi sensor, or a Z-Wave sensor. I didn’t consider RF because I don’t have an RF bridge (but I’m planning on getting one).

I try to avoid WiFi at all costs, so that was not an ideal option, and I really prefer to keep it wireless. This left me with the option to use a Z-Wave contact sensor, but the predicament here was the price of the sensor! Most Z-Wave contact sensors that I saw were $35 or more. However, recently Zooz released their ZSE41 contact sensor, which was selling at a stunningly low price of $18, and for a couple dollars more you can get a waterproof case for it! This is the contact sensor I decided to use for this project.

Extending Your Z-Wave Network

Once the sensor arrived, I easily paired it with Home Assistant via Z-Wave JS. I decided to test the range of my Z-Wave network by holding the contact sensor and walking out into the yard. I only got about halfway out to the road before I went out of range. The signal had to go through a wall as well as my front door in order to reach the mailbox, so I installed a Zooz Z-Wave light switch (which works as a a Z-Wave range extender) directly inside my front door, hoping the switch would extend my Z-Wave network. Once the new Z-Wave switch was installed, I had to “heal” the contact sensor node so that it would try to find the path of least resistance back to the hub. This did extend the range a little, but it did not extend it far enough to reach my mailbox. I realized that since my front door is made of metal and my house has brick on the outside, this may have been interrupting the Z-Wave signal.

Next, I decided to use a Zooz smart plug (which also acts as a repeater) to try extending the range.

Zooz ZEN15

I plugged it into an outdoor outlet on the front outside wall of my house, just outside the front door. Once again, I “healed” the Z-Wave node, and this time I had signal all the way out at the mailbox! This proved that the metal door or the brick wall was affecting the signal, and that a range extender on the outside of my house would work. Then I ordered an Aeotec Z-Wave repeater to use instead of the smart plug.

Distance problem solved!

Contact Sensor Installation

Next, I did some planning as to where I would mount it on the mailbox. My first thought was to mount it inside the mailbox. After seeing how it would look on a cardboard box, I installed the sensor on the inside of the mailbox without the waterproof case. Typically, the inside of my mailbox stays dry, so I wasn’t worried about it getting damaged. However, the sensor could not communicate with my Z-Wave network from inside the metal mailbox! Next, I tried mounting the sensor underneath the mailbox, still no signal! Then I tried mounting it on the side of the mailbox, using the waterproof case.

Sensor Mounted on the Side

Still, no signal! After trying lots of difference locations on the mailbox, I finally found that mounting it on the side of the plastic door of the mailbox worked. It was evident that having the device inside or directly mounted to a big metal box was messing with the Z-Wave signal.

Sensor Mounted on Lid

My problem with mounting the sensor on the mailbox door was that the gap between the sensor and the small piece of the sensor, was too large, and there was nowhere to mount the small piece that would allow it to sit close enough to the sensor for the sensor to be made. Since the small piece is just a magnet, I took some round kitchen fridge magnets, stuck them together with double-sided tape, and used them in place of that small piece.

Gap Between Sensor and Mailbox (too big)
Magnets Back-to-Back, Wrapped in Electrical Tape

With this configuration, the sensor worked reliably each time the mailbox door was opened and closed. Though not as aesthetically appealing as a direct mount, it does the job. I may do some modifications in the future to make the sensor more secure, but this whole setup did survive hurricane Henri, so the adhesive mounting sticker and the waterproof case work very well!

Sensor Snug n’ Dry
Final Installation Location

Setting It Up In Home Assistant

In home assistant, I created a Boolean entity called “Mail Present” to indicate the presence of mail. An input_boolean entity in Home Assistant is a toggle entity that can be either on or off. If it is “on”, then mail is present in the mailbox. If it is “off”, mail is not present.

I also created an input_datetime entity called “Mail Arrived” that allows you to set its date and time value. The entity will be used to “save” the time that the mail arrives.

After creating these, it’s time to automate! I created two automations: The first one is triggered when the mailbox sensor is opened. The automation goes as follows:

  • First, it turns “on” the input_boolean that I created indicating that mail is present
  • Second, it sets the input_datetime value to the current date and time.
  • Next, it sends a notification to both my phone and my wife’s phone that mail has arrived.
  • Finally, it plays an audio notification over two different Google Home speakers in common areas of our house.

I also set conditions for this automation, because if there is already mail in the mailbox, I don’t want this automation being triggered when I open mailbox to retrieve the mail. I added a condition requiring the “Mail Present” Boolean entity to be “off”, meaning the automation only triggers if there is no mail in the mailbox.

alias: 'Mail: Mailbox Opened'
 description: ''
 trigger:
 type: opened
 platform: device
 device_id: b6b334716102cbd8f72727eadd377f24
 entity_id: binary_sensor.mailbox_sensor_open
 domain: binary_sensor
 condition:
 condition: state
 entity_id: input_boolean.mail_present
 state: 'off'
 action:
 service: input_boolean.turn_on
 target:
   entity_id: input_boolean.mail_present
 service: input_datetime.set_datetime
 target:
   entity_id: input_datetime.mail_arrived
 data:
   datetime: '{{ now().strftime(''%Y-%m-%d %H:%M:%S'') }}'
 service: notify.mobile_app_oneplus7
 data:
   message: You've got mail!
 service: notify.mobile_app_oneplus3t
 data:
   message: You've got mail!
 service: media_player.play_media
 data:
   media_content_type: music
   media_content_id: http://192.168.86.219:8123/local/youve-got-mail-sound-2.mp3
 target:
   entity_id: media_player.living_room_speaker
 service: media_player.play_media
 data:
   media_content_type: music
   media_content_id: http://192.168.86.219:8123/local/youve-got-mail-sound-2.mp3
 target:
   entity_id: media_player.kitchen_display
 mode: single Code language: YAML (yaml)

Next, there needs to be a way to turn the “Mail Present” sensor back to the “off” state so that the automation will trigger when mail comes the next day. To do this I created a simple automation that turns the input_boolean off each day at midnight.

alias: 'Mail: Reset Mail Presence'
 description: ''
 trigger:
 platform: time
 at: '00:00:00'
 condition: []
 action:
 service: input_boolean.turn_off
 target:
   entity_id: input_boolean.mail_present
 mode: single Code language: YAML (yaml)

My favorite part of this project is being able to see an indicator on my wall-mounted control panel then tells me that mail has arrived, and when it has arrived. To do this I first created a template sensor using the input_datetime information that gets “saved” in the automation. The sensor formats that information nicely.

  - platform: template
    sensors:
      mailbox_status:
        friendly_name: Mailbox Status
        value_template: >-
          {{ as_timestamp(states("input_datetime.mail_arrived")) | timestamp_custom("%I:%M %p") }}Code language: YAML (yaml)

Then I created a custom button card that shows me if there is mail, and when it arrived, or it shows “no mail” if it has not been delivered yet. I also gave it a tap action that allows you to “clear” the notification by turning of the “Mail Present” input_boolean.

type: custom:button-card 
entity: input_boolean.mail_present 
color: white 
show_state: false 
tap_action:   
  action: toggle 
state: 
- value: 'off'
  icon: mdi:email-off-outline
  name: No Mail
  color: rgba(0,0,0,0.3)
- value: 'on'
  icon: mdi:email-alert
  name: |
    [[[
      var time_delivered = states["sensor.mailbox_status"].state;
      return 'Mail delivered at ' + time_delivered 
    ]]] Code language: YAML (yaml)
Tablet
Close-Up of Custom Button Card

Key Takeaways

Anyway, that’s pretty much it. I have to say, once I was able to get in range, this sensor is very responsive and reliable, and I would highly recommend it. I haven’t had it long enough to test battery life, but the waterproof case is very affective even in extreme rain and wind!

The biggest thing I learned with this project is the ability of metal objects/doors and brick to attenuate a Z-Wave device’s signal. Even though Z-Wave devices have a longer range than other types, the construction material of the outside walls of your house play a big part. I was also amazed that putting the sensor directly on the metal mailbox caused a problem. If you have a metal mailbox, take this into consideration before starting the project.

If you enjoyed this article, check out my YouTube channel.

Automate Your Projector Setup with the Broadlink RM4 Pro

Hey Smart Homers! In this article I’ll show how I used the Broadlink RM4 Pro to automate my projector and motorized screen for a hands free experience. If you prefer a video, I’ve posted one on YouTube. If you watch it and enjoy it, please consider subscribing!

Before I really started building my smart home, I bought a 100-inch motorized projector screen (controlled by an RF remote) and a projector (controlled by an IR remote) for watching movies. As I added more to my smart home, I really wished I could automate these devices. This problem is now solved with a Broadlink RM4 Pro and Home Assistant. Now I can control both without needing the remotes, and can even use Alexa voice commands to control them.

RF vs. IR

Before I actually show how I did it, I want to quickly explain the difference between RF and IR. This is important information so that you are able to troubleshoot any future potential issues with your setup. Basically RF and IR are two different wavelengths on the electromagnetic spectrum. RF stands for Radio Frequency, and IR stands for Infrared. Both of these have longer wave-lengths than actual visible light, so you can’t see them. As you can see on the diagram below, RF has a longer wavelength than IR. This is important because it results in RF signals being able to pass through walls and other solids (to a certain extent of course). Though invisible, Infrared light cannot pass through solids because it of its longer wavelength.

Electromagnetic Spectrum

This difference between RF and IR will be important later.

How the RM4 Pro Works

Ok, so now I’ll explain how the RM4 Pro works. The RM4 pro works as both a transmitter and receiver for RF and IR signals. The device can “learn” signals from IR/RF remotes, and then can transmit those signals to the various devices that those remotes control. The RM4 Pro can be integrated with Home Assistant to allow for automations and scripts using these remote signals.
Important Note: The RM4 Pro only supports RF devices that operate at 433 MHz, so you check your remote to see what frequency your RF devices use before you buy this.

Connecting the RM4 Pro to WiFi

The first thing you’re going to need to do is set up the RM4 Pro in the Broadlink app. The only use we will have for the Broadlink app is that it will connect your RM4 Pro to your WiFi network. Once this is done, the app won’t be needed anymore.

First, plug in your RM4 Pro (power) and download the “Broadlink – Universal Remote” app. Once it is installed, open it follow the required steps in order to sign in. If you haven’t already, you’ll need to create a Broadlink account. Once you’re all signed in you should be at the “Welcome home” screen. Tap “Start to use” and then tap “Add device”. Allow any permissions it requests, and then it will begin scanning for nearby devices. Tap “WiFi devices” and then follow the instructions it shows. Once connected, you should see your RM4 Pro in the device list on this screen. Now you’re done with the app! Just close it out without proceeding any further.

Next, head over to your router settings (this will vary depending on what router you have) and find the IP address of your connected RM4 Pro. It’s a good idea to reserve that IP address for Home Assistant integration.

Setup in Home Assistant

Next, It’s time to head over to Home Assistant. Click on “Configuration”, “Integrations”, and look for the Broadlink integration. Your device should already be discovered and show up on this page, but if it doesn’t, click “Add Integration”. Search for Broadlink, and click the Broadlink integration. The “Connect to the device” box will pop up, requiring you to enter the IP address of your Broadlink device that you found earlier. Enter that IP address and click Submit. Once it’s integrated, click “Configure” on the integration, and give your RM4 Pro a name and area if you like.

Teaching a New Dog Old Tricks

Ok, now comes the grind. We’re going to have the RM Pro listen for codes sent by remotes, and save those codes so Home Assistant can send them. This part is really not too difficult, but just takes some time depending on how many remotes you want to learn from. I only had two remotes for this project: one for my projector and one for my projector screen. The projector remote uses Infrared while the screen’s remote uses RF. Each button press must be learned individually. The first thing we do is head over to developer tools. From there, click services, and on the services page, search for the “remote.learn_command” service. In the Targets field, click “Pick entity” and choose your RM Pro from the list. We are going to run this service for each button press we want to “learn”, changing the information in the fields shown below each time. Check the boxes next to Device, Command, and Command Type. The Device field lets you give a name to the device that you will control, for example, “projector”. The Command field lets you give a name to the command, for example, “power”. These two fields are completely custom, so you can call them whatever you want. After this, choose the Command Type from the dropdown menu for the 3rd field. My projector operates via IR, so I chose IR. Finally, click call service, and you should see a notification appear in Home Assistant telling you to press the button on the remote. Point the remote at the RM Pro and press the button. This should cause the notification to be cleared, and there you have it, you’ve learned the first code!

Now you can repeat this step for each button on your remote that you want to have the RM Pro learn. Note that, because of what I explained before about IR not being able to pass through solids, I found that you need to point the remote straight on at the RM Pro’s orange light where the IR receiver is. This is important for when you decide where you want to put the RM Pro – it needs to be in the same room as the projector, and facing it properly so that the projector can receive the signal it sends.

Next we can program our RF remote, which is only a slightly different procedure than with IR. In the service tab again, change the name of the device in the Device field to the name of the RF device. I name it “projectorscreen”. For my screen, I’m only programming up, down, and ok buttons, so in the Command field I put “up”. Change the command type to RF, and then click “call service”. You’ll see a notification appear in Home Assistant telling you to hold the button that you are programming. The RM Pro then sweeps across a range of frequencies looking for the signal that your remote is putting out. Keep holding until the notification goes away and then let go. Another notification will appear telling you to press the button once again, so give it a single press (no need to hold it) and that notification should also be cleared. As with the IR remote, repeat this step for each button you want to program. Once that’s complete, you’re all set to start sending commands via Home Assistant! Not so bad, eh?

Commands can also be “batch-learned”; multiple commands can be learned in a row. To do this, just put a list of commands (one per line) in the command field. Then you can learn them one by one.

Testing the Commands in Home Assistant

You can then test these commands by changing the service to “remote.send_command”, selecting your RM Pro as the target again, putting the name that you chose for your device in the Device field, putting in the name of the command that you want to send, and then clicking “Call Service”.

Scripts in Home Assistant

Maybe we want to send a sequence of multiple of these commands by tapping a button. In this case, we can write a script, and then call that script with a Lovelace button card. On the scripts page, choose “Add Script”. Give it a name, and then in the “Sequence” section, set the action type to “Call Service”. The service will be the same one you just tested (“remote.send_command”) and the same target. Specify the Device and the command. When making a script, you can add multiple commands in a sequence. You can also add delays in between commands if need, and you can also control other devices as well, like lighting. I’ll show a sample script later on.

Virtual Projector Remote in Home Assistant

Another cool thing that you can do is use the “custom:tv-card” to make a virtual remote in Lovelace. The card has a bunch of pre-defined buttons that can be tied to a service. Tapping the buttons on the card will call the service that you define. I used this card to combine both my projector and projector screen remotes into a single virtual remote. The card has predefined buttons for selecting  a TV’s channels (going up and down), so I used these buttons to raise and lower the projector screen. I used the source button to select the input for my projector. If you do not specify a service for a particular button, that button will not be displayed on the card (pretty nice). Below I have left the config YAML for my custom:tv-card setup.

type: custom:tv-card
 entity: sun.sun
 name: Projector Setup
 tv: true
 power:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: power
 up:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: up
 down:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: down
 left:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: left
 right:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: right
 select:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: ok
 back:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: exit
 source:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: source
 info:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projector
     command: menu
 channelup:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projectorscreen
     command: up
 channeldown:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projectorscreen
     command: down
 home:
   service: remote.send_command
   service_data:
     entity_id: remote.broadlink_rm4_pro_remote
     device: projectorscreen
     command: okCode language: CSS (css)

Automating the Entire Setup

I have a pretty cheap projector, and every time I turn it on I have to change the input source to HDMI so that my Chromecast with Google TV with be displayed. If we want to watch something on the setup, we have to lower the screen, turn on the projector, change the input source, and then we can control the Chromecast with the Chromecast remote. I don’t mind navigating Google TV with a remote, but I wanted to automate the rest of the process so that the kids can get the projector set up by themselves. I created a script that performs all these actions in a sequence as shown earlier. First the script sends the command to bring the projector screen down, and while that’s going (it takes a while), it sends the command to turn on the projector. Since the projector needs to be fully booted up before it can receive the commands to change the source, I put a “wait” action in the sequence. After 10 seconds, the script then sends a command to open up the Input Source menu. To select HDMI, the “right” command needs to be sent twice, and then the “select” or “ok” command needs to be sent. In order to make sure my cheap projector recognizes each command, I put a one-second delay between each. After the input source is selected, the Chromecast remote can be used to control Google TV from there. I set up a button card in Lovelace to that can be tapped to run this script and set up the projector. I also made another script that turns off the projector and retracts the projector screen.

Lovelace Buttons to Call the Scripts

To make this automation much simpler for anyone to use, I wanted trigger the whole sequence with a voice command. If you have Amazon Alexa integrated with Home Assistant, your Scripts will show up as Scenes in the Amazon Alexa app. You can create a simple automation in the Alexa app that triggers these scenes. I made a Routine that triggers the “Projector Setup” script when I say, “Alexa, time to watch a video.”. Then when we’re done watching, we can say “Alexa, turn off the projector” to run the “Projector Shutdown” script.

alias: Projector Setup
sequence:
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projectorscreen
      command: down
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projector
      command: power
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projector
      command: source
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projector
      command: right
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projector
      command: right
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: remote.send_command
    data:
      entity_id: remote.broadlink_rm4_pro_remote
      device: projector
      command: ok
mode: single
icon: mdi:projectorCode language: CSS (css)
alias: Projector Shutdown
 sequence:
 service: remote.send_command
 data:
   entity_id: remote.broadlink_rm4_pro_remote
   device: projector
   command: power
 service: remote.send_command
 data:
   entity_id: remote.broadlink_rm4_pro_remote
   device: projectorscreen
   command: up
 delay:
   hours: 0
   minutes: 0
   seconds: 1
   milliseconds: 0
 service: remote.send_command
 data:
   entity_id: remote.broadlink_rm4_pro_remote
   device: projectorscreen
   command: up
 mode: single
 icon: mdi:projector Code language: CSS (css)

Wrap-Up

To sum it up, I’m blown away that I can make my dumb projector and motorized screen into smart devices, and its nuts that they are controlled by one device. This device is super easy to set up and use, and I would highly recommend it for automating your projector setup. Thanks for reading, and if you’re a fan of my work, check out some of the other articles I’ve written or head over to my YouTube channel. See ya!