Automatically Stop Channels Every Night

channels-api
home-automation

#1

One request we’ve gotten a lot is for a sleep timer. Well, we still haven’t gotten around to it :crazy_face: The good news is, with the Channels API, you can do it yourself!

With a simple cronjob, you can tell your Channels app to stop playing every day at the same time of night. With this approach, you don’t even have to set a sleep timer. You just get it free every night.

Caveat: cronjobs are specific to macOS and Linux, but I’m sure there’s an equivalent on Windows.

If you need to learn about setting up cronjobs, here’s a great post about them.

Here’s a great cheat sheet on the format:

* * * * * *
| | | | | | 
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)

So lets say we want to stop Channels every night at 3am.

* 3 * * * * curl -X POST http://192.168.1.50:57000/api/stop

And that’s it! Replace the IP address with that of your device, and it will tell Channels to stop every night at 3am. No other tools needed.

Learn more about the Channels API on our site.


#2

I don’t have use for a cronjob to stop playback, but like that you posted a link to the API commands. I played around with it briefly. You forgot the port number in your http POST command. At least, in my case, the port (57000) needs to be specified in order for the commands to return valid JSON.


#3

Doh! Thanks.


#4

Anyway to do this through HomeAssistant?


#5

Totally. It’s super simple. Just use a time trigger on an automation:

automation:
  - alias: Stop Channels at 3 am
    trigger:
      platform: time
      at: '03:00:00'
    action:
      - service: media_player.media_stop
        data:
          entity_id: media_player.living_room_channels

#6

After I figured out how to modify the config. It worked perfectly!


#7

Will it also stop channels even if the timeline is not live? For example when someone paused for a few seconds. On my apple TV when I press stop it always asks if I really want to exit in this case.


#8

Yes.


#9

I know the idea is to promote the use of the API, but a setting in Channels that forced it to stop every night at a set time would be useful. Just to close the tuners down so they can be reclaimed the next day buy actual viewers.