Control Hass.io server using REST API from a third-party controller

Hello, Tomas.

I imported the сurl working command

curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3OGUyZjkyNTc0NGE0MjcxOWY0MTIwNDQxOWZmOWFmNCIsImlhdCI6MTU3ODIxOTU2OCwiZXhwIjoxODkzNTc5NTY4fQ.TEvEUieMyT1GYu6F9XCiDEFJI3QxIa8G9wEtnMTLsxQ" -H "Content-Type: application/json" -d '{"entity_id": "switch.switch_1gang"}'  http://192.168.1.4:8123/api/services/switch/toggle

into Postman.

HTTP code

I missed one point: an empty line after Headers (in the HTTP code it is visible).

I added an empty line to the command code for the Accelerator:

\x0D\x0A\x0D\x0A

now the command code for the Accelerator looks like this:

POST\x20/api/services/switch/toggle\x20HTTP/1.1\x0D\x0AHost:\x20192.168.1.4:8123\x0D\x0AAuthorization:\x20Bearer\x20eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3OGUyZjkyNTc0NGE0MjcxOWY0MTIwNDQxOWZmOWFmNCIsImlhdCI6MTU3ODIxOTU2OCwiZXhwIjoxODkzNTc5NTY4fQ.TEvEUieMyT1GYu6F9XCiDEFJI3QxIa8G9wEtnMTLsxQ\x0D\x0AContent-Type:\x20application/json\x0D\x0AContent-Length:\x2036\x0D\x0A\x0D\x0A{"entity_id":\x20"switch.switch_1gang"}\x0D\x0A\x0D\x0A

Answer:

HTTP/1.1\x20200\x20OK\x0D\x0AContent-Type:\x20application/json\x0D\x0AContent-Length:\x20901\x0D\x0ADate:\x20Tue,\x2014\x20Jan\x202020\x2006:42:34\x20GMT\x0D\x0AServer:\x20Python/3.7\x20aiohttp/3.6.1\x0D\x0A\x0D\x0A[{"attributes":\x20{"auto":\x20true,\x20"entity_id":\x20["switch.3_in_1_sensor_5",\x20"switch.airconditioner_power_16",\x20"switch.airconditioner_temp_17",\x20"switch.warmplintus_temp_10",\x20"switch.dimmer_01",\x20"switch.plug_switch_led",\x20"switch.plug_switch_socket",\x20"switch.switch_1gang"],\x20"friendly_name":\x20"all\x20switches",\x20"hidden":\x20true,\x20"order":\x202},\x20"context":\x20{"id":\x20"77f1a61ba05f4f448e6e4bfd41321460",\x20"parent_id":\x20null,\x20"user_id":\x20null},\x20"entity_id":\x20"group.all_switches",\x20"last_changed":\x20"2020-01-14T06:42:34.021177+00:00",\x20"last_updated":\x20"2020-01-14T06:42:34.021177+00:00",\x20"state":\x20"on"},\x20{"attributes":\x20{"friendly_name":\x20"switch_1gang"},\x20"context":\x20{"id":\x20"588a90fa62a44cc1b4dfc69fe3d09a84",\x20"parent_id":\x20null,\x20"user_id":\x20"10688b7431b246a59e83dca954f26dde"},\x20"entity_id":\x20"switch.switch_1gang",\x20"last_changed":\x20"2020-01-14T06:42:34.020198+00:00",\x20"last_updated":\x20"2020-01-14T06:42:34.0201

Now these commands work fine.

turn_on , turn_off , toggle .

Thanks.

do you have this working now in URC? if so i just got a URC system and could use some help. I have no clue what i am doing. in this type of thing

how did you convert the curl command to the command you put in URC?