In Python app remy_python I added a scheduler.

Now the app has three parts:

  • Functions to send commands to the infrared transmitter, which then transmits the commands to the television sound bar
  • A Flask web service to accept television command requests (e.g. volume decrease, volume increase)
  • A scheduler that automatically sends remote control commands at programmed times (e.g. mute during TV commercials)
Pi IR remote shield
Raspberry Pi with infrared remote control board

define quiet times

QuietTime = namedtuple('QuietTime', 'start end')

quiet_times17 = [
    QuietTime(datetime.time(hour=17, minute=17, second=0), datetime.time(hour=17, minute=20, second=0)),
    QuietTime(datetime.time(hour=17, minute=27, second=0), datetime.time(hour=17, minute=31, second=20)),
    QuietTime(datetime.time(hour=17, minute=38, second=15), datetime.time(hour=17, minute=41, second=45)),
    QuietTime(datetime.time(hour=17, minute=48, second=0), datetime.time(hour=17, minute=51, second=50)),
    QuietTime(datetime.time(hour=17, minute=54, second=20), datetime.time(hour=17, minute=57, second=50))
]

use apscheduler to run jobs at scheduled times

def add_jobs_mute(quiet_times, scheduler):
    """ mute sound during each quiet time
    """

    for quiet_time in quiet_times:
        # add_job, implicitly create the trigger
        # args is for function transmit_command_ir
        # first call to mute toggles sound off
        scheduler.add_job(transmit_command_ir, cron,
                          day_of_week=day_of_week,
                          hour=quiet_time.start.hour, minute=quiet_time.start.minute, second=quiet_time.start.second,
                          args=[RemoteCommand.MUTE])
        # next call to mute toggles sound on
        scheduler.add_job(transmit_command_ir, cron,
                          day_of_week=day_of_week,
                          hour=quiet_time.end.hour, minute=quiet_time.end.minute, second=quiet_time.end.second,
                          args=[RemoteCommand.MUTE])

TODO

See if commercial times are consistent enough for scheduler approach to be practical. If not, consider automatically detect commercials e.g. similar to “Enough Already” by Matt Richardson checking closed captioning text for a word on a list (e.g. “Lexus”, “Tylenol”)

References

Raspberry Pi infrared remote control for a television sound bar

https://beepscore.com/website/2019/02/03/raspberry-pi-infrared-remote-control-tv.html

Network enabled Raspberry Pi tv remote control

https://beepscore.com/website/2019/02/05/network-enabled-raspberry-pi-tv-remote-control.html

remy_python

https://github.com/beepscore/remy_python
Make a Raspberry Pi infrared remote control. The device can programmatically control television sound bar audio volume. The Raspberry Pi uses LIRC (Linux Infrared Remote Control) to send commands to an attached infrared transmitter. The README includes links to similar remote control projects, infrared remote control hardware.

Advanced Python Scheduler

https://apscheduler.readthedocs.io/en/latest/userguide.html
Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically.

Inspirational projects

Enough Already by Matt Richardson

https://makezine.com/2011/08/16/enough-already-the-arduino-solution-to-overexposed-celebs/

TV-B-Gone Kit

https://www.adafruit.com/product/73

TV-B-Gone

https://www.tvbgone.com/