Track hours I'm at work?

I was wondering if anyone knows how I could track my hours I spend at work and put them into a data base or excel sheet with Home Assistant?

briefly glancing at the device tracker component, it logs zone enter/exit and in the state history keeps track of when the state change happens. Also on the history tab it has a running total how long (for the current day only) the device has been in that location. I was hoping I could do a template and grab the value but I was unsuccessful. I’m wondering if something like Owntracks may be a little better for this?

Anyone ever find anything for this? I basically just want it to track the hours I’m in my work zone then give a summary of hours per week…

sensor:
  - platform: history_stats
    name: Time at work (this week only)
    entity_id: device_tracker.me
    state: 'Work'
    type: time
    start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
    end: '{{ now() }}'

I track my commutes to and from work using zones, and then use IFTTT to write my starting zone and ending zone and the time it took to get from one place to another. I’m sure you could use the same concept to keep start time as the time you entered your work zone and end time as the time you left your work zone. In IFTTT I have a log to google spreadsheet which tracks the times. Again, not the full solution, but I feel like all the parts are there for you to get what you need

- alias: "Leave any zone"
  trigger:
  - platform: state
    entity_id: device_tracker.paul_all
    to: 'not_home'
  condition:
  - condition: numeric_state
    entity_id: sensor.ha_runtime_in_minutes
    above: 1  
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.leave_any_zone.attributes.last_triggered) | int > 120 }}'
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.commute_start_time
      value: '{{ as_timestamp(now()) }}'
  - service: input_text.set_value
    data_template:
      entity_id: input_text.commute_start_zone
      value: '{{ trigger.from_state.state }}'

- alias: "Enter any zone"
  trigger:
  - platform: state
    entity_id: device_tracker.paul_all
    from: 'not_home'
  condition:
  - condition: numeric_state
    entity_id: sensor.ha_runtime_in_minutes
    above: 1  
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.enter_any_zone.attributes.last_triggered) | int > 120 }}'
  - condition: template
    value_template: "{{ states('input_text.commute_start_zone') != states('device_tracker.paul_all') }}"
  action:
  - service: ifttt.trigger
    data_template:
      event: CommuteLog
      value1: '{{ states("input_text.commute_start_zone") }}'
      value2: '{{ states("device_tracker.paul_all") }}'
      value3: '{{ ((as_timestamp(now()) - (states("input_number.commute_start_time")|int))/60)|round }}'
  - service: script.sms_notify_with_images
    data_template:
      service: notify.sms_paul
      condition: "{{ is_state('input_boolean.notify_paul','on') }}"
      title: "Commute Logged"
      message: "Your commute from {{ states('input_text.commute_start_zone') }} to {{ states('device_tracker.paul_all') }} took {{ ((as_timestamp(now()) - (states('input_number.commute_start_time')|int))/60)|round }} minutes"

Edit: actually if you change the 1st Trigger to
to: ‘WORK ZONE’

and the second trigger to
from: ‘WORK ZONE’

you should get what you need.

Of course you’ll need to set up the appropiate input number, and input text, and the IFTTT trigger, etc

Awesome, thanks!