Home Assistant & API rest

Hi all,

When I’m reading data from a webserver in a web browser with the following URL: https://192.168.1.2/api/menutree/datapoint_desc.json?SessionId=73539bf7-344b-4a51-9390-523705b616f0&Id=671

I got a nice answer:
image

However, when I’m trying to code into Home Assistant configuration.yaml file, with the following code, it fails:

# Sensors
rest:
  - verify_ssl: false
    scan_interval: 10
    resource: https://192.168.1.2/api/auth/login.json?user=<mylogin>&pwd=<mypassword>
    sensor:
      - name: "sid_token"
        unique_id: sid_token
        value_template: '{{ value_json.SessionId }}'
  - verify_ssl: false
    scan_interval: 1
    resource: https://192.168.1.2/api/menutree/datapoint_desc.json?SessionId={{ states.sensor.sid_token.state }}&Id=671
    sensor:
      - name: "Temp ext."
        unique_id: temp_ext
        value_template: '{{ value_json.Description.Value }}'

I have no error on my home assistant configuration, I just failed to get my value into the development tools → stats of entities

Any help would be appreciate

Precision: I’m a total beginner in coding in yaml

I don’t think you can do the authentication the way you have it setup, or at least I’ve never seen someone do it that way. Because you are authenticating separately from the actual call, I won’t be surprised if the session is expiring. At a minimum, you really should look through the docs again on the Rest Sensor. I doubt any login script is just going to take a username and password in the URL like that. That would be horribly bad security practice.

There is a way to create a rest sensor that uses basic or digest auth. If the particular service uses some other kind of form based authentication, you might be out of luck.

Hi,

The main issue is that it looks like I need SessionId to access any data: