A python server to control Hue lights with Plex webhooks. Rules are set with a yaml file.
- cherrypy
- pyyaml
- phue
- 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
python plhuexpy.py --bridge-ip <ip_address_of_bridge> --rules path/to/rule/file
http://<server_address>:38148
- 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
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.
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).
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: []
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
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']
Loads light states from a previously saved state
- hue_load_action:
name: <name of state to load>
transition_time: <integer of deciseconds>
Actives a scene.
- hue_activate_scene:
name: <name of the scene to activate>
group: <room or qroup the scene is for>