Git Product home page Git Product logo

plhuexpy's Introduction

plhuexpy

A python server to control Hue lights with Plex webhooks. Rules are set with a yaml file.

Requirements

  • cherrypy
  • pyyaml
  • phue

Example Rule Set

- rule:
    - plex_condition:
        events: [media.resume]
        players:
            local: [true]
            title: [Plex Web (Chrome)]
    - hue_action:
        items: [Bedroom]
        settings:
            turn_on: true
            brightness: 25
            color_cie: [0.7,0.3]
- rule:
    - plex_condition:
        events: [media.pause]
        players:
            local: [true]
            title: [Plex Web (Chrome)]
    - hue_action:
        items: [Bedroom]
        settings:
            turn_on: true
            brightness: 25
            color_hsv: [0.666,1,1]
- rule:
    - plex_condition:
        events: [media.play]
        players:
            local: [true]
            title: [Plex Web (Chrome)]
    - hue_save_action:
        name: before_play
        items: [Bedroom]
    - hue_action:
        items: [Bedroom]
        settings:
            brightness: 25
- rule:
    - plex_condition:
        events: [media.stop]
        players:
            local: [true]
            title: [Plex Web (Chrome)]
    - hue_load_action: 
        name: before_play
        transition_time: 30

Example Usage

python plhuexpy.py --bridge-ip <ip_address_of_bridge> --rules path/to/rule/file

Don't forget to add your plex webhook

http://<server_address>:38148

Wishlist / ToDo

  • web interface to setup rules
    • Start easy and maybe just have a web interface to edit yaml
  • daemonize
  • add server port to CL args
  • named action/conditions. can be used multiple times in rules
  • implement logging instead of this print crap
  • web interface for RGB/CIE/HSV colorpicker
  • flesh out the PlexCondition to take more options. Ideally, it would just match anything that is in the plex json data and the rule yaml without much special handling

More details

Rules

The rule base is read from a yaml document. Rules are made up of any number of conditions and any number of actions. The conditions must ALL test true in order for the actions to execute.

Conditions

Within a single condition, the options are basically or'd. For example, if a condition has event: [media.play,media.resume] and the event is media.play OR media.resume, the condition will pass (test true).

Plex Condition

Tests agains the data that Plex posts via json.

- plex_condition
    events: [] # items in list are or'd, must be a list
    players:
        local: [] 
        title: []

Actions

Hue Action

Basic action to do most things with a hue light.

- hue_action
    items: [] #can be room, group or light name
    settings:    
        turn_on: <true or false>  
        color_rgb: [r,g,b] 
        color_hsv: [h,s,v] 
        color_cie: [x,y]
        color_temp: 153 (6500K) to 500 (2000K)
        brightness: 0 - 1

Notes:

  • color_* options are mutually exclusive, only one may be used.
  • for rgb,hsv,cie colors, range is 0-1

Hue Save Action

Saves the states of lights to be loader later:

- hue_save_action:
    name: <name to save state to>
    items: ['A list', 'of lights or', 'groups to save']

Hue Load Action

Loads light states from a previously saved state

- hue_load_action:
    name: <name of state to load>
    transition_time: <integer of deciseconds>

Hue Run Scene Action

Actives a scene.

- hue_activate_scene:
    name: <name of the scene to activate>
    group: <room or qroup the scene is for>

plhuexpy's People

Contributors

therealpickle avatar

Stargazers

 avatar  avatar  avatar  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.