Skip to content

Instantly share code, notes, and snippets.

@lfg6000
Created May 30, 2022 21:12
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 lfg6000/e677f4c910d17d96734e8fe8134bbc19 to your computer and use it in GitHub Desktop.
Save lfg6000/e677f4c910d17d96734e8fe8134bbc19 to your computer and use it in GitHub Desktop.
Deconz Rest API Python Example
import requests, pprint
# ***** use must have the deconz app or service running for this to work ******
# this was test using a ConBee II on windows and raspberry pi
# - to install the deconz app follow these instructions: https://phoscon.de/en/conbee2/install
# - on windows: from start menu run the 'deCONZ app' - it defaults to port 80
# - on pi from app on cmd line w/ ui: > /usr/bin/deCONZ --http-port=8080
runThisApi = 0
port = '80'
ipAddr = 'http://192.168.2.103:' + port
key = '57XXXXXX74' # put your key here after running runThisApi = 0
outlet1 = '1'
# ---------------- get api key
# do this first
# 1) start the 'phoscon app' from the 'deconz app' ui
# 2) enable 'authenticate app' in 'phoscon app'-gateway-advanced then run this cmd
# 3) set runThisApi = 0 and run the code and you will receive an api key
if (runThisApi == 0):
payload = {"devicetype": "my application"}
r = requests.post(ipAddr+'/api/', json=payload)
# [{'success': {'username': '4EXXXXXXB6'}}]
# ---------------- turn light or socket on
if (runThisApi == 1):
payload = {"on": True}
r = requests.put(ipAddr+'/api/'+key+'/lights/'+outlet1+'/state', json=payload)
# ---------------- turn light or socket off
if (runThisApi == 2):
payload = {"on": False}
r = requests.put(ipAddr+'/api/'+key+'/lights/'+outlet1+'/state', json=payload)
# ---------------- get light or socket state
if (runThisApi == 3):
r = requests.get(ipAddr+'/api/'+key+'/lights')
pprint.pprint(r)
pprint.pprint(r.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment