Tracking work hours manually can be tedious. As a System Engineer who loves automation, I’ve streamlined this process using Home Assistant, zones, and the Clockify API. Here’s how I automatically log my work hours when I arrive at or leave my office, leveraging Home Assistant automations and Clockify’s API.
Why Automate Time Tracking?
Manual time tracking is easy to forget. By automating this with Home Assistant and Clockify, I ensure my timesheets are accurate and up-to-date, with zero manual intervention. This setup is especially useful because I move between multiple office locations and want a seamless integration with my smart home/work environment.
How It Works: The Concept
- Zones in Home Assistant: Definition of the office locations as zones. When I enter or leave these zones, Home Assistant triggers automations.
- Clockify API: Usage of Home Assistant’s REST commands to start or stop a timer in Clockify, logging my work hours automatically.
- Notifications: Instant feedback on my phone when a timer starts or stops.
+------------------+ (1) Enter/Leave Zone +-------------------+
| |------------------------------------->| |
| Phone | | Home Assistant |
| (Location App) |<-------------------------------------| (Automations) |
+------------------+ (4) Notification +-------------------+
| |
| |
| |
v v
+-------------------+ +-------------------+
| | | |
| Clockify API |<-------------| REST Command |
| (Start/Stop Timer)| (2,3) | Integration |
+-------------------+ +-------------------+
Legend:
- Phone detects entry or exit from a defined work zone and updates Home Assistant.
- Home Assistant automation triggers a REST command to Clockify API to start or stop a timer.
- Clockify logs work session.
- Home Assistant sends a push notification to the phone confirming the action.
Setting Up the Automation
- Definition of the Zones
In Home Assistant, I configured my zones for office locations (e.g., zone.work1, zone.work2). This was done via the UI under Settings > Areas & Zones, where new zones can be configured, their coordinates, and their radius.
- Home Assistant Automations This was done via the UI under Settings > Automations. Here are the automations I use:
Start Timer When Entering a Work Zone
alias: Clockify - Start Timer at Work Zones
triggers:
- entity_id: person.david
zone: zone.work1
event: enter
trigger: zone
- entity_id: person.david
zone: zone.work2
event: enter
trigger: zone
actions:
- data:
start_time: "{{ now().isoformat() }}"
description: Work @ Office
project_id: 684055c531f323308c6d2783
action: rest_command.clockify_start_time_entry
- data:
title: ⏱️ Clockify
message: Timer started for 'Work at Office' 🏢
action: notify.mobile_david
mode: single
Stop Timer When Leaving a Work Zone
alias: Clockify - Stop Timer Leaving Work Zones
triggers:
- entity_id: person.david
zone: zone.work1
event: leave
trigger: zone
- entity_id: person.david
zone: zone.work2
event: leave
trigger: zone
actions:
- data:
end_time: "{{ now().isoformat() }}"
action: rest_command.clockify_stop_time_entry
- data:
title: ⏹️ Clockify
message: "Timer stopped after leaving Work."
action: notify.mobile_david
mode: single
- REST Commands for Clockify API
I added these to
configuration.yaml
to interact with the Clockify API:
rest_command:
clockify_start_time_entry:
url: "https://api.clockify.me/api/v1/workspaces/****/time-entries"
method: POST
headers:
X-Api-Key: !secret clockify_api_key
Content-Type: "application/json"
payload: >
{
"start": "{{ start_time }}",
"billable": false,
"description": "{{ description }}",
"projectId": "{{ project_id }}"
}
clockify_stop_time_entry:
url: "https://api.clockify.me/api/v1/workspaces/****/user/****/time-entries"
method: PATCH
headers:
X-Api-Key: !secret clockify_api_key
Content-Type: "application/json"
payload: >
{
"end": "{{ end_time }}"
}
Tip: The Clockify API key securely stored in secrets.yaml
.
How It All Comes Together
When I arrive at the office, my phone’s location updates Home Assistant, which triggers the automation to start a timer in Clockify.
When I leave, another automation stops the timer, ensuring my work hours are accurately logged.
I receive push notifications on my phone, so I always know when the timer starts or stops.
Why This Approach?
- Accuracy: No more forgotten time entries.
- Simplicity: Once set up, it’s completely hands-off.
- Integration: Works seamlessly with other Home Assistant automations and smart home devices.
Further Customization
This setup can be extend to:
- Track time in multiple locations or projects.
- Add conditions (e.g., only track during business hours).
- Integrate with other tools via Home Assistant or platforms.
- Use smart devices, to monitor work @Home
Conclusion
Automating time tracking with Home Assistant and Clockify saves time, reduces errors, and lets me focus on work, not my timesheet. 😊 I’m already using Home Assistant for other automations, so it was a natural next step to integrate my work life into my smart home ecosystem.