Sending url with button on the dashboard

Hello everybody, I am new on this forum and homeasstant. I can’t figure out how to send a url from a button on the dashboard. I want to send something like
http://192.168.X.X/LED1=ON. Can somebody help me ??
greetings Han

Hi Han,
welcome to the home assistant community :dizzy:.

You could use either the rest command integration, the shell command integration or the command line integration for the purpose of triggering some URL. While the rest command integration is specifically designed to be used with RESTful interfaces, you can use the others with any simple webpage.

I’ll assume you already checked the URL and its function just using your standard browser.

I would prefer the command line integration for this use case.

Shell command integration

Add a shell command calling curl and your URL (add the -k parameter in case you would call a https service and want to skip the ssl verification. When and why you must not do this verification skipping is another question…)

# Example configuration.yaml entry
shell_command:
  activate_led1: 'curl "http://192.168.x.x/LED1=ON"'

You need to restart homeassistant to be able to use the shell command.

Command line integration

command_line:
  - switch:
      name: "control_led"
      command_on: 'curl "http://192.168.x.x/LED1=ON"'
      command_off: 'curl "http://192.168.x.x/LED1=OFF"'
      # Some way to get the activate state
      #command_state: "/usr/bin/curl -X GET http://192.168.0.3/LED1"
      #value_template: '{{ value == "1" }}'

To reload the configuration you just need to trigger the option Command line entities on the Yaml-Page within Developer tools after having Homeassistant Check configuration files.

Now you can use this switch using a button.

In case the server is not reachable the switch/button state would not change because of an error. Errors should usually be visible within the Home Assistant menu System/log depending on your configuration.

1 Like

If I’m not mistaken, curl depends on HAOS being installed on top of another OS. Could HAOS stand-alone send a URL “command”?

I’m running a VM and right now I have no Raspi at hand for testing.

I found some posts about not having curl but until now all of them seemed to be false-positives as the problem was always a configuration one not a missing curl.

If you’r unsure I would first try to call the command curl http://example.com from within a haos shell e.g. using the Terminal & SSH Addon. I don’t know the haos architecture in detail but at least it would be a hint.

Next thing would be the logging. What does it tell about the command line having failed?

Thanks for your reply David, but where do I have to put this yaml code regarding the commandline integration

Hello Han,
Welcome to the HA forum.

Perhaps you missed the links daalja provided.
That is the how-to for these in the HA Docs.

As @Sir_Goodenough mentioned the people in this forum want to encourage you do use the official docs - the reason I usually mention them with my solutions.

But here is the short answer: You just have to append it to your configuration.yaml. If you are not familiar with this file yet: The easiest way for you to edit this basic configuration file of home assistant might be to use the file editor addon. It might look somehow like this:

1 Like