Start a new topic

python read json value

Hi... I am trying to read my Sonoff Basic json message using Python. I am having trouble with the formatting trying to get the "Power" value from it. This is what I am using right now, which outputs 17 (zeros). This does seem to match the Power state of 0 or 1 which is what I am after.  Here is the code:

 

# Get Sonoff One Relay Status
sonoff01_URL = sonoff01
son01 = requests.get(sonoff01_URL)
x = json.loads(son01.text)
status3 = x["Status"]
timestamp = status3["Power"]
device_names = list(status3.keys())[1:-1]

for name in device_names:
    device = status3[name]
    print(f'{status3["Power"]}')

 

Login or Signup to post a comment