Record TV ON hours and display as barchartH

Goal: record number of hours the Tv is ON, and display a per day chart of the previous week.

TV ON/OFF is available through media_player.living_room_tv (LG). the data is more or less already there, but i’m stumped on how to get it translated to a per day chart.

I have set up a history sensor (today) but I’m not confident in that it will give me what I want.

- platform: history_stats
    name: TV_ON_Today
    entity_id: media_player.living_room_tv
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now().replace(hour=23, minute=59, second=59) }}'

I’ve also setup a Utility_meter based on the history sensor, but I’m perplexed wether it will give me what I want.

utility_meter:
  tvondaily:
    source: sensor.TV_ON_Today
    cycle: daily

Any pointers?

Your history stats sensor is correct.

Forget the utility meter.

Install the mini-graph custom Lovelace card and give it a config like this example:

Your recorder integration should be set up to retain at least 7 days. The default is 10 days so if you haven’t changed it you’re good.

Cool thanks.

I already use that component elsewhere, but for some reason its not fond of me
(I just coped the exact code into an empty card and replaced the sensor)
image

Throwing sensor.TV_ON_Today onto a mini-graph-card that worked previously just yields a blank card.

The example is for pasting into a Lovelace file, not a UI card.

Remove the leading “-” and adjust the indentation of each line 2 spaces to the left. title should be against the left margin and the relative indentation of the lines below should remain.

The formatting is correct, as it displays just fine if I switch out the sensor for another.
Gotta be something with the history stats sensor.

There are no capital letters in entity ids.

Jup, realized that. Thanks.

So far so good, I have a graph, and it displays data. but the bars don’t group by date. instead its grouped by 2 hours

image

  - type: 'custom:mini-graph-card'
    entities:
      - entity: sensor.tv_on_today
    name: TV Consumption
    hours_to_show: 168
    aggregate_func: max
    group_by: date
    show:
      graph: bar

Unless my eyes trick me, only the entity is different from the one in the docs.

I’m also only able to get the graph to work if its inside another control - like the swipe card in the picture - I wonder if there has been a breaking change that hasn’t been reflected in the docs yet - all the mini-graphs I have that are “standalone” are broken like this:

image

Got it - have had issues with HACS lately, and an much older version of the Graph card was still present in the resource file.

image

Thanks!

1 Like

You can set severity level colours too.
Example from one of my cards (low = blue, green, yellow, red = high)

color_thresholds:
  - color: '#e45e65'
    value: 7
  - color: '#e0b400'
    value: 5
  - color: '#0da035'
    value: 3
  - color: '#039BE5'
    value: 0
color_thresholds_transition: hard

Forgot to add the actual solution.

History on 2 tv’s and a combined sensor used to display a graph.

sensor:
  - platform: history_stats
    name: lrtv_on_today
    entity_id: media_player.q90tlr
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now().replace(hour=23, minute=59, second=59) }}'
  - platform: history_stats
    name: mbtv_on_today
    entity_id: media_player.samsungbedroom
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now().replace(hour=23, minute=59, second=59) }}'
  - platform: template
    sensors:
      tv_consumption:
        unit_of_measurement: "Hours"
        value_template: "{{ (states('sensor.lrtv_on_today') | float) + (states('sensor.mbtv_on_today') | float) }}"
        friendly_name: 'Combined TV Consumption'
1 Like