I’m new to Home Assistant and exploring its capabilities. I’m trying to authenticate against the UniFi UDM using Home Assistant’s REST commands and query the results. I’ve successfully done this using Python, but now I’m interested in achieving the same using the REST integration in Home Assistant OS (HAOS).
Here’s what I have so far: I’ve set up the authentication part, and it seems to be working. On the Overview dashboard, I see the “unifi auth” entity, and clicking on it shows the deviceToken in its time slot.
The next step is to query another URL to retrieve the JSON results, and I want to do this natively in HAOS using the REST integration, rather than Python. I’m unsure how to proceed with using the authenticated token to make this additional request.
Any guidance on how to authenticate and then use that authentication to query the next URL and gather the JSON results?
# Authentication with first API
sensor:
- platform: rest
name: unifi auth
resource: https://X.X.X.1:443/api/auth/login
method: POST
payload: !secret unifi_payload
headers:
Content-Type: "application/json"
verify_ssl: false
value_template: "{{ value_json.deviceToken }}"
# Query second API using authentication from first
- platform: rest
name: unifi health
resource: "https://X.X.X.1:443/proxy/network/api/s/default/stat/health/"
method: GET
headers:
Authorization: 'Bearer {{ states("sensor.unifi_auth") }}'
value_template: "{{ value_json.result }}"
Also, when it comes to debugging this, I set homeassistant.core: debug, I still don’t see much more information. Is there a debug for API? Any clues on how to degub this would be great also.
Any help is appreciated.