I am looking to use HA to enforce tv off time for my children while we are sleeping. I want this automation to check every 5 minutes to see if their tv is on, and if it is on, send a signal to turn the tv off. I have an automation set that that work when manually activated but it dont see in the traces it waking up to check every 5 minutes to check.
THis is the yaml of my automation. Please tell me what I am doing wrong.
alias: Turn off girls TV - 8pm to 6am - weekday
description: ""
trigger:
- platform: time_pattern
minutes: /5
condition:
- condition: time
before: "06:00:00"
after: "20:00:00"
- condition: device
device_id: 33f44c2a912979c0d0abc51065a6bde6
domain: media_player
entity_id: 6993da84820a3c842669a2ddbd1128f7
type: is_on
action:
- type: turn_off
device_id: 33f44c2a912979c0d0abc51065a6bde6
entity_id: 6ee76f9eb2877a40d032d261d1067756
domain: remote
mode: single
Then you would only need a single automation with a time trigger of 8 PM to turn the TV off, and then a second automation with a trigger of “TV turn on” and conditions of “after 8PM” “before 6 AM”
Someone even more creative than me might know how to combine them into a single automation, but I personally would rather have 200 easy-to-understand automations rather than 20 SUPER complicated ones that will take me an hour to understand when I have to make changes to them 2 years after I wrote them. LOL
My only caution if you go this route is to make sure to have a good naming scheme for them. Since HA doesn’t have folders or any other type of organization system for automations, finding the one you want to modify can be a challenge if you don’t have a good naming convention. I made this mistake when I first started, and learned the hard way. Now, my automations are named like this:
Lights - Exterior - Floodlights
Lights - Exterior - Garage
Lights - Exterior - Uplighting
Lights - Interior - Kitchen
Lights - Interior - My Office
Notification - Doorbell - Front door
Notification - Doorbell - Garage door
Notification - Water Leak - Half Bath sink
Notification - Water Leak - Hot water tank
Notification - Water Leak - Kitchen sink
Notification - Water Leak - Master Bath sink
Notification - Water Leak - Prep sink
You get the idea. I try to group them up into what the notification does - controls lights, notifies me about something, takes action based on security camera, locks up when nobody is home, open the garage door when someone arrives home, etc.
Agree. I have 90% of my config generated by shell scripts. In other words, I’ve built a class / object system outside of HA to generate the config and that creates the naming conventions. With this I can add a new light control loop with multiple triggers, occupancy and luminance in about a minute. and it’s based on code that already works. Some day I’ll package these tools into a public repo.
alias: Turn off girls TV - 8pm to 6am - weekday
description: ""
trigger:
- platform: state
entity_id: 6993da84820a3c842669a2ddbd1128f7
from: "off"
to: "on"
- platform: time
at: "20:00:00"
condition:
- condition: time
before: "06:00:00"
after: "20:00:00"
- condition: state
entity_id: 6993da84820a3c842669a2ddbd1128f7
state: "on"
action:
- service: media_player.turn_off
target:
entity_id: 6ee76f9eb2877a40d032d261d1067756
mode: single
No need to poll continuously. If it is on at 8pm it gets turned off. If someone attempts to turn it on between 8pm and 6am it gets tuned off.
If you look in Developer Tools → States you will be able to replace the stupid entity_id: 6ee76f9eb2877a40d032d261d1067756 with something more meaningful like entity_id: media_player.kids_tv or whatever it is called.