Hello community! Happy New Year!
I ask for help. I am a novice user of Hass.io and have not yet been able to deal with the following question.
How can I control the devices integrated into Hass.io using the REST API through http/tcp from a third-party controller.
I read the following information: https://developers.home-assistant.io/docs/en/external_api_rest.html
I created a long term token. Is the token really so long?
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3OGUyZjkyNTc0NGE0MjcxOWY0MTIwNDQxOWZmOWFmNCIsImlhdCI6MTU3ODIxOTU2OCwiZXhwIjoxODkzNTc5NTY4fQ.TEvEUieMyT1GYu6F9XCiDEFJI3QxIa8G9wEtnMTLsxQ
I try several ways to create commands, but I get errors:
with this version of the command from third-party controller with IP 192.168.1.10:
POST\x20/api/states/switch.switch_1gang\x0D\x0Aheaders:\x0D\x0Aauthorization:\x20'Bearer\x20eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3OGUyZjkyNTc0NGE0MjcxOWY0MTIwNDQxOWZmOWFmNCIsImlhdCI6MTU3ODIxOTU2OCwiZXhwIjoxODkzNTc5NTY4fQ.TEvEUieMyT1GYu6F9XCiDEFJI3QxIa8G9wEtnMTLsxQ'\x0D\x0Acontent-type:\x20'application/json'\x0D\x0Apayload:\x20'{"state":"on"}'\x0D\x0A\x0D\x0A
I get this message in third-party controller:
HTTP/0.9\x20401\x20Unauthorized\x0D\x0AContent-Type:\x20text/plain;\x20charset=utf-8\x0D\x0AContent-Length:\x2017\x0D\x0ADate:\x20Thu,\x2009\x20Jan\x202020\x2013:26:06\x20GMT\x0D\x0AServer:\x20Python/3.7\x20aiohttp/3.6.1\x0D\x0A\x0D\x0A401:\x20Unauthorized
and I get this error in Hass.io:
Login attempt or request with invalid authentication from 192.168.1.10
Next.
with this version of the command from third-party controller with IP 192.168.1.10:
curl\x20-X\x20POST\x20-H\x20"Authorization:\x20Bearer\x20eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3OGUyZjkyNTc0NGE0MjcxOWY0MTIwNDQxOWZmOWFmNCIsImlhdCI6MTU3ODIxOTU2OCwiZXhwIjoxODkzNTc5NTY4fQ.TEvEUieMyT1GYu6F9XCiDEFJI3QxIa8G9wEtnMTLsxQ"\x20-H\x20"Content-Type:\x20application/json"\x20-d\x20'{"entity_id":\x20"switch.switch_1gang"}'\x20http://192.168.1.4:8123/api/services/switch/turn_on
I get this message in third-party controller:
HTTP/1.0\x20400\x20Bad\x20Request\x0D\x0AContent-Type:\x20text/plain;\x20charset=utf-8\x0D\x0AContent-Length:\x2011\x0D\x0ADate:\x20Thu,\x2009\x20Jan\x202020\x2013:31:13\x20GMT\x0D\x0AServer:\x20Python/3.7\x20aiohttp/3.6.1\x0D\x0A\x0D\x0ABad\x20Request
and I get this error in Hass.io:
Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 275, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: invalid HTTP method
Maybe there are somewhere examples of how the command for http/tcp looks right?
Thanks.