What is the best way to debug a Restful command?

Hi everyone,

I just started on Home Assistant a few weeks back, so I’m quite new to this.

I am trying to use Restful command to send a notification within an Automation (when a sensor is triggered), but I can’t seem to get it right.

I came across a couple of posts there were quite helpful (including this and this) and they gave me some confidence that Rest or Restful command is the right approach. But I seem to be missing something because I am still not doing my get request right and sending stuff to the right place. I get specific errors in the logs when I got the templating stuff wrong. But other times I just get a status code 500 error or nothing.

Does anyone have any suggestions or tips for debugging this or maybe I am just missing something?

This is what I have in my configuration.yaml file:

automation: !include automations.yaml
script: !include scripts.yaml
logger:
    default: debug
    logs:
        rest_command.example_request: debug

rest_command:
    example_request:
        url: 'https://example.com/events/?api_key=abcde'
        method: get
        payload: '&deviceid=somedeviceid&value="{{value}}"&type="{{type}}"&date="{{date}}"'

and my automation.yaml with the action where I call the rest_command:

  action:
  - service: rest_command.example_request
    data:
        value: "value"
        type: "type"
        date: "{{utcnow()}}"

Again, any help or suggestions will be much appreciated!

That entry probably won’t log anything useful. Try:

    logs:
        homeassistant.components.rest_command: debug

Normally you can’t send any payload in a GET request,
By the looks of it though you are trying to add custom URL parameters through templating. I don’t think that this is possible in a rest_command. The url parameter does not support template code, and the payload is not magically appended to the URL.

Does the service you are trying to call support POST requests? In this case you might be able to send templated data inside the payload.

Hi exxamalte,

Thanks so much for the explanation. I wasn’t able to find that information or maybe I wasn’t looking at the right places.

No, unfortunately, I think it has to be a GET request.

What about Notify Rest? Do you know if that can achieve what I am trying to do?

Thanks again for your time!

I haven’t tried that myself. However, I just had a brief look into the code, and it appears that the data_template parameter allows you to define a template and the result is added as URL parameters when using GET method.

Thanks for that exxamalte !

In the meantime, I found that the example in this post: Stuck with Notify Rest , particularly the shell command approach to do a GET request works well.

The same post also mentions the possibility of using Notify and GET method with URL parameters. I made a number of attempts with little success. I will try it for a bit more and post an update if I get it to work.

1 Like