Change Shelly plug S+ LED colors, stuck on RESTfull commands in HA

I’m trying to setup an automation to change the LED color of my Shelly plug S+. I have it working when i enter the REST command below in a browser, but i get stuck at how i have to format the RESTfull command in homeassistant correctly.

If i enter the following into my browser it works: (led turns blue, when shelly is on or off - you can also set different colors for on/off if you want).

http://<ip of shelly>/rpc/PLUGS_UI.SetConfig?config={"leds":{"mode":"switch","colors":{"switch:0":{"on":{"rgb":[0,0,100],"brightness":100},"off":{"rgb":[0,0,100],"brightness":100}},"power":{"brightness":100}}}}

However as this command uses “”, i can not just put in my configuration.yaml on the URL line as that also needs to be between “”, so it gets “cut off”

I assume i have to split it up in a URL part and a payload (or other type ? ) part, but this is where i get lost. I tried to split it up as follows (but this does not work):

  shelly_pink_collor_blue:
    url: "http://<IP of shelly>/rpc/PLUGS_UI.SetConfig?config="
    payload: '{"leds":{"mode":"switch","colors":{"switch:0":{"on":{"rgb":[0,0,100],"brightness":100},"off":{"rgb":[0,0,100],"brightness":100}},"power":{"brightness":100}}}}'

# and also this:
  shelly_pink_collor_blue:
    url: "http://<IP of shelly>/rpc/PLUGS_UI.SetConfig?"
    payload: 'config={"leds":{"mode":"switch","colors":{"switch:0":{"on":{"rgb":[0,0,100],"brightness":100},"off":{"rgb":[0,0,100],"brightness":100}},"power":{"brightness":100}}}}'

To be clear, i do have the shelly_pink_collor_blue as a service, but when i run it with the developertools, nothing changes on the Shelly.

ps if anyone else wants to play with this, be aware that the given numbers for the RGB color are in % (not the actual RGB values for some reason…). so for example 0,0,100 sets your shelly led to 0,0,255 (= blue). If you try to set values above 100, nothing happens. (and you do not get an error message)

my testing is done on the latest stable firmare (version 1.1.0, and my plugs are hardware version v2.)
Details on this API in shelly documentation can be found here:

2 Likes

Please try this with
“shell_command:”

In configuration.yaml:

rest_command:
    call_url:
        url: "{{ url }}"

and then with your HTTP Request

service: shell_command.curl
data:
  url: http://192.168.178.xxx/relay/0?turn=on&timer=1800

Thanks for the pointers, after some sleep and trying again, it is now working. turned out i could just leave out the ""arround the URL in the first place… this now works:

  shelly_pink_collor_blue:
    url: http://<shelly IP>/rpc/PLUGS_UI.SetConfig?config={"leds":{"mode":"switch","colors":{"switch:0":{"on":{"rgb":[0,0,100],"brightness":100},"off":{"rgb":[0,0,100],"brightness":100}},"power":{"brightness":100}}}}

This worked for me:

Configuration.yaml

yaml

rest_command:
  set_color:
    url: "{{ url }}"

Automations

Open a new script under Automations and go to the three dots (menu) → Configure as YAML:

yaml

description: Changes the color of the Shelly Plug
fields:
  ip:
    description: IP address of the Shelly Plug
    example: 192.168.11.73
    required: true
  red:
    description: Red value (0-255)
    example: 100
    required: true
  green:
    description: Green value (0-255)
    example: 100
    required: true
  blue:
    description: Blue value (0-255)
    example: 100
    required: true
sequence:
  - service: rest_command.set_color
    data:
      url: >
        http://{{ ip }}/rpc/PLUGS_UI.SetConfig?config={
          "leds": {
            "mode": "switch",
            "colors": {
              "switch:0": {
                "on": {"rgb": [{{ red }}, {{ green }}, {{ blue }}], "brightness": 100},
                "off": {"rgb": [{{ red }}, {{ green }}, {{ blue }}], "brightness": 100}
              }
            },
            "power": {"brightness": 100}
          }
        }

To Change the Color

Start the script in your automation with:

yaml

service: script.change_shelly_color
data:
  ip: "192.168.11.73"
  red: 0
  green: 100
  blue: 0

Replace the ip with your Shelly Plug’s IP address and adjust the color values as needed (0-100 for each color component).

2 Likes

Update: for Softwareversion on Shelly Plug later then 1.3.0 you need this code in the script:

script:
  change_shelly_color:
    description: Changes the color of the Shelly Plug
    fields:
      ip:
        description: IP address of the Shelly Plug
        example: 192.168.11.73
        required: true
      red:
        description: Red value (0-255)
        example: 100
        required: true
      green:
        description: Green value (0-255)
        example: 100
        required: true
      blue:
        description: Blue value (0-255)
        example: 100
        required: true
    sequence:
      - service: rest_command.set_color
        data:
          url: >
            {% set config = {
              "leds": {
                "mode": "switch",
                "colors": {
                  "switch:0": {
                    "on": {"rgb": [red, green, blue], "brightness": 100},
                    "off": {"rgb": [red, green, blue], "brightness": 100}
                  }
                },
                "power": {"brightness": 100}
              }
            } %}
            http://{{ ip }}/rpc/PLUGS_UI.SetConfig?config={{ config | tojson | urlencode }}
2 Likes

I been trying to get the previous code working the whole day and this fixed it instantly. Thanks a lot man!