A couple of months ago I had a nasty problem in my studio. My studio smelled like a dead animal. When I went to investigate I found out that I had a mouse infestation in my ceiling. Since it’s a tough place to check, I decided to see how I could use Home Assistant to create a smart mouse trap. I succeeded. And it’s super simple!
⭐⭐⭐ NOTE: ⭐⭐⭐
This article accompanies a YouTube video. I wrote it for people who would rather read than watch a video. In order to keep doing this, I would like to ask you to also check out the video, leave a comment under the video, give the video a thumbs up and subscribe to my YouTube channel. This means that the video is offered more often to new visitors so that they also stay informed of the latest Home Assistant tutorials.
Thank you for your support!
When I found out that I had a mouse infestation in my ceiling I was not happy. The issue was so big that I had to remove my ceiling and needed to replace it entirely. Using poison is no longer allowed in our country and is not the best way either. Mice will rot when they die of poison and you don’t know where they are when they are dead. And besides, I think it’s a bit sad to kill them and I’d rather catch them alive.
So I decided to create a simple solution to catch mice and get notified by Home Assistant as soon as they are trapped.
But before we start, please do me a favor and smash the thumbs-up button for this video and subscribe to my channel. This way you make sure that I can keep creating these videos for you.
Create the physical Smart Mouse Trap
I use these mouse traps for a while now. They are effective and the mechanism is very simple. I wanted to create a simple solution to automate this mouse trap. First, I was thinking of attaching a door sensor to this mouse trap so that I could detect if the sensor contact was opened, but it turned out that it was too bulky to use. Because of that, I decided to use a vibration sensor. I used double-sided tape to stick the vibration sensor to the tilt mechanism of the mousetrap. When the mouse is entering the trap, the tilt mechanism will trigger the vibration sensor and this can be handled within Home Assistant. You do not have to use this specific mouse trap of course. I think a vibration sensor works on almost all mouse trap models, including the ones that will kill the mice.
If you have other ideas for creating a DIY mouse trap, please let me know your ideas in the comments below! I think using ESPHome might be an option too if you have power around your mouse trap, but I needed to use a battery-powered device because of the location of the trap.
Now that our mouse trap is created, we have to create an automation, a dashboard card, and a notification on our phone to get notified when a mouse is trapped. I also want to reset the status after I removed the mouse from the trap.
Create the Helper
We’ll start by creating a toggle helper in Home Assistant to save the state when a mouse is trapped or not.
- For this, go to Settings.
- Go to Devices & Services.
- Click on the Helpers tab.
- Click Create Helper.
- Select the Toggle Helper.
- Give the helper a name.
- Select the icon. In my case, it’s mdi:rodent.
- Click Create.
This helper will be set to On when a mouse is detected and will be set to Off if we reset the status.
Create the automation for our smart mouse trap
The vibration sensor is a Zigbee device and it’s connected to Home Assistant using Zigbee2MQTT or ZHA. If you’d like to know how you can connect Zigbee devices to Home Assistant using Zigbee2MQTT, then check this video on how to set this up. If you’d like to know how you can connect Zigbee devices to Home Assistant using ZHA, then check out this video. We want to get notified if a mouse enters the trap. I want to see a notification on my dashboard and I want to get a message on my phone. To get this to work, we need an automation.
- Go to Settings.
- Go to Automations & Scenes.
- Click Create Automation.
- At trigger select your Vibration Sensor.
- The trigger is something like “starting detecting motion”. It depends on your device and if you use Zigbee2MQTT or ZHA what the exact trigger will be.
- Then go to Actions.
- What I’m going to do here is turn on the helper we just created. We will check the status of this helper in the dashboard card that we are going to create later.
- Click Add Action.
- Select Call Service.
- Select Input boolean: Turn On in the service field.
- and select our helper with the name Mouse Detected as our entity.
Next to this, I want to receive a message on my phone that a mouse is detected. So we’re going to click on Add Action again.
- Select Call Service.
- Select the service that sends a notification to your phone. it starts with “Notifications:” and contains the name of your phone.
- Enter a message in the message field
- and enter a title in the title field.
- Click Save.
Create the dashboard card for our smart mouse trap
Our automation is now ready. It will toggle our helper and it will send us a message. The only thing that we have to add now is a dashboard card that is only visible when a mouse is detected. I like to show this message only when a mouse is detected in my messages area in my dashboard. This video explains how to set up a perfect dashboard that has a specific message area where you can show these messages. Check it out!
Now go to one of your dashboards and click on the three dots in the right upper corner.
- Click Edit Dashboard.
- Click Add Card.
- Select the Conditional Card.
- Select the Mouse detected Helper in the entity field.
- Enter “on” in the State field.
- Now click on the CARD tab.
- Select the Tile Card.
- Select the Helper Mouse Detected in the entity field
- At Actions select Toggle in the Tap Action field.
- Click Save.
- Click Done.
You don’t see the card because the status of the Toggle helper is set to Off. If the mouse enters the trap, the automation is activated because the vibration sensor detects movement. At that point, the card appears on the dashboard because the condition in the conditional card has been met. The toggle helper will be set to “Off” if you click on the card, so the card will be hidden again.
You can type the code from the screen or download the code I used in this video from the link in the description. This saves you time and frustration plus you support me so that I can continue to make these tutorials. By supporting me, you also support my study to become a music therapist to help people with mental issues.
This was a fairly simple way to make your dumb mouse trap smart. I hope it inspired you to create your own automations using vibration or other sensors. Let me know in the comments if you created a mouse trap yourself and how you automated it!
I was able to create this tutorial thanks to these people. They sponsor me because they find these videos valuable. I rely entirely on sponsorship to be able to make these tutorials for you and I can’t keep doing this without your help. Thank you for this. If you want to sponsor me too, you can do so through Patreon, Ko-Fi, or by joining my channel. This allows me to pay for my groceries and continue to make these tutorials for you. And don’t forget to give this video a thumbs up, subscribe to my channel, and hit the notification bell.