Getting specific data from Api/Json

  api, dictionary, json, python, python-3.9

I am trying to figure out how exactly to just get the brightness. I have attached my code and the response below.

import requests
import json

response = requests.get("https://developer-api.govee.com/v1/devices", headers={"Govee-API-Key”:”KEY”})
rp = response.text
rs = json.loads(rp)
de = (rs['data']['devices'][0]['device'])
mo = (rs['data']['devices'][0]['model'])

responses = requests.get("https://developer-api.govee.com/v1/devices/state?device=00000000000&model=H6159", headers={"Govee-API-Key”:”KEY”})
rps = responses.text
rpsj = json.loads(rps)

print(rpsj['data']['properties'])
val = 100

print(de)
print(mo)


response1 = requests.put("https://developer-api.govee.com/v1/devices/control", headers={"Govee-API-Key":"KEY”}, json={"device": de, "model": mo,"cmd": {"name": "brightness", "value": val}})




[{'online': True}, {'powerState': 'on'}, {'brightness': 100}, {'color': {'r': 209, 'b': 255, 'g': 222}}]
00:00:00:00:00:00:00:00
H6159

Source: Python Questions

LEAVE A COMMENT