Help with restful command

My ac unit can take remote commands using a query string, for example,

http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1

will set the AC in heat mode, temperature 21, fan speed to ‘night mode’, normal mode and state ON.

Sending http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1 from my web browser woks as expected.

Before I get all fancy and start using input_selects to set the values I did a simple test:

rest_command:
  lounge_ac_control:
    url: 'http://10.1.1.9/'
    method: post
    payload: 'r?d=4&t=21&f=176&a=0&s=1'


script:
  test_ac_control:
    sequence:
      - service: rest_command.lounge_ac_control

Unfortunately running this script did nothing as HA returned an error 401 on call http://10.1.1.9/.

I tried just using the IP address as the url (‘10.1.1.9’) but this returned a bunch of python invalid url errors.

Does HASSIO support the rest_command?

Can anyone see what I am doing wrong?

I tried just using the IP address as the url (‘10.1.1.9’) but this returned a bunch of python invalid url errors.

Wasnt sure what the meant?

have you tried just this?

rest_command:
lounge_ac_control:
url: 'http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1'

script:
test_ac_control:
sequence:
- service: rest_command.lounge_ac_control

Same problem.

Error 401 on call http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1

Tried it with and without single quotes.

I copied the exact string from the error report and pasted it in my browser and it works. Not sure why HA cant find this URL.

Ok now I’m really confused. This works:

switch:
  - platform: command_line
    switches:
      lounge_ac_test:
        command_on: 'curl -k "http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1"'
        command_off: 'curl -k "http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=0"'

So what gives?

This works too:

shell_command:
  test_lounge_ac: 'curl -k "http://10.1.1.9/r?d=4&t=21&f=176&a=0&s=1"'

I can work with that.

I’d still be interested to know why I couldn’t get the restful command to work if anyone knows.

Edit: I just realised HA was returning error 401 (unauthorized) not 404 (not found) for the restful command. Which explains why curl with -k option (insecure) works. Why the restful command is trying to make a secure connection to an http address on the other hand is a mystery.

It’s all academic now as I have realised I can do this a lot simpler with shell_command.

2 Likes

@tom_l
I had a similar problem, but fixed it by replacing the name of my restful device by its IP in the url to be hit by HA. I still don’t understand why/when my ddns fails…
Can you tell me how do you observe the error codes in HA (401 and 404)?

Good lord! This is a two year old post. I honestly don’t remember. I suspect it must have been in the logged error.

Thanks.
I was wondering if your were using the “Log Viewer” add-on of the Supervisor add-on store, or if there is a easier way to consult the log.

Nope just the configuration / logs menu.

Thanks. Good to know.

Hi Folks!

I’ve try this solution (thank you) and it is working manually. I can see the switch as entity and can click on or off but when i wanna use this in automation or scene it simply do not appear.
But i can use it to make a helper. But this helper also do not show up when i wanna use as automation or scene. When i make it in yaml it simply do not save with wrong order message.
Do you have any idea?

You need to explain what you mean by “I can see the switch as entity and can click on or off but when i wanna use this in automation or scene it simply do not appear.”

If you can see it as an entity you should be able to operate it in an automation action via Call Service / switch.turn_on for example.

Thank you for your answare Troon.
The souliton was more restart. I do not know why, but it is looks like for my setup it is not enough a simle restart, 2 or 3 necessary. It is runnung under VM.