REST api to query entities & devices details

Team,

Is it possible to query entities (and devices) in HA?
Like an /api/entity and /api/devices endpoint?

Something that returns all entities together with their area, parent device, integration, related entities, part of automations, etc.

Cheers
DJ

@duittenb

Anyone?
:+1:

Anyone?

I am testing some automation platform and I would like to query the location of my mobile phone straight from home assistant and am wondering if this is possible? (I have setup the HA android app and it correctly reports my location to HA)

I use NodeRed with this flow:

[{"id":"bdf8cd6f.ad5c3","type":"tab","label":"PHP State Endpoint","disabled":false,"info":""},{"id":"b05b14fc.2bb988","type":"http in","z":"bdf8cd6f.ad5c3","name":"","url":"/hastate","method":"get","upload":false,"swaggerDoc":"","x":150,"y":60,"wires":[["62eb1352.a9756c"]]},{"id":"4414b44.8b3f44c","type":"ha-get-entities","z":"bdf8cd6f.ad5c3","name":"","server":"49949cfc.3312d4","version":0,"rules":[{"property":"entity_id","logic":"is","value":"[a-z].*\\..*","valueType":"re"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":150,"y":120,"wires":[["67bd9d28.06ebb4"]]},{"id":"67bd9d28.06ebb4","type":"http response","z":"bdf8cd6f.ad5c3","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":470,"y":200,"wires":[]},{"id":"d1e53794.50d368","type":"debug","z":"bdf8cd6f.ad5c3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":640,"y":80,"wires":[]},{"id":"62eb1352.a9756c","type":"switch","z":"bdf8cd6f.ad5c3","name":"","property":"payload.req","propertyType":"msg","rules":[{"t":"nempty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":40,"wires":[["5827eb49.e4ed94"],["4414b44.8b3f44c"]]},{"id":"5827eb49.e4ed94","type":"ha-get-entities","z":"bdf8cd6f.ad5c3","name":"","server":"49949cfc.3312d4","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"payload.req","valueType":"msg"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":410,"y":120,"wires":[["67bd9d28.06ebb4"]]},{"id":"49949cfc.3312d4","type":"server","name":"Gaia","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":true,"heartbeatInterval":"60"}]

I am then able to make simple REST calls like this:

http://homeassistanturl:1880/endpoint/hastate

To receive ALL entities.

http://homeassistanturl:1880/endpoint/hastate?req=light

To get ALL light entities.

http://homeassistanturl:1880/endpoint/hastate?req=sensor.andy_mobile_battery

To receive just a single entity.

1 Like

It sounds like this question needs its own thread?

Thanks for the suggestion @mobile.andrew.jones !
Think that this has pointed me in the right direction.

I’m not sure why as I am asking how to query an entity / device details? Anyway, I will open my own thread if I need more details but so far I see no difference between my question and your thread title.

mobile phone = device and phone’s location = entity? or did I misunderstand these terms?

My question was around querying all entities/devices with all the fields.
I just enabled locations in my app to test this. You can do an API call to:

http://192.168.4.33:8123/api/states/sensor.djsiphone_geocoded_location

That would return:

{
    "entity_id": "sensor.djsiphone_geocoded_location",
    "state": "Unknown",
    "attributes": {
        "Administrative Area": "PROVINCE",
        "Areas Of Interest": "N/A",
        "Country": "Netherlands",
        "Inland Water": "N/A",
        "ISO Country Code": "NL",
        "Locality": "CITY",
        "Location": [
            52.000,
            4.000
        ],
        "Name": "STREET_HOUSE_NR",
        "Ocean": "N/A",
        "Postal Code": "ZIP_CODE",
        "Sub Administrative Area": "COUNTY",
        "Sub Locality": "CITY",
        "Sub Thoroughfare": "00",
        "Thoroughfare": "STREETNAME",
        "Time Zone": "Europe/Amsterdam",
        "Zones": [],
        "icon": "mdi:map",
        "friendly_name": "DJsiPhone Geocoded Location"
    },
    "last_changed": "2022-01-24T22:44:25.665240+00:00",
    "last_updated": "2022-01-24T22:44:25.665240+00:00",
    "context": {
        "id": "0000000",
        "parent_id": null,
        "user_id": null
    }
}

(an easy way to query this information is using Postman and the “HA Collection”)

1 Like