Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

considering adding this example python code to the docs #26

Open
lfg6000 opened this issue Jun 1, 2022 · 0 comments
Open

considering adding this example python code to the docs #26

lfg6000 opened this issue Jun 1, 2022 · 0 comments

Comments

@lfg6000
Copy link

lfg6000 commented Jun 1, 2022

  • i wrote this script while trying out the conbee II

  • i think it would great to have some python example code in the docs

  • if you think it is a good ideal feel free to use the code sample below

  • i think the conbee II, deconz app, phoscon app are great...i am very happy...thank you.

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant