Variables to RESTful sensor

Hey everyone,

I am trying to pull some information into HA via a RESTful sensor that requires authentication. The process works like this:

First I need to POST login information which returns a token and then I can use GET (including that token as a header) to pull the information I need. The token expires every few hours, so this process will need to be repeated.

I’ve tried to do what I want with the following code in my config:

  - platform: rest
    name: myauth
    json_attributes:
      - "data"
    resource: https://myurlhere.com
    method: POST
    headers:
      Accept-Language: en-US;q=1.0
      Accept-Encoding: gzip;q=1.0, compress;q=0.5
      Content-Type: application/x-www-form-urlencoded; charset=utf-8
    payload: 'password:xxxxusername:xxxx'
    value_template: '{{ value_json.data.user_id }}'
    scan_interval: 14400
  - platform: rest
    name: mydata
    json_attributes:
      - "data"
    resource: https://myurlhere.com
    method: GET
    headers:
      Accept: application/json
      Authorization: '{{ "Bearer " + states.sensor.myauth.attributes["data"].access_token }}'
    value_template: '{{ value_json.data.id }}'

The first step (POST) works, and when I throw "{{ “Bearer " + states.sensor.myauth.attributes[“data”].access_token }}” in the template editor, it spits out what I want, but my data sensor just shows as “unknown”.

Can HA just not accept a template in one of the headers or am I doing this wrong? And if it is the former, is there another way to get the information I want?

1 Like

Hey!

Did you ever get a solution to this? I’m wanting to do basically the exact same thing and am struggling a little.

Cheers :slightly_smiling_face:

Hey,

I too am also looking to do this. I have an Inner Range Inception security system with a REST API, but it requires the authentication to be sent, then a session ID received and used to as part of the body of POST requests.

If anyone knows how to do it, please let us all know.

Cheers!

1 Like

I did solve this, but you aren’t going to like the answer haha. The only way I found to do it was to write a custom component / platform in Python. Happy to help you through my process - though full disclosure, what I did is definitely not as robust as what the real developers and people with more experience than me do.

Could you please share your version of the component?

Hi @B_Raz,

If you can please share you custom component, that would be sensational! It will at least give me a starting point for my own component.

Thanks!

Hi Mate,

I have recently acquired an Inception panel for home, just wondering if you ended up having any luck with home assistant integration? I’ve been playing around with API a little with no success. Can get them to talk over TCP but its a bit dodgy. Any help would be greatly appreciated.

Cheers.

I have access to the Inner Range Inception as well, and recently started playing Home Assistant. I’m keen to see how far we can get with integration.

Have you had a look at these?

hi, can you share that custom component? or is it in Hacs? or anyone else have it?