Logging a persons whereabouts

Hi there,

As a cross border commuter I need to file my whereabouts every year to both the tax agencies in both the country of residence and the country I work in. My thought was that it may be possible to automate in HA, since it already has my tracking.

I found the File integration, which I would like to write to a log file, whenever my Person enters some predefined Zones in my working country. All the rest working days will be assumed working from my country of residence.

My goal would be to:

  1. Trigger when my person has been in a zone for more than 4 hours
  2. Write the log to a File: timestamp and name of zone

I tried to write an automation, but this is a bit over my current knowledge to get it to work.

alias: Whereabout
description: ''
trigger: // not sure how to add the minimum time in a specific zone
  - platform: zone
    entity_id: person.john_doe
    zone: zone.work_office_a
    event: enter
  - platform: zone
    entity_id: person.john_doe
    zone: zone.work_office_b
    event: enter
condition: []
action:
  - service: notify.john_does_whereabout //Using the File integration
    data:
      message: '{{person.john_doe}}' //Not sure how to fetch the persons current zone name as variable?
mode: single

Anyone able to help me getting this automation progressed? Or does there exist better ways of doing so? All input is appreciated thanks. :slight_smile:

Hi, being a cross-boarding person too… this data will not be accepted by the authorities as this is not formally accepted as a source of truth and (you do know this) this can be manipulated easily.
If you only want it for reporting, the data can be stored in a long-term db (e.g. influx) and used for reporting from their on…check e.g. for influx in other posts

EDIT: I cross French-Swiss boarder and never needed to prove my whereabouts…which country is asking you to do so?

Hi @vingerha

I believe here they are satisfied with somekind of “statement of truth” here. I’m crossing Denmark and Sweden. Sweden asked for prove on my tax year 2020 they accepted an excel sheet template made by Danish tax authorities, which was based on my own excel sheet extracted from Google Maps.

Luckily Google Maps tracked all my locations when I needed it, at that time, but it also worried me what they logged so much, so I turned off Maps tracking. Instead I will use my HA.

Sounds as a good idea to use Influx. Actually I did install it for some month ago for other reasons, but seems like it’s worth take a look into how it can solve my use case.

I use an Automation to log my daily/monthly energy usage to a CSV file via a file notify group, I think you should be able to achieve what you want using this technique with the triggers you have defined above.

- alias: Daily Energy Usage
  description: ''
  trigger:
  - platform: time
    at: 00:01:00
  condition: []
  action:
  - service: notify.energy_log
    data:
      message: '{{ states(''sensor.date_time'') }};Daily;{{ state_attr(''sensor.energy_usage_day_std'',
        ''last_period'') }};{{ states(''sensor.energy_cost_last_day'') }} '
  - condition: template
    value_template: '{{ now().day == 1 }}'
  - service: notify.energy_log
    data:
      message: '{{ states(''sensor.date_time'') }};Monthly;{{ state_attr(''sensor.energy_usage_month_std'',
        ''last_period'') }};{{ states(''sensor.energy_cost_last_month'') }} '
  mode: single

This is the associated notify group that is required for the service calls:

- name: energy_log
  platform: file
  filename: /config/www/csv_logs/energy_log.csv
  timestamp: false

This is what the output looks like:

2022-04-01, 00:01;Monthly;1237.5;184.38
2022-04-02, 00:01;Daily;39.1;5.83
2022-04-03, 00:01;Daily;42.7;6.36
2022-04-04, 00:01;Daily;40.2;5.99
2022-04-05, 00:01;Daily;39.6;5.9
2022-04-06, 00:01;Daily;32.5;4.87
2022-04-07, 00:01;Daily;34.8;5.2
2022-04-08, 00:01;Daily;33.7;5.04
2022-04-09, 00:01;Daily;35.7;5.34
2022-04-10, 00:01;Daily;40.6;6.05
2022-04-11, 00:01;Daily;35.4;5.29
2022-04-12, 00:01;Daily;46.7;6.94
2022-04-13, 00:01;Daily;16.0;2.46
2022-04-14, 00:01;Daily;10.2;1.61
2022-04-15, 00:01;Daily;12.6;1.96
2022-04-16, 00:01;Daily;35.2;5.26
2022-04-17, 00:01;Daily;27.5;4.14
2022-04-18, 00:01;Daily;32.4;4.85

I have setup reporting for my AC/Heating so that it does something similar to what you’re trying to achieve, I guess.
It measures how long both of my AC/Heating zones are running throughout the day and adds this info to the end of a csv file at midnight.

In order to do that I set up a few sensors, which I think could be replicated with location info/zones.

#######################################################################
# Turn 'fan on' into true/false for stats
#######################################################################
- platform: template
  sensors:
    s_w_fanon4stats:
      value_template: >-
        {%- if states.climate.s_w_thermostat.attributes.hvac_action == 'heating' -%}
          true
        {%- elif states.climate.s_w_thermostat.attributes.hvac_action == 'cooling' -%}
          true
        {%- else -%}
          false
        {%- endif -%}
- platform: template
  sensors:
    l_e_fanon4stats:
      value_template: >-
        {%- if states.climate.l_e_thermostat.attributes.hvac_action == 'heating' -%}
          true
        {%- elif states.climate.l_e_thermostat.attributes.hvac_action == 'cooling' -%}
          true
        {%- else -%}
          false
        {%- endif -%}
#######################################################################
# Since Midnight Fan Stats
#######################################################################
- platform: history_stats
  name: S&W Fan On Since Midnight in h
  entity_id: sensor.s_w_fanon4stats
  state: 'true'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'
- platform: history_stats
  name: L&E Fan On Since Midnight in h
  entity_id: sensor.l_e_fanon4stats
  state: 'true'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

The above could probably be easily adjusted to how long you are in a specific zone.

The below is the definition of the notification method in my configuration.yaml:

notify:
  - platform: file
    name: daily_fan_run_time
    filename: daily_fan_run_time.csv
    timestamp: False

And every day at midnight I write the info to the csv file:

alias: 'Write to File - Daily Fan Run Time '
description: ''
trigger:
  - platform: time
    at: '23:59:59'
condition: []
action:
  - service: notify.daily_fan_run_time
    data_template:
      message: >
        {{ now().strftime('%d/%m/%Y') }},  {{
        states.sensor.s_w_fan_on_since_midnight_in_h.state }},  {{
        states.sensor.l_e_fan_on_since_midnight_in_h.state }}
mode: single

This results in a csv-file looking like this:
image

Added bonus:
For my analysis I’m linking the csv file directly from the HA config folder (via Samba) as a source into my Power BI Dashboard: