[SOLVED] Turn on Shelly via CURL

Hello guys,
i like to receive a suggest about a simple project with my door garage.
Ive almost fininshed the setup step by step but i stopped on the curl part.

Wath i want to do:

On my home assistant ive setup a switch named “garage” that execute a simple command curl to invoke the “on” order on a Shelly 1 (out of my lan) via cloud.

So, ive built the curl string:

curl -X POST http://shelly-10-eu.shelly.cloud/device/relay/control -d "channel=0&turn=on&id=ABCDE1234&auth_key=ABCDE12345678"

Ive test the string via iphone shortcuts and an online tool (https://reqbin.com/curl).
It works perfectly.

Now the last step, how execute it from the switch "garage"on home assistant?

Trying adding this to configuration.yaml with no success:

switch:
  - platform: shell_command
    switches:
      garage:
        command_on: 'curl -X POST http://shelly-10-eu.shelly.cloud/device/relay/control -d "channel=0&turn=on&id=ABCDE1234&auth_key=ABCDE12345678"'

What i do wrong?
If there are an easiest way to do this i accept suggestion.

Maybe try using a command line switch to perform your curl?

https://www.home-assistant.io/integrations/switch.command_line/

Mmm… tried with it,
the switch button appears correctly on entities and is clicable but nothing happening.

Actual code:

switch:
  - platform: command_line
    switches:
      garage:
        friendly_name: Apertura garage
        command_on: curl -X POST http://shelly-10-eu.shelly.cloud/device/relay/control -d "channel=0&turn=on&id=a8032xxxxx&auth_key=MjcyN2F1axxxxxxxxxxx"
        command_off: curl -X POST http://shelly-10-eu.shelly.cloud/device/relay/control -d "channel=0&turn=off&id=a8032xxxxx&auth_key=MjcyN2F1axxxxxxxxxxx"

Tried also with and without the ’ at the start and end on curl command.

If i send the command via terminal i see this:
(it doesn’t work anyway)

Why not add the Shelly to home assistant using the core integration?

I assumed the device wasn’t on the same network as HA, as the OP is using Shelly Cloud instead of a local IP, but yeah. If the integration’s an option it’s super-easy to use.

I’ll have to see if I can do this Cloud method with my own Shelly devices.

I’m sad to say, I pasted your command_line code into my config, modified it to turn my Shelly Dimmer on and off using Shelly Cloud and… it worked. I now have a dumb switch that turns my light on/off via Cloud.

I did notice that Shelly had a disclaimer in the Cloud API documentation that said they could move your user to another server at any time. You might want to check that your URI is still correct.

Also… use HTTPS

Here’s my terminal from HAOS…

Test

Because the shelly is outside my lan and the the only way (that I know of) to do this is to go through the shelly cloud.

1 Like

@scy60 , solved by your suggest! :clap:
Twice problem:

  • adding HTTP S (sorry for my slip :slightly_smiling_face:)
  • check the server (changed from 2 days ago, pray dont change too frequently.)

@tom_l so i think this is the simplest way to do this, the actual native integration only support the local devices, right?

Correct

Great.
Thanks for your invaluable help!

Glad to help :wink:

I hope Shelly don’t stuff you up by frequently changing your server. It would be nice if they provided a static URI that adapted to changes behind the scenes, but I suppose not enough people are using the Cloud API.

Hello everyone, i’ve manage to set 3 Shelly 1PM Plus that i have in a different network working in HA, but now i saw an issue, the state of shelly’s is not updated correcly after a status change.

How can i fix this?