Skip to content

Master Your Schedule: The Ultimate 2026 Guide to Home Assistant Time Tracking with Google Calendar

22/04/2026

Updated on April 22, 2026

In the world of smart homes, Home Assistant presence detection is one of the most powerful tools in your arsenal. In this definitive 2026 guide, we’re taking it to the next level: we’ll build a complete time tracking system using Home Assistant and Google Calendar. The goal is to automatically log an event every time you enter or leave a predefined zone (like work, school, or the gym) and, crucially, to quantify the total time spent there.

This project isn’t just a fun technical challenge; it unlocks a ton of practical applications, from optimizing your daily routines to creating a fully automated, location-based access control system. Let’s dive in!

What You’ll Need (Prerequisites)

Before we get started, make sure you have the following ready to go in your Home Assistant setup:

  • An up-to-date Home Assistant instance: It’s crucial to be on a recent version of Home Assistant (2026.x) to ensure all components are compatible.
  • The Home Assistant Companion App: Installed and configured on the smartphones of the people you want to track. This is the most reliable method for location tracking.
  • Defined Zones: You must have already created the geographic zones you want to monitor (e.g., “Home,” “Work,” “School”).
  • Configured Person entities: Each person should have their own person entity associated with their tracking device.
  • Google Calendar Integration: You’ll need the Google Calendar integration up and running. If you haven’t set it up yet, I recommend following my complete guide to integrating Google Calendar with Home Assistant.

Step 1: Create Your Time & Visit Counter Sensors

First, we need to create the sensors that will measure and store the time each person spends in a specific zone. We’ll use the powerful History Stats integration to do the heavy lifting and some template sensors to format the data nicely.

Add the following code to your configuration.yaml file. Remember to replace person.albert with your person’s entity and school with the exact lowercase name of your zone.

Time-in-Zone Sensors (History Stats)

# configuration.yaml

sensor:
  # Sensor to track hours in the "school" zone for "albert"
  - platform: history_stats
    name: "Time at School Today"
    entity_id: person.albert
    state: "school"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: "Time at School This Week"
    entity_id: person.albert
    state: "school"
    type: time
    start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0, microsecond=0)) - now().weekday() * 86400 }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: "Time at School This Month"
    entity_id: person.albert
    state: "school"
    type: time
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

Visit Count Sensors (History Stats)

Similarly, we can count how many times a zone has been entered. This is great for weekly or monthly summaries.

# configuration.yaml (continued under the sensor: section)

  - platform: history_stats
    name: "Visits to School Today"
    entity_id: person.albert
    state: "school"
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: "Visits to School This Week"
    entity_id: person.albert
    state: "school"
    type: count
    start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0, microsecond=0)) - now().weekday() * 86400 }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: "Visits to School This Month"
    entity_id: person.albert
    state: "school"
    type: count
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

Once you’ve added the code, save the file and restart Home Assistant. Your new sensors will now appear as entities.

Step 2: Build the Automations to Log Events in Google Calendar

Now that we have the data, it’s time to build the Home Assistant zone automations. We’ll create four automations: one for logging arrivals, another for departures, and two more to send weekly and monthly summaries to the calendar.

You can create these automations via the UI (under Settings > Automations & Scenes) or by adding the following YAML to your automations.yaml file.

Heads-up: Be sure to replace person.albert, zone.school, and especially YOUR_CALENDAR_ID@group.calendar.google.com with your own values.

# automations.yaml

- id: '1633684973186_updated_2026'
  alias: 'Time Tracking - Arrival at School'
  description: 'Creates a Google Calendar event upon entering the school zone'
  trigger:
    - platform: zone
      entity_id: person.albert
      zone: zone.school
      event: enter
  condition: []
  action:
    - service: google.add_event
      data:
        calendar_id: 'YOUR_CALENDAR_ID@group.calendar.google.com'
        summary: '✅ Arrived at School'
        description: "Entered 'School' zone at {{ now().strftime('%-I:%M %p') }}."
        start_date_time: '{{ now() }}'
        end_date_time: '{{ now() + timedelta(minutes=5) }}'
  mode: single

- id: '1633686513021_updated_2026'
  alias: 'Time Tracking - Departure from School'
  description: 'Creates a Google Calendar event upon leaving the school zone'
  trigger:
    - platform: zone
      entity_id: person.albert
      zone: zone.school
      event: leave
  condition: []
  action:
    - service: google.add_event
      data:
        calendar_id: 'YOUR_CALENDAR_ID@group.calendar.google.com'
        summary: '❌ Departed from School'
        description: "Left 'School' zone at {{ now().strftime('%-I:%M %p') }}. Total time today: {{ states('sensor.time_at_school_today') | float(0) | round(2) }} hours."
        start_date_time: '{{ now() }}'
        end_date_time: '{{ now() + timedelta(minutes=5) }}'
  mode: single

- id: '1633689084156_updated_2026'
  alias: 'Time Tracking - Weekly School Summary'
  description: 'Sends a summary of time at school at the end of the work week'
  trigger:
    - platform: time
      at: '21:30:00'
  condition:
    - condition: template
      value_template: '{{ now().isoweekday() == 5 }}' # Runs on Friday (5)
  action:
    - service: google.add_event
      data:
        calendar_id: 'YOUR_CALENDAR_ID@group.calendar.google.com'
        summary: 'Weekly School Summary'
        description: >
          This week's stats: {{ states('sensor.visits_to_school_this_week') }} visits to school, 
          for a total of {{ states('sensor.time_at_school_this_week') | float(0) | round(2) }} hours.
        start_date_time: '{{ now() }}'
        end_date_time: '{{ now() + timedelta(minutes=5) }}'
  mode: single

- id: '1633689372804_updated_2026'
  alias: 'Time Tracking - Monthly School Summary'
  description: 'Sends a summary of time at school on the last day of the month'
  trigger:
    - platform: time
      at: '22:00:00'
  condition:
    - condition: template
      value_template: '{{ (now().date() + timedelta(days=1)).day == 1 }}' # Runs on the last day of the month
  action:
    - service: google.add_event
      data:
        calendar_id: 'YOUR_CALENDAR_ID@group.calendar.google.com'
        summary: 'Monthly School Summary'
        description: >
          This month's stats: {{ states('sensor.visits_to_school_this_month') }} visits to school,
          for a total of {{ states('sensor.time_at_school_this_month') | float(0) | round(2) }} hours.
        start_date_time: '{{ now() }}'
        end_date_time: '{{ now() + timedelta(minutes=5) }}'
  mode: single

I’ve tweaked these automations to make the calendar events more descriptive, using emojis and templates to dynamically add info like the time of day or the total accumulated hours.

Step 3: Visualize Your Data on a Dashboard

Having the data is great, but seeing it right on your Home Assistant dashboard is even better. You can use a simple Entities Card to display the current values.

Edit your dashboard, add a new card, and select “Manual.” Then, paste in the following YAML:

type: entities
title: Time Tracking - School
entities:
  - entity: person.albert
  - entity: sensor.time_at_school_today
    name: Time Today (Hours)
  - entity: sensor.visits_to_school_today
    name: Visits Today
  - type: divider
  - entity: sensor.time_at_school_this_week
    name: Time This Week (Hours)
  - entity: sensor.visits_to_school_this_week
    name: Visits This Week
  - type: divider
  - entity: sensor.time_at_school_this_month
    name: Time This Month (Hours)
  - entity: sensor.visits_to_school_this_month
    name: Visits This Month

For a more advanced view, you can use the history-graph card to see a presence chart throughout the day:

type: history-graph
title: Presence History Graph - School
entities:
  - entity: person.albert
hours_to_show: 24
refresh_interval: 60

Practical Use Cases: Beyond Just Time Tracking

Combining presence detection with time logging opens up a world of possibilities. Here are a few ideas to get you started:

Use CaseDescription
Parental Peace of MindGet a notification and a log on the family calendar when your kids arrive at or leave school, extracurriculars, or a friend’s house.
Automated Work Time ClockIf you work in-office or have a hybrid schedule, automatically log your arrival and departure times. Perfect for freelancers or just for personal record-keeping.
Smarter Energy SavingsWhile it doesn’t log to the calendar, the same “leave zone” logic can be used to turn off lights, set the thermostat to “Away” mode, and power down devices when the last person leaves home.
Effortless Habit TrackingCreate a zone for your gym and automatically track how many times you go per week and how long you spend there each session.

A Critical Note on Privacy and Security

It’s essential to talk about privacy. One of the biggest advantages of using Home Assistant is that your location data is processed and stored locally on your own server. It isn’t sent to third-party clouds, except in cases you explicitly configure—like this Google Calendar integration.

You have total control over what data is shared and with whom. To maintain security, I strongly recommend hardening your Home Assistant instance. If you expose your system to the internet, make sure you’re using a secure connection (HTTPS), strong passwords, and two-factor authentication (2FA) if possible. For an extra layer of protection, consider segmenting your home network.

Troubleshooting Common Issues

If things aren’t working as expected, here’s a quick checklist for the most common problems:

  • Inaccurate or Delayed Location Tracking:
    • In your phone’s settings, ensure the Home Assistant Companion app has location permissions set to “Always Allow” and has access to “Precise Location.”
    • Disable battery optimization for the app (especially on Android).
    • In Home Assistant, go to Settings > Areas & Zones and consider slightly increasing the zone’s radius to compensate for minor GPS drift.
  • Events Not Showing Up in Google Calendar:
    • Double-check that the calendar_id in your automations is correct.
    • Go to Settings > Devices & Services, find the Google integration, and try reloading it. If that doesn’t work, you may need to re-authenticate it.
    • Check the Home Assistant logs (Settings > System > Logs) for any errors related to the google.add_event service call.
  • History Stats Sensors Show ‘0’ or ‘Unknown’:
    • Verify that the person’s entity_id and the state name (the zone in all lowercase) are correct in your configuration.yaml.
    • The history integration must be enabled (it is by default). If you’ve disabled it for some reason, these sensors won’t function.
    • Remember to restart Home Assistant after making any changes to configuration.yaml.

With this guide, you’ve now configured an incredibly robust and customizable time and presence tracking system, all while keeping privacy at its core. Now it’s your turn to experiment and adapt it to your life!