HTTP API Access without Bearer Token?

Hi,

i have a system in my network with the IP Address: 192.168.178.124

I want to call my sensor with it http://192.168.178.53:8123/api/states/sensor.smartmeter_currently

The Problem, i get 401 unauthorized with it.
I cant set a Bearer Token in the Header with it, so i dont can authorize it with it.

Is there a way to set trusted_networks or so?
I tried that in my configuration.yaml:

homeassistant:
  auth_providers:
    - type: trusted_networks
      trusted_networks:
        - 192.168.178.124

But doesnt help.
Is there any way to call sensor with http, to get json out of it?

I suppose that the Bearer header limitation is imposed by the system initiating the call.

If you can make a POST request, the you could use a webhook.

The following explains how to setup a web page where the user can click a button that then initiates the post request using javascript.

However, if you can convert your GET request in a POST request (even empty), then you can use the webhook ithout having to provide a special header.

You could pass in a parameter or use a unique webhook name to add some kind of token implicitly.

I already tried to grab the value with rest_command, but get that warning and no value:

Template variable warning: 'state' is undefined when rendering '{"state": "{{state}}"}'

Thats the command in configuration.yaml

rest_command:
  rest_smartmeter_currently:
    url: http://192.168.178.53:8123/api/states/sensor.smartmeter_currently
    method: POST
    headers:
      authorization: 'Bearer XXXXXXXXXX'
      accept: "application/json, text/html"
    payload: '{"state": "{{state}}"}'
    content_type:  'application/json; charset=utf-8'

Any idea why?

The next step than an automation webhook… But i didnt get the first ready… i dont know why…

Thats my first webhook try:

alias: REST Webook Smartmeter Currently
description: ""
trigger:
  - platform: webhook
    webhook_id: webhook_smartmeter_currently
action:
  - service: rest_command.rest_smartmeter_currently
    data:
      sensor_id: sensor.{{trigger.json.id}}
      state: "{{'Available' if trigger.json else 'Unavailable'}}"
      attributes_json: "{{ trigger.json }}"

But get 405: Method Not Allowed with calling http://192.168.178.53:8123/api/webhook/webhook_smartmeter_currently

Any idea why?

  1. You can use a service like https://webhook.site/ to see what your request actually looks like.
  2. You used “state” in a template, but you need to privide the data for it when you call the service (rest_command) you created. See the documentation: RESTful Command - Home Assistant (an example on how to use it inside an automation is also shown).
  3. A webhook only accepts POST reqeusts, I suppose you are not running a post request.