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?
le_top
April 18, 2023, 10:12am
2
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.
AFAIK HA requires a POST request.
What I share here is a proof of concept where a web page button starts a “post”, but there still is a “POST” request in the process.
Define an automation (adjust notify.mobile_app_sm_a125f to your notification service)):
alias: Test Webhook
description: ""
trigger:
- platform: webhook
webhook_id: test_webhook
condition: []
action:
- service: notify.mobile_app_sm_a125f
data:
message: Test Webhook succes
mode: single
This implementation uses …
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?