floslight
(Torsten Otto)
March 23, 2024, 6:22pm
1
Hi, I have been reading the community in order to learn to create a Template Sensor within Home Assistant to identify the state = playing of an Apple TV and calculate the Screen Time in minutes.
As such I have added the following code in a Template Sensor:
{{ (state_attr('media_player.kuche_2 ', ‘media_duration’) | selectattr(‘state’, ‘eq’, ‘playing’) | sum) / 60 | round(2) }}
Somehow, while the media player is now on, i.e. playing, nothing counts up.
Any ideas/ mistakes you can spot or a simple reference to a best practice?
Thanks!
Frosty
March 25, 2024, 7:47pm
2
I use Measureit to calculate viewing time on my TV if that’s what your after gives me this.
hope this helps
3 Likes
floslight
(Torsten Otto)
March 25, 2024, 9:29pm
3
Thanks a lot, this is exactly what I was looking for!
wild-a
January 13, 2025, 7:58am
4
Can you please share the config for this?
Frosty
January 13, 2025, 10:31am
5
I don’t use it anymore. I don’t see why it wouldn’t still work.
type: custom:stack-in-card
title: Kettle
keep:
background: true
box_shadow: true
mode: horizontal
cards:
- type: custom:mushroom-template-card
card_mod:
style: |
ha-card {
border: none;
box-shadow: none;
ha-card-border-width: 0px;
margin-top: -30px;
width: 200px;
}
primary: Cost / W
secondary: >-
£{{ '%.2f' | format(states('sensor.kettle_daily_energy_cost')| float) }} /
{{ '%.2f' | format((states('sensor.kettle_power')|float / 0.05) | round()
* 0.05) }}W
icon: mdi:kettle
multiline_secondary: true
icon_color: |-
{% set state = states('sensor.kettle_power')|float(-1) %}
{% if state >= 50 %} green
{% else %} grey
{% endif %}
- type: custom:mushroom-template-card
card_mod:
style: |
ha-card {
border: none;
box-shadow: none;
ha-card-border-width: 0px;
margin-top: -30px;
margin-left: 10px;
}
secondary: >-
{{ states('sensor.kettle_count_day') }}/{{
state_attr('sensor.kettle_count_day', 'prev_period')}}
primary: Count/yesterday
icon: mdi:counter
icon_color: blue
entity: sensor.kettle_count_day
tap_action:
action: more-info
- type: custom:mushroom-entity-card
card_mod:
style: |
ha-card {
border: none;
box-shadow: none;
ha-card-border-width: 0px;
margin-top: -30px;
}
layout: horizontal
secondary_info: state
tap_action:
action: toggle
entity: switch.localbytes_plug_pm_8c9d3a_kettle
name: Plug
icon: mdi:power-socket-uk
icon_color: green
card_mod:
style:
$: |
h1.card-header {
font-size: 16px;
padding-top: 1px;
padding-bottom: 18px;
color:var(--secondary-text-color);
}
1 Like