Parsing the STATES from HomeAssistant

I’m trying to figure out how to parse multiple values out of the data returned from the http api using states. The data comes as a long string of text, like so…

[{“attributes”: {“Vera Device Id”: 29, “friendly_name”: “Deck Light”}, “entity_id”: “switch.deck_light_29”, “last_changed”: “2018-05-28T20:43:21.511941+00:00”, “last_updated”: “2018-05-28T20:43:21.511941+00:00”, “state”: “off”}, {“attributes”: {“Vera Device Id”: 5, “battery_level”: “50”, “device_armed”: “False”, “friendly_name”: “Front Door”}, “entity_id”: “switch.front_door_5”, “last_changed”: “2018-05-28T20:43:21.516366+00:00”, “last_updated”: “2018-05-28T20:43:21.516366+00:00”, “state”: “off”}, {“attributes”: {“Vera Device Id”: 182, “friendly_name”: “Indoor Humidity”, “unit_of_measurement”: “%”}, “entity_id”: “sensor.indoor_humidity_182”, “last_changed”: “2018-05-29T21:22:21.616838+00:00”, “last_updated”: “2018-05-29T21:22:21.616838+00:00”, “state”: “59”}]

I’ve got a previous routine that accomplished this same feat from a Vera box. The code that I’m trying to modify is fairly simple. It looks like this:

import requests
import json

url = ‘http://localhost:8123/api/state.name?api_password=welcome
command=requests.get(url)
content = command.content
content = content.decode(‘ASCII’)
data = json.loads(content)
deviceList = data[‘attributes’]
i = 0
for x in deviceList:
print(deviceList[i][‘id’])
i=i+1

Everything appears to go well until the deviceList line. Then it all goes south. If anyone has already done this, I’d love to see your code. You’re welcome to point out my obvious error as well…

I found the homeassistant.remote module and the API. Much easier than doing it all myself…