I have an input_number configured in HomeAssistant like this in the configuration.yalm:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
input_number:
box1:
name: some_number
min: 0
max: 100
step: 1
mode: box
unit_of_measurement: "%"
And I would like to get that value from a NodeMCU board with MicroPython. And I'm trying to get that value from the REPL. First I connect to the network:
>>> import network
>>> ssid = "ssid"
>>> password = "password"
>>> sta_if = network.WLAN(network.STA_IF)
>>> ap_if = network.WLAN(network.AP_IF)
>>> sta_if.active(True)
>>> sta_if.connect(ssid, password)
And after I few seconds I check if sta_if.isconnected()
returns True
.
Then I try to get the value from the API with:
>>> import urequests
>>> url = "http://homeassistant.local:8123/api/states/input_number.box1"
>>> token="token"
>>> headers = {"Authorization": f"Bearer {token}", "content-type": "application/json"}
>>> response = urequests.get(url, headers=headers)
But I get the following error:
>>> response = urequests.get(url, headers=headers)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urequests.py", line 116, in get
File "urequests.py", line 55, in request
OSError: -2
>>>
To create the token I went to homeassistant web > Profile > Long-Lived Access Tokens > Create Token. No more.
Any idea?
Thank you a lot!