How to track tv time, shower duration and much more

I would like to provide the family with daily/weekly/monthly reports on all kind of topics like:

  • how much time the tv was on
  • time spent in the shower
  • energy usage
  • time in bed
  • distance traveled by car
  • etc. etc.

(I know I will not make myself popular :nerd_face:)

I guess I’m not the first wanting to do this. What is the best way to approach this? Are there any (custom) components that can help or do I really need to go down the road of all kind of input helpers and automations to calculate and reset measures?
I see similarities with the utility_meter component which has cycles and source sensors, but it doesn’t track time or other units.

Thanks in advance for your ideas!

Some of these can be done with this integration (the others can use the utility meter integration):

Note: as this uses your recorder database it can only track time periods as far back as your recorder purge keep days setting (default = 10 days).

Thanks, though I’m hoping for something more plug and play :grimacing:

1 Like

More plug and play than core integrations?

This is what I’ve recently setup in 3 steps to track the time the boiler is on:

1.- Create a sensor which accounts for the time some binary sensor is 'on’

sensor:
  - platform: history_stats
    name: Time Boiler On
    entity_id: binary_sensor.led_boiler
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

2.- Create a utility meter to reset the values daily, weekly, monthly,…

utility_meter:
  boiler_daily_usage:
    source: sensor.time_boiler_on
    cycle: daily

3.- Customize the utility so that you can benefit from the long-term statistics

homeassistant:
  [...]
  customize:
    # Add an entry for each entity that you want to overwrite.
    sensor.boiler_daily_usage:
      state_class: measurement

In this way, although my recorder saves the data for two days, you will have the mean, max and min values in the long-term statistics database.
I build this up one week ago and it is working nicely so far:
image

6 Likes

Thanks a lot Tim! Creative and close to what I had in mind!
@tom_l : I realize this is actually what you meant as well. I confused the history_status integration with the ‘history’ one.

One drawback I see is that it will be hard to measure based on multiple conditions? E.g. how long did the tumble dryer run during electricity peak tariff.

Yeah you need to set up template binary sensors for the composite ones.

@timseebeck thanks for the information. I set this up like you documented, but I can get the graph to work like you are showing. It looks like your “mean” amounts are somehow fluctuating, where as my “mean” hours seems to the the actual mean hours for the life of the data. Are you using a “statistical graph card” in your screen shot above? if so do you mind sharing a screenshot of the configuration of that graph? I must be doing something.

For my scenario I am tracking how long I am watching tv, so I really just want to see hrs tracked/tv on per day, it seems like for your screenshot that you have basically accomplished that with the logic you provided.

Thanks!

Hi Richard, sorry for the long silence. I don’t use that setup anymore (lots of things change in HA in one year). But let me explain what I use now.
This is a plot showing the number of hours per day my boiler is on:

image

What we need

  • A binary sensor that registers the state, in my case: binary_sensor.boiler_light
  • A history stats sensor sensor.tiempo_caldera_on (sorry, spanish) that registers the time the previous sensor is ‘on’:
sensor:
  - platform: history_stats
    name: Tiempo Caldera On
    entity_id: binary_sensor.boiler_light
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
type: custom:history-explorer-card
cardName: historycard-75569561
tooltip:
  showLabel: false
statistics:
  enabled: true
  mode: mean
defaultTimeRange: 3w
header: Time boiler ON
uiLayout:
  toolbar: top
  selector: hide
graphs:
  - type: bar
    title: ' '
    options:
      interval: daily
    entities:
      - entity: sensor.tiempo_caldera_on
        name: ''
        color: rgba(255,0,0,1)
        fill: rgba(255,0,0,0.15)

I hope it helps.

5 Likes

Thanks Tim!

This is more then I could have asked for in a response! I really appreciate you taking the time to lay this all out.

-Richard

icon

Almost 2 years after I created this topic… I wrote a custom integration that I’m really excited about. It easily measures all examples I mentioned in the topic start and much more!

I will create a new topic about this integration but before that I hope to find some interested beta testers in this topic.

Check it out: MeasureIt and let me know your thoughts!
To be installed via HACS, not yet in the standard HACS repo, so to be added as a custom repository in HACS.

After that go to Settings → Devices & Services → + Add integration
Search for MeasureIt and follow the config flow.

2 Likes

@danieldotnl
ready when you are to test, but where is documentation?:slight_smile:

1 Like

Yes thought the same… Code sounds good when checked, but I’m always afraid about stuff w/o even simple documentation and some print screen for example of usage.

Sorry guys, that took some time, but I finally created a proper topic about MeasureIt! :partying_face:

Check this out: MeasureIt: Measure all you need based on time and templates!