Git Product home page Git Product logo

roku-sleep-timer's Introduction

Roku Sleep Timer

Turn off Roku and TV after specified period of time. Self hosted dockerized application using Python, Flask, Docker, and Docker Compose.

Companion repo to Medium article.

Table of Contents

Overview

This repo allows you to create and deploy a Roku Sleep Timer application using Flask and Docker. Docker Compose is used to build the Docker image, inject environment variables, and act as a starting point to add additional services to your application.

Architecture

The final architecture of this application is as follows: Roku Sleep Timer Architecture This repo represents the Roku Sleep Timer block in the diagram. It will be invoked via an HTTP request from some source (in this case Apple Shortcuts), routed via Cloudflare and NGINX Proxy Manager, and finally interact with the Roku via a Python SDK.

Application Routes

The routes defined in the Flask app are as follows:

Endpoint Description
/ Test connection - will return Connected if successful.
/host Returns IP Address of Roku device.
/on Manually turn Roku + TV on.
/off Manually turn Roku + TV off.
/discover Start discovery for Roku on the network and re-sync.
/start/<int:minutes> Starts job to sleep in <minutes> number of minutes.
/stop Cancel all sleep timer jobs.

Application Files

This repo contains the following files and directories:

  • src/: Directory for source code - will be copied into Docker image
    • src/app.py: Definition of application routes
    • src/roku_sleep_timer.py: Python code to control Roku via SDK
  • default.env: Default environment file for secret management - should be renamed to .env and never checked into source control
  • docker-compose.yml: Default Docker Compose file that injects secrets from .env file and builds Docker image specified by Dockerfile
  • Dockerfile: Default Dockerfile that copies source code, installs Python dependencies, and runs Flask server
  • Makefile: Helper to easily start, stop, and restart app
  • requirements.txt: Defines list of Python requirements that are used by the application and will be installed into the Docker image

Prerequisites

Ensure you have Docker, Docker Compose, and Python installed.

Getting Started

  1. Clone the repository.
  2. Copy the default.env file to a new file called .env and populate with your desired port and any secrets
    • This should never be commited into source control - this template is setup to ensure the .env file is excluded from Git
  3. Deploy the app by running make up.
  4. Navigate to http://<IP_ADDRESS>/<FLASK_PORT> (e.g. http://localhost:5050) in your browser - you should see Connected if successful.
    • IP_ADDRESS is the IP address of the machine running Docker.
    • FLASK_PORT is the port defined in your .env file (default is 5050)
  5. Update app with any changes by re-running make up
  6. Restart app by running make restart
  7. Stop app by running make down
  8. Follow Medium article to setup connectivity outside your local network

License

This template is made available under a modified MIT license. See the LICENSE file.

roku-sleep-timer's People

Contributors

nschenone avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.