RESTful Notification setup and use for a basic GET command

Hello,
I need help with REST notify setup & usage syntax for a pretty basic usage. Despite reading around, all my tries so far failed with both RESTfull Notifications and with RESTful commands.
Since I do not care about the http response , I guess notify service should be sufficient although I don’t really know which service to prefer.

I need to send the following kind of command :

http://localIPaddress?topic=blind_1&cmd=u

This example will make blind_1 to go up. topic and cmd parameters to be set in my automations.

Could someone be kind enough to help me with the syntax needed in configuration.yaml, how to use it in the developer tools to test and in an automation ?

Thanks,
Al

Useful links:
RESTful Notifications : RESTful Notifications - Home Assistant
RESTful Command: RESTful Command - Home Assistant

u’ve linked the docs, u have examples in docs, so what’s the problem?

Problem is maybe that the doc was written by an expert for another expert and we are not all experts.
A simple working example for a basic GET command would help me (and possibly some others).

# Example configuration.yaml entry
rest_command:
  example_request:
    url: "http://example.com/"

That’s exactly it. This is a definition of a GET request with “example_request” as “service_name”.

Add it to your config and restart HA.

Go to http://homeassistant.local:8123/developer-tools/service

Start typing rest – your newly created rest_command.example_request service is available. When you call it, the request is made and you can see response.

You can use that in automation, you can pass in parameters, etc. → the details are in the docs. Try, experiment :slight_smile:

Try, experiment…yeah… I have been doing nothing but this !

Instead of continuing to throw darts in the dark and hope to hit the target, I decided to turn the lights on :wink:
I modified the receiver to trace in a log any malformed incoming request.

For memory, my simple need is to send a GET request like this, with 2 parameters :

 /?topic=blind1&cmd=u

Playing with Rest Notify service

First basic try in configuration.yaml

notify:
  - name: my_target
    platform: rest
    resource: http://local_ip_address

After a full HA restart, I go to developer tools and call the service

notify.my_target

There are several parameters in the UI.
message is mandatory. I enter sample_text there and click “Call Service” button.

The target receives:

GET /?message=sample_text HTTP/1.1

This is a correct GET request, except that I did not expect the first parameter “message” to be forced there by HA.

Fortunately, my requests always start with the same literal, and again fortunately, it can be changed in HA with the additional setting:

message_param_name: "topic"

With this, the target receives

GET /?topic=sample_text HTTP/1.1

Sounds like a good start!

I tried to send a more realistic request “blind1&cmd=u” by simply putting it into the message field. It failed miserably !
The target receives:

GET /?topic=blind1%26cmd%3Du HTTP/1.1

There seem to be no way to send an & or = as a string in the message.

I assume that the data: dictionary parameter would help with additional parameters.
So I tried this in the config:

notify:
  - name: my_target
    platform: rest
    resource: http://local_ip_address
    message_param_name: "topic"
    data:
      "cmd": "{{ cmd }}"

I call the service like this:

service: notify.my_target
data:
  message: blind1
  data:
    cmd: u

The target now receives

GET /?topic=blind1&cmd= HTTP/1.1

Almost good, except that cmd parameter remains empty.
I tried syntax variants in dev tools and in a script with no success.

I am doing something wrong in either settings or service call or both, and can’t see what.

I give up with REST notification service and will try with the Rest command service, hoping for better results.

1 Like

A working solution with RESTful command integration:

For memory, I want to send a basic HTTP GET request to a local IP Address with two parameters, like this:

/?topic=blind1&cmd=u

Add in configuration.yaml

rest_command:
  my_target:
    url: "http://local_ip_address/?topic={{ topic }}&cmd={{ cmd }}"
    method: get

As usual, it requires a full HA restart.

To call it in developer tools, script or automation:

service: rest_command.my_target
data: 
  "topic": "blind1"
  "cmd": "u"

Now that I found the solution, I can see that it was in the doc with a subtle hint “URL (supports template)”.

Hope this helps :slight_smile:

2 Likes

I agree docs require a lot of polishing, I’m glad you came up with the solution!