It would be really nice if I could get how long time the media player has been active (playing) this day and be able to turn it automatically off if used over a given target.
The reason is that I want to limit how long time my son is sitting on his room watching YouTube. If I could get that number to show on my HA panel and even better, add a automation rule that turns the media player off if over a certal usage time.
@VDRainer I completely forgot about that sensor!! I remember reading the PR and thinking I had some uses for that and then I guess I got sidetracked… thanks for reminding me about it!
I’ve now managed to show hours of use for the sensor, but I still can’t make it send a stop command to the Chromecast.
When I use the configuration below, HA GUI sais “unable to connect” and makes me have to log in agay. But it will never do. To me it seems the action bit probably is the problem. Tried to read the documentation on how to set it up, but not 100% if it’s correct.
From the error log:
2017-05-09 04:55:33 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in "/home/homeassistant/.homeassistant/configuration.yaml", line 78, column 14
My configuration:
sensor:
- platform: history_stats
name: Oliver ChromeCast i dag
entity_id: media_player.oliver
state: 'playing'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
automation:
trigger:
platform: time
minutes: '/5'
seconds: 05
condition:
condition: and
conditions:
- condition: state
entity_id: media_player.oliver
state: 'playing'
- condition: template
value_template: '{{ sensor.oliver_chromecast_i_dag.value | float > 3 }}'
action:
service: media_stop
entity_id: media_player.oliver
automation:
trigger:
- platform: time <--- added hyphen before 'platform'
action:
- service: media_player.media_stop <--- added hyphen before 'service' and domain before 'media_stop'
entity_id: media_player.oliver
Now HA GUI loads and I get the automation in the list.
When my son comes crying later today I will know if it works…