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:

3 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}}}}
1 Like

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).

5 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 }}
6 Likes

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

Hello! :slight_smile:

Thanks a lot Minizag for your suggested automation example, it helped me tremendously setting up my first scripts/actions/automation!

For anyone else reading this at a later time (like I did) I would like to add that the example is not entirely correct. The values for red, green and blue are not supposed to be in a range of 0-255, but a range of 0-100, as described by the Shelly documentation linked in the first post.

Cheers!

1 Like

Hi!
I’ve tried to implement this code today, but always getting the failure “Action rest_command.set_color not found” when running the script. My plug runs on newest stable firmware 1.5.1
Did they change something? Any suggestions what I’m doing wrong?
Thanks in advance!

edit: nevermind, my fault, I just reloaded the yaml configurations. After full restart of HA everything works perfect!

Can this same script also be used to switch the leds on/off?
I’ve tried to find the docs on Shelly but the cloud seems to be offline today

Just set all color values to 0

@Minizag Thanks so much. A small note. My Shelly Plug S has Firmware 1.2.3 and requires also the newer version.

Ah yes, I hadn’t thought about that option, thanks!

hi, i want to change the colors when there is a certain amount of watt.

0-30 watt green
30-100 yellow

100 red

how could i do this in HA?

1 Like

Very late to this conversation.
Beside a few template sensors I’m very new to yaml, so I hope somebody is kind enough to point me in the right direction.
I’m running HAOS on fully updated Green

Situation:
I copied the rest_command in configuration.yaml, did the reboot, like you (Minizag) posted.
But when trying to the save the yaml in a new script (Change Shelly color), I get the message:
“Message malformed: extra keys not allowed @ data[‘script’]”

Anybody here knows what this means? BTW I used Minizag’s updated yaml.

If you have rest_command, script and automation up and running, I’m struggling with this btw, maybe you can help me with that?
Then in HA it’s easy: use the power entity of the plug as a trigger in an automation and trigger the right color at a certain wattage

I recently purchased a Shelly Plus Plug S and needed to change the LED color.
I found @Minizag code and adapted it to the latest Home Assistant version available at the moment (2025.12.3).

New features:

  • RGB color selector
  • Brightness input
  • Countdown (OPTIONAL): Turns device off after a certain time
  • Sets RGB boundaries and corrected the variable descriptions according to the Shelly API.

Add to configuration.yaml:


Create a new Script:

IMPORTANT: Script Entity ID should be: script.change_shelly_led_color

Go to the three dots () menu → Configure as YAML

alias: Change Shelly LED color
description: Changes the color of the Shelly Plug
mode: parallel
max: 100
fields:
  ip:
    name: IP
    selector:
      text:
        multiple: false
    default: 192.168.1.224
    required: true
  rgb_color:
    name: RGB Color
    description: RGB color
    selector:
      color_rgb: {}
    default:
      - 255
      - 255
      - 255
    required: true
  brightness:
    name: Brightness
    description: Brightness value (0-100)
    example: 100
    selector:
      number:
        min: 0
        max: 100
        step: 1
        unit_of_measurement: "%"
        mode: slider
    default: 100
    required: true
  countdown:
    name: Countdown
    description: Countdown to turn device off after a certain time
    example: 100
    selector:
      number:
        min: 0
        max: 3600
        step: 1
        unit_of_measurement: seconds
        mode: slider
    default: 60
sequence:
  - action: rest_command.set_color
    data:
      url: >
        {% set red   = (rgb_color[0] / 255 * 100) | round(2) %} {% set green =
        (rgb_color[1] / 255 * 100) | round(2) %} {% set blue  = (rgb_color[2] /
        255 * 100) | round(2) %}

        {% set config = {
          "leds": {
            "mode": "switch",
            "colors": {
              "switch:0": {
                "on":  {"rgb": [red, green, blue], "brightness": brightness},
                "off": {"rgb": [red, green, blue], "brightness": brightness}
              }
            },
            "power": {"brightness": 100}
          }
        } %} http://{{ ip }}/rpc/PLUGS_UI.SetConfig?config={{ config | tojson |
        urlencode }}
  - alias: Turn off Shelly LED if countdown is set
    if:
      - condition: template
        value_template: "{{ countdown is defined and countdown | int > 0 }}"
        alias: if countdown is set
    then:
      - delay:
          seconds: "{{ countdown | int }}"
      - action: script.change_shelly_led_color
        metadata: {}
        data:
          ip: "{{ ip }}"
          rgb_color: "{{ rgb_color }}"
          brightness: 0
        alias: Turn Off Shelly LED

Run the script from an automation:

  1. Create a new automation.
  2. Add an action → Script → select the previously created script “Change Shelly LED color.”
  3. Select the Shelly parameters as you wish from the UI :tada:

Regards!

4 Likes

this is f**ing awesome!!

1 Like