Using Grafana, InfluxDB or anything else to visualize how long I'm watching Apple TV

I’m trying to visualize how long I’m watching Apple TV and ideally what sources I am using (Vikki, Netflix, etc). Trying to create a healthy reminder that the answer is “too much”.

I’ve set up InfluxDB and can see information flowing into it. Here is my configuration:

influxdb:
  host: a0d7b954-influxdb
  port: 8086
  database: homeassistant
  username: homeassistant
  password: homeassistant
  max_retries: 3
  default_measurement: state

I’ve also set up Grafana and can see the InfluxDB info flowing into that.

Where I’m struggling is that I’m a n00b on both of these technologies and could use help on creating the proper query with the appropriate plugin to visualize an answer to the following questions:

  • In the past [week|month], how many hours have I watched Apple TV?
  • In the past [week|month], what % of time was spent in what apps?

I’m guessing that somehow the above is possible as whenever my Apple TV is running, the standard OOTB dashboard shows not only what source (read: app) is being used, but also the specific content being displayed.

I’m confused where to start. I’ve deduced that a Grafana plugin like the “Discrete Plugin” is probably one approach to generate the above answers, but haven’t been able to create a query that makes it work. Given that I am not reporting on numeric data (degrees, %s, etc) and am reporting on state and state attributes, is Grafana even the way to go for this info? Again, I’m flexible on the format…it doesn’t even have to be Grafana. But if it is, what sort of info do I put in this query?

Thanks!

Just use this:

1 Like

Awesome! Will check this out and get back. Thanks!

Alright, so this is pretty good! I could use some help, however. My config looks like this:

- platform: history_stats
  name: Apple TV 4K Playing in Last 7 Days
  entity_id: media_player.living_room_apple_tv_4k
  state: "playing"
  type: time
  end: "{{ now().replace(hour=0, minute=0, second=0) }}"
  duration:
    days: 7

I’d like to further filter this so that it only counts hours in a specific window (9-5). Is that at all possible?

Thanks!