REST Sensor, passwords and !secrets

Is it possible to use !secrets with a REST Sensor?

This works (the password is hard coded in the resource secret)

sensor:
  - platform: rest
    name: hall_panel_fully_kiosk_info
    resource: !secret fully_kiosk_rest_resource
    value_template: '{{ value_json.isScreenOn }}'
    json_attributes:
      - batteryLevel

But neither of these do

sensor:
  - platform: rest
    name: hall_panel_fully_kiosk_info
    resource: http://192.168.1.223:2323//?cmd=deviceInfo&type=json
    password: !secret fully_kiosk_rest_password
    value_template: '{{ value_json.isScreenOn }}'
    json_attributes:
      - batteryLevel

(I didn’t actually expect this next one to work)

sensor:
  - platform: rest
    name: hall_panel_fully_kiosk_info
    resource: http://192.168.1.223:2323//?cmd=deviceInfo&type=json&!secret fully_kiosk_rest_password
    value_template: '{{ value_json.isScreenOn }}'
    json_attributes:
      - batteryLevel

The reason that the second attempt fails is because the password config parameter is used for basic or digest authentication, but the Fully rest interface does not support these forms of authentication. You have to provide the password as a URL parameter, so your first (and working) attempt is the correct one if you want to keep the password in the URL a secret.

1 Like