Skip to content

Instantly share code, notes, and snippets.

@wolph
Created September 13, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolph/9cf58bd13894260dd991 to your computer and use it in GitHub Desktop.
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 :)
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