Control Shelly bulb with a script: not able to get the color right

I am trying to control a shelly bulb with a script.
It works, but not quite the way I want it.
I can turn the bulb on and off, but I also want to add the color and I can’t.

My script is as follows:

Red-framed part goes well: switch the bulb on / off in turn.

But the yellow shaded part is not ok, I can’t get the color right.

What am I doing wrong; glad with all your suggestions and tips.

Best regards, Ko

The style you are using is Device Automation and produced when you use the Device Automation editor. This style isn’t well documented so it’s challenging to create/modify manually (in fact, it’s been said that it wasn’t designed to be manually created/modified).

The traditional way is well documented and is service-oriented as opposed to device-oriented. This is an example of turning on a light and setting its color:

  - service: light.turn_on
      entity_id: light.shelly_bulb_7914d8_light_0
      rgb_color: [0, 255, 63]

There are several other options available and they are listed here: Light service turn_on

As far as I know, you can use both styles within the same script.

Thanks you for your reaction.

But in which configFile should I further specify the service?

Is that in automation.yaml where I call the service …

… or in another place?

I have tried both automation.yaml and scripts.yaml but no result yet.

I have also seen that my bulb is not mentioned as a supported
integrations at

Regards, Ko

Your bulb is an mqtt light.

If you have posted you code properly formatted, I could have shown the changes that Tara’s proposed. But I’m not going to retype your screenshot.

In the same place as the script shown in your first screenshot. What I suggested should replace the portion that lies outside the red box.

You should know that by posting screenshots of your code it makes it very inconvenient for others to provide you with working examples. We have to type everything shown in the screenshot. I’m not willing to do that so, in the future, to get better service from people trying to help you, please post your code as text, not a screenshot.

Ok, thanks for the lesson regarding posting code, l will no longer use screenshots in the future.

My code in automations.yaml is as follows:

  • id: voordeur_open
    alias: Voordeur open
    description: Als voordeur open gaat gaat bulb in achterkamer aan
    • entity_id: sensor.sensative_strips_access_control
      from: ‘23’
      platform: state
      to: ‘22’
      condition: []
    • data: {}
      service: script.1586028919428

My code in scripts.yaml is as follows:

alias: frontDoor_open

  • brightness_pct: 20
    device_id: d9f0fddaa890471880270f96f7ead436
    domain: light
    entity_id: light.shelly_bulb_7914d8_light_0
    type: turn_on
  • delay: ‘3’
  • device_id: d9f0fddaa890471880270f96f7ead436
    domain: light
    entity_id: light.shelly_bulb_7914d8_light_0
    type: turn_off
  • delay: ‘1’
  • brightness_pct: 40
    device_id: d9f0fddaa890471880270f96f7ead436
    domain: light
    entity_id: light.shelly_bulb_7914d8_light_0

Good to know that my bulb is a MQTT–bulb. I assume that they way to configure it is according to the directions on this page Is that correct?

I notice that the config there is done there in configuration.yaml, while I was thinking in the direction of the two aforementioned configFiles. I guess I am on the wrong track and am happy with all your explanations.

Not necessarily.

Although everything can exist in one file (configuration.yaml), many people choose to separate it into multiple files, where each file represents either sensors, automations, scripts, scenes, etc.

For example, if I put this in configuration.yaml

script: !include scripts.yaml

I am instructing Home Assistant that my scripts are not in configuration.yaml but in a separate file called scripts.yaml. That’s what you appear to have done so that’s where you should continue to place your scripts, in scripts.yaml.

Ok, that makes sense – thanks for the explanation.

Since my bulb is a “mqtt device” I guess it must be possible to switch it on/off from the “developers tools MQTT” Tab in HA.

So I listened with “#” (and toggles the bulb on and off) resulting in the following messages:


  • “ison”: true,*
  • “mode”: “color”,*
  • “red”: 0,*
  • “green”: 255,*
  • “blue”: 63,*
  • “white”: 0,*
  • “gain”: 80,*
  • “temp”: 3175,*
  • “brightness”: 100,*
  • “effect”: 4*

*shellies/shellybulb-7914D8/color/0 *

So now I know the topics and payloads to switch the bulb on/off.
But applying them in the MQTT tab did not switch the bulb on or off.

Should this indeed be possible?

The use cases that I finally want to achieve is as follows:

  • I have a Z-wave door sensor.
  • If the door opens I want the bulb to flash green
  • If the door closes I want the bulb to flash red.

I created two automations that call a service if the door opens / closes - so far so good.

I implemented the use case by letting the automations trigger scenes that controls the bulb.

But Z-wave in combination with scenes seems not to be a good practice (resulting in errors) so now I am in the process of converting my scenes to scripts.

Is this a good approach?

I am struggling and fall from one problem to another……