Created
September 13, 2015 17:47
-
-
Save wolph/9cf58bd13894260dd991 to your computer and use it in GitHub Desktop.
Example script to access domoticz from eventghost, I'll make this in a plugin somewhere in the future :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIGHT_ID = 123 | |
LIGHT_LEVEL = 40 | |
DOMOTICZ_URL = 'http://domoticz/json.htm?' | |
def fetch(**kwargs): | |
import json | |
import urllib | |
params = urllib.urlencode(kwargs.items()) | |
url = DOMOTICZ_URL + params | |
print 'Fetching', url | |
return json.load(urllib.urlopen(url)) | |
def set_level(light, level): | |
fetch(type='command', param='switchlight', idx=light, switchcmd='Set Level', | |
level=level) | |
def get_state(): | |
devices = fetch(type='devices', used='true') | |
state = dict() | |
for device in devices['result']: | |
state[int(device['idx'])] = device | |
return state | |
if not hasattr(eg.globals, 'domoticz'): | |
eg.globals.domoticz = get_state() | |
light = eg.globals.domoticz[LIGHT_ID] | |
if light['Status'] == 'On': | |
eg.globals.domoticz = get_state() | |
set_level(LIGHT_ID, LIGHT_LEVEL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment