Measure time the TV is ON
To track how long your TV is on in Home Assistant, you can use the template sensor and history statistics integration. Assuming your TV has an entity (e.g., switch.tv
or media_player.tv
), here's a YAML setup to calculate the time it's on each day.
Step 1: Create a Template Binary Sensor
First, create a binary sensor to detect when your TV is on:
binary_sensor:
- platform: template
sensors:
tv_status:
friendly_name: "TV Status"
value_template: "{{ is_state('media_player.tv', 'on') }}"
Replace media_player.tv
with the actual entity ID of your TV. This sensor will be on
when the TV is on.
Step 2: Use the History Statistics Sensor
Now, use the history statistics sensor to calculate the total time the TV has been on each day:
sensor:
- platform: history_stats
name: TV On Time Today
entity_id: binary_sensor.tv_status
state: "on"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
This setup will provide a TV On Time Today
sensor, which resets every day and accumulates the time your TV was on.
Optional: Adding a Weekly or Monthly Tracker
You can duplicate the history_stats sensor and adjust the start
time to track weekly or monthly usage:
- platform: history_stats
name: TV On Time This Week
entity_id: binary_sensor.tv_status
state: "on"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) - timedelta(days=now().weekday()) }}"
end: "{{ now() }}"
This will give you daily, weekly, and customizable duration insights on your TV's usage. Let me know if you'd like to add automations or notifications based on this data!