Tracking total time of presence in a month, with some complications


I am would like to create a sensor which will at the end of the calendar month contain the amount of time the nanny spent in our house, to help me pay her right for when she stays longer.

Her phone connects to the network, so I am tracking when she is present, so in the end I need to do some stats on person.nanny.

The problem is that she goes in and out durign the day, her phone sometimes disconnects etc, so I am interested in ony tracking the time between her first appearance and her last in that day. My idea is as follows:

  • Have an automation write the current time into an input_datetime.first whenever person.nanny goes from off to on. Condition this on an input_boolean.not_here_yet which will get set to false once this automation gets triggered and reset back to on at midnight
  • Have an automation write the current time into an input_datetime.last whenever person.nanny goes on to off.
  • have a template sensor sensor.nanny_hours tracking the time difference between input_datetime.last and input_datetime.first, with some logic to set it to zero after midnight
  • have a history sensor sum the total sensor.nanny_hours since the first day of the month

Is this optimal? Or is there some smarter way of doing it (e.g. just with a template sensor with some triggers?)

Thanks for suggestions!

The default recorder purge days is 10. So you would have to keep 31 days if you want to use the history stats integration.

Ah so maybe another automation at midnight to add the day’s time to some monthly total in another input_number? or template sensor?

In my opinion it seems fragile.
I wouldn’t want my boss to base my salary on if my phone connects to a wifi and/or if I have my phone with me and/or it’s charged enough to last the full day.

And this is not mentioning any issues in HA, like restarts, failed automation so that the time for a day is not saved.
Or even router issues, and/or internet connection. If your internet is down the nanny will probably disconnect from the wifi and use 2/3/4/5G.

Honestly, it’s to track the afterhours for my own benefit – she is being paid fixed plus and tracking it herself. But I don’t like the construction either which is why I’m trying to think of something less complicated. Any my internet is never down! :wink: