Need help writing an automation - TV on time

Hey Y’all!

Looking to do an automation for my kids’ TVs… If they have more than 2 hours TOTAL on time for the day, i want the TV to turn off. Same if they turn it back on after the automation has turned it off… I have state for the TV on time being pulled in through a command line switch (TCL Roku TVs.) I have a History Stats sensor, but not sure I can automate off of its state…