Grafana > Graph of media_player source

Heya all!

I have installed influxdb and grafana and I can already see temperatures, battery levels etc.

What I really need is a way to monitor what my kid watches on the smart tv,(the media_player source)… eg I want to be able to know how many hours spent a day watching YouTube or Netflix etc.

Has anyone achieved this? If yes, how?

try the history statistics component

You may need to turn the media_player source attribute into a template sensor to use the history statistics on it.

Either way, that component can get you a duration of use on the media player.

1 Like

Wow, thanks @petro!

I have already made a template sensor for the source (I have automations for the lights when I launch netflix etc) so doing this will be easy as pi :slight_smile:

Will try and report back with the solution, if I succeed :slight_smile:

1 Like

So here is the setup in my sensors.yaml:

- platform: history_stats
  name: TV Youtube Today
  entity_id: sensor.living_room_tv_source
  state: 'YouTube'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'
- platform: history_stats
  name: Smart IPTV Today
  entity_id: sensor.living_room_tv_source
  state: 'Smart IPTV'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'
- platform: history_stats
  name: Netflix Today
  entity_id: sensor.living_room_tv_source
  state: 'Netflix'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

And they are looking good on Home Assistant:

46

(Looks like our guests left the TV on and fell asleep :thinking: )

On Grafana I have created a table using these settings:


And I am getting this:

Now, the question is, why is the timestamp at 03:00:00 since at the time of writing this message it is 10:00 in the morning?

what’s your timezone?

Europe / Athens :slight_smile:

pi@hassbian:~ $ date
Fri Jul 13 15:55:55 EEST 2018
pi@hassbian:~ $ timedatectl status | grep "Time zone"
       Time zone: Europe/Athens (EEST, +0300)
pi@hassbian:~ $

Weird thing, although values are being updated on Grafana, they are not the same (YouTube) as in Home Assistant and the Time remains 03:00:00

08

it’s probably reporting the start of the day in UTC.

EDIT:

I’ve never used graphina, but home assistant stores all time values in UTC. It reports all time values in Local. If graphina is using the raw values, then that’s your problem because the raw values are in UTC.

1 Like

I think that’s the case, you are right. Now I guess I need to find how to set up Grafana to display the timestamps in my local timezone :}