(2014-02-27, 22:13)giftie Wrote: I see the two typos and have fixed them.
Thanks.. Let me know what needs to change
Actually, I think that was it, my last issue was probably one of my test machines that was the issue, I think it is running Gotham..
Well, I just tested it on my laptop with Frodo, and got it working just fine,
so it is time to give it a go on my "live" MCE running Linux, and finetune the last stuff (brightness on each level, hue, saturation and stuff)
A big thanks for your help
script
Code:
# This module's future home should be inside userdata/addon_data/script.cinema.experience/ha_scripts
# to make sure it does not get over written when updating the script
import xbmc, xbmcaddon
import socket, sys, httplib
from threading import Thread
triggers = sys.modules[ "__main__" ].triggers
ha_settings = sys.modules[ "__main__" ].ha_settings
class Automate:
def __init__( self ):
# Put the Philips Hub address and api key here.
self.hue_address = '192.168.0.7'
self.hue_api_key = 'philipshue'
self.command_groups = '/api/%s/groups/%s/action'
self.command_light = '/api/%s/lights/%s/state'
def philips_hue( self, group = -1, light = -1, content = "" ):
""" This function provides simple control of single groups and single lights.
The following websites might prove to be useful:
http://developers.meethue.com/1_lightsapi.html
http://developers.meethue.com/2_groupsapi.html
http://rsmck.co.uk/hue
Ussage:
To call the philips_hue function, you need to provide the group or
light number as well as the function you would like to use.
Groups:
The function call to create an action for a group is the following:
self.philips_hue( group = group_number, content = body_content )
# where group_number is the actual group number and body_content the action.
You can actually use the above line exactly how it is with declaring the variables be for it.
group_number = 7
body_content = '''{"on":true}'''
self.philips_hue( group = group_number, content = body_content )
This would turn on group 7.
Lights:
The function call to set a light is almost the same as the group function:
self.philips_hue( light = light_number, content = body_content )
# where light_number is the actual light number and body_content the action.
You can actually use the above line exactly how it is with declaring the variables be for it.
light_number = 1
body_content = '''{"bri": 254, "on": true}'''
self.philips_hue( light = light_number, content = body_content )
This would turn on light 1 at full brightness.
"""
if light > -1: # Not sure if there is a light number 0, but this will take care of it.
command = self.command_light % ( self.hue_api_key, light )
else:
command = self.command_groups % ( self.hue_api_key, group )
connection = httplib.HTTPConnection( self.hue_address )
connection.request( 'PUT', command, content )
def broadcastUDP( self, data, port = 8278, ipaddress = '255.255.255.255' ): # XBMC's former HTTP API output port is 8278
IPADDR = ipaddress
PORTNUM = port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
if hasattr(socket,'SO_BROADCAST'):
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.connect((IPADDR, PORTNUM))
s.send(data)
s.close()
def activate_ha( self, trigger = None, prev_trigger = None, mode="thread" ):
if ha_settings[ "ha_enable" ]:
if ha_settings[ "ha_multi_trigger" ] and prev_trigger == trigger:
pass
elif mode != "thread":
self.activate_on( trigger )
else:
thread = Thread( name='ha_trigger', target=self.activate_on, args=( trigger, ) )
thread.start()
return prev_trigger
def activate_on( self, trigger = None ):
"""
Scripting to trigger almost anything(HA, other scripts, etc...) when videos start.
Usage:
activate_on( "Movie" )
will trigger code that is set under the Movie heading.
"""
if not trigger:
xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - No Trigger Sent, Returning", level=xbmc.LOGNOTICE )
return
xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - activate_on( %s ) Triggered" % trigger, level=xbmc.LOGNOTICE )
if trigger in triggers:
xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - Trigger %s" % trigger, level=xbmc.LOGNOTICE )
# Script Start
if trigger == "Script Start" and ha_settings[ "ha_script_start" ]:
# place code below this line
body_content = '{"on":true, "bri":150, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
pass
# Trivia Intro
elif trigger == "Trivia Intro" and ha_settings[ "ha_trivia_intro" ]:
pass
# place code below this line
# Trivia
elif trigger == "Trivia" and ha_settings[ "ha_trivia_start" ]:
pass
# place code below this line
# Trivia Outro
elif trigger == "Trivia Outro" and ha_settings[ "ha_trivia_outro" ]:
pass
# place code below this line
# Movie Theatre Intro
elif trigger == "Movie Theater Intro" and ha_settings[ "ha_mte_intro" ]:
pass
# place code below this line
# Coming Attractions Intro
elif trigger == "Coming Attractions Intro" and ha_settings[ "ha_cav_intro" ]:
pass
# place code below this line
# Trailer
elif trigger == "Movie Trailer" and ha_settings[ "ha_trailer_start" ]:
pass
# place code below this line
# Coming Attractions Outro
elif trigger == "Coming Attractions Outro" and ha_settings[ "ha_cav_outro" ]:
pass
# place code below this line
# Feature Presentation Intro
elif trigger == "Feature Presentation Intro" and ha_settings[ "ha_fpv_intro" ]:
pass
# place code below this line
# MPAA Rating
elif trigger == "MPAA Rating" and ha_settings[ "ha_mpaa_rating" ]:
pass
# place code below this line
# Countdown
elif trigger == "Countdown" and ha_settings[ "ha_countdown_video" ]:
pass
# place code below this line
# Audio Format
elif trigger == "Audio Format" and ha_settings[ "ha_audio_format" ]:
pass
# place code below this line
body_content = '{"on":true, "bri":50, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
# Movie
elif trigger == "Movie" and ha_settings[ "ha_movie" ]:
pass
# place code below this line
body_content = '{"on":false, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
# Feature Presentation Outro
elif trigger == "Feature Presentation Outro" and ha_settings[ "ha_fpv_outro" ]:
pass
# place code below this line
# Movie Theatre Intro
elif trigger == "Movie Theatre Outro" and ha_settings[ "ha_mte_outro" ]:
pass
# place code below this line
# Intermission
elif trigger == "Intermission" and ha_settings[ "ha_intermission" ]:
pass
# place code below this line
# Script End
elif trigger == "Script End" and ha_settings[ "ha_script_end" ]:
pass
# place code below this line
body_content = '{"on":true, "bri":200, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
# Paused
elif trigger == "Pause" and ha_settings[ "ha_paused" ]:
pass
# place code below this line
body_content = '{"on":true, "bri":120, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
# Resumed
elif trigger == "Resume" and ha_settings[ "ha_resumed" ]:
pass
# place code below this line
body_content = '{"on":false, "transitiontime":50}'
self.philips_hue( group = 1, content = body_content )
else:
xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - Opps. Something happened", level=xbmc.LOGNOTICE )