Setting Up Motion Sensor Counters in Home Assistant

I’ve been trying to set up a motion sensor counter in Home Assistant, and I wanted to share my journey and findings with the community. Motion sensors are fantastic for detecting activity, but sometimes you need more than just a simple on/off state. That’s where counters come in handy!

My goal was to create a system where the counter increments every time motion is detected and resets when the door is opened. Here’s the logic I wanted to implement:

variable: sensorCount = 0
Motion detected: sensorCount++
If sensorCount > 1 {
do something
}
DoorOpened: sensorCount = 0

After some research and trial and error, I found that using Home Assistant’s automation with variables and conditions was the way to go. I used a combination of templates and automations to track the motion events and reset the counter when the door opens. It took a bit of tweaking, but it finally worked!

One thing I learned is the importance of testing each part of the automation separately before putting it all together. For example, I tested the motion sensor detection first to ensure it was working correctly before moving on to the counter logic.

If anyone has similar questions or needs help setting up their own motion sensor counter, feel free to reach out! I’d be happy to share more details or troubleshoot any issues you might encounter.

Happy automating! :rocket: