I created a really cool presence-tracking project over the weekend using my Shelly Presence Gen4 sensor. It turned out pretty awesome ![]()
!
Step-by-step overview
- Sensor used: https://www.shelly.com/products/shelly-presence-gen4-white
- Created a new user in Home Assistant to be used by the MQTT broker.
- Installed the Mosquitto Broker app and logged in using the newly created username.
- Enabled the MQTT protocol through the local web interface on the Shelly Presence Gen4 sensor and connected it to the MQTT broker.
- Added the MQTT integration in Home Assistant, created a new device, verified that the MQTT topics were being received correctly, and then created a new entity.
- Created a couple of Helper buttons for switching between tracking sessions, plus buttons for starting, pausing, ending, and restarting the animation.
- Installed Plotly Graph Card and generated the YAML/code for it using Claude.ai.
High-level overview of the Plotly Card YAML
-
Reads my sensor history - it pulls the last 48 hours of data from my presence sensor. Each reading contains information about where an object was detected and how tall it measured.
-
Splits the history into separate walks/sessions - a new session starts whenever there is a gap of more than 20 seconds or when a continuous stretch exceeds 3 minutes. It keeps the last 10 sessions, ordered from newest to oldest.
-
Separates individual objects - points are grouped by object
id, so if two people or cars are moving at the same time, they appear as two separate paths instead of one confusing zig-zag. -
Draws a top-down map - I use a rotated diamond-style view where each path is shown as a green-to-amber gradient line, with the color indicating the direction of travel. It also includes dots for each measured point, arrows showing heading, Start/End markers, the sensor location, and reference shapes for Parking area, House, Parking area II, and Tree.
I had to do a lot of walking around the area and go through several iterations to get the object positions visualized properly. Very much a trial-and-error approach
-
Shows session statistics - in the top-left it displays the selected session, its start time, and duration. In the top-right it shows the number of points, the number of detected objects, and the P95 height - roughly the tallest the object measured while ignoring extreme outliers.
-
Animates the tracked path on demand - I select a session at the top, which is shown in full by default, and then use Play / Pause / End / Restart to animate the path at approximately real walking speed. It also shows a countdown of the remaining playback time.
-
Remembers playback progress - because the card reloads every couple of seconds, it stores the animation state and progress in the browser. This means Play/Pause/Resume can survive card refreshes.
-
Uses
refresh_intervalas the animation heartbeat - this controls how often the card redraws and re-checks Home Assistant. In practice, it also acts as the animation frame rate, which is why smoother animation gets very heavy on mobile.I tried running it at around 25 FPS, but it was way too much for my phone - an iPhone 17 Pro Max
. Everything basically froze and the animation took over the whole phone
.So I reduced it to 1 FPS (which is also the speed at which the sensor transmits data). I even tried creating a completely custom Home Assistant card as an alternative, but the results were similar. Surprisingly, even at 1 FPS the animation still looks great and does a pretty good job of mimicking the speed of someone walking (I took this into account using event data timestamps).
-
Created a push notification when presence is detected - it sends a critical notification to my phone
and deep-links directly to the Home Assistant Dashboard containing the Plotly card.
One thing I had to troubleshoot 
One issue I ran into was keeping the sensor “alive” whenever presence was detected. Otherwise, some tracking sessions would simply go missing
.
To solve this, I created a Home Assistant automation that keeps the sensor active while presence is detected, so it doesn’t drop the tracking stream. The automation is gated by presence, meaning I only “nag” the sensor to stream out data via MQTT while there is actually someone or something to track.
I built this entire project from scratch using Claude.ai
.
Without AI, I probably would have spent weeks manually coding everything and trying to figure out how all the pieces fit together. Claude gave me simple step-by-step instructions, which I then manually refined through a lot of testing and experimentation.
The whole project probably took me around 12 hours in total, plus some paid Claude tokens
because I was way too excited to wait, lol.
This was actually my first-ever Home Assistant project, so I decided to share it with everyone and hopefully give something back to the community. Thanks!
I’m extremely happy with how it turned out, and I’m also genuinely impressed by how well the Shelly Presence Gen4 performs
. I’m using the default firmware and connecting it over Wi-Fi.
The off-the-shelf software really doesn’t show what this sensor is actually capable of doing.
The one thing I would still love to improve is the smoothness of the tracking animation on mobile
. On desktop it works like a charm, although it does generate quite a lot of network traffic.
On mobile, however, smoother animation basically freezes everything else. While the Card is on with high fps, I can’t use any other Home Assistant buttons inside the app.
I tried a lot of different approaches to solve this, but so far nothing has really worked. Buh
.
Still, even with the animation limited to 1 FPS, I’m really happy with the final result
.




