Controlling RGB Strip WS2801, having multiple effects

Dear community,
I have completed this tutorial and everything is working so far. I can set colors with the color picker, but I’m having troubles with effects. I want to be able to set a firm color to the strip, but also want to be able to change between several effects(rainbow animation, etc.) Those animations are running in a while loop so the script will never stop and I can’t exit them. Is there an easy way to do this?

Thanks in advance,

While writing this I got an idea of a possible solution. I’m not firm in Python and I’m a bit rusty in programming so I don’t know if that would work. Also it’s pretty dirty.

while True:
setColor(r, g, b)
rainbow_cycle(pixels, wait=0.01)


It’s not clear, are you wanting to do this from openHAB Rules? There is nothing in that tutorial that is openHAB related. Are you controlling this from openHAB somehow? Are you wanting to write this behavior into openHAB Rules? Or is this just a generic programming question?

I’m so sorry. I have linked the wrong tutorial. The one I followed hasn’t been translated into English
In openhab I created a color picker that communicates via the execute add on with the strip and that is working. I can also start scripts with animation effects but with the restrictions I mentioned in the first post.
After doing some research I think I have to use node-red or node.js though.

I don’t think so but I don’t know enough to say for sure. There is a way to do a while loop like you asked about in openHAB Rules, either Rules DSL or using Scripted Automation Python. But what you posted doesn’t look like either of those so I’m still trying to figure out the context so I can tell you how.

So the problem is that if I’m starting a script from openhab, the script will never stop running because in the script itself there is a while true loop and won’t exit by itself (In the bash I’d just hit ctrl+C and start a new script). Starting a different script or trying to set a static color doesn’t work then anymore.
I’m not at my computer anymore, but this script is similar:

Thanks for your answers so far,

Have a look at the wled project for which there is an unmerged binding for on this forum.
Cheap esp8266 controller the firmware is all ready done and mqtt based. Rainbow fx and solid colours and far more is possible.

If you are connecting the LEDs directly to the Pi you could use my MQTTany software. You send commands via MQTT to trigger animations, or even change portions of the array directly. There are a few built in animations, or you can program your own.

If you want to control LEDs remotely you could get an sACN receiver that connects to your network and configure MQTTany to send commands to that device.

So don’t use a while True loop. There are lots and lots of ways to “keep doing something until X”. Even in a shell script, while True is almost never the proper approach.

For one example using Rules DSL: Design Pattern: Looping Timers.

In Scripted Automation Python you could do something like while items["Rainbow"] == ON: and it will only continue to loop while the Rainbow Switch Item is ON and stop as soon as it goes to OFF.

I’ll read into it, thanks a lot for your reply.

Thank you as well for your reply, this sounds promising.

1 Like

Unfortunately I can’t get it to work. If I just add the host address in the mqttany.yml it seems to run:

[20:37:31] openhabian@openhab:/opt/mqttany$ python3 mqttany/
2020-03-12 20:37:35,445 [INFO ] [mqttany ] MQTTany 0.10.2 starting
2020-03-12 20:37:35,593 [INFO ] [mqttany ] Process started successfully for module ‘mqtt’
2020-03-12 20:37:35,607 [INFO ] [mqttany.mqtt ] Connected to broker ‘’
2020-03-12 20:38:39,108 [INFO ] [mqttany ] Module ‘mqtt’ unloaded
2020-03-12 20:38:39,109 [INFO ] [mqttany ] MQTTany stopped

But as soon as I try to activate the LED section I get errors I don’t understand:

[20:43:12] openhabian@openhab:/opt/mqttany$ python3 mqttany/
2020-03-12 20:43:24,183 [INFO ] [mqttany ] MQTTany 0.10.2 starting
2020-03-12 20:43:24,212 [ERROR] [mqttany ] Config file contains errors
2020-03-12 20:43:24,212 [ERROR] [mqttany ] Traceback (most recent call last):
2020-03-12 20:43:24,213 [ERROR] [mqttany ]
2020-03-12 20:43:24,213 [ERROR] [mqttany ] yaml.parser.ParserError: while parsing a block mapping
2020-03-12 20:43:24,213 [ERROR] [mqttany ] in “/etc/mqttany/mqttany.yml”, line 229, column 3
2020-03-12 20:43:24,214 [ERROR] [mqttany ] expected , but found ‘’
2020-03-12 20:43:24,214 [ERROR] [mqttany ] in “/etc/mqttany/mqttany.yml”, line 250, column 5
2020-03-12 20:43:24,214 [ERROR] [mqttany ]

######## LED Module ########

  ### Module Topic
  topic: '{module_name}'

  ### Animation Directory
  # A directory or list of directories to look for additional animations in
  #anim dir: []

  ### Startup Animation
  # Animation to play when MQTTany loads
  anim startup: 'test.array'

  ### Animation Frame Rate
  # Frame rate for animations, you may need to decrease this for
  # longer arrays or certain interface types.
  #anim fps: 60

  ### Array Configuration
  array_name: 'testarray'

    ### Output
    # The interface to use for outputting data
    # Available options are 'rpi' or 'sacn'
    output: 'rpi'

    ### Array Topic
    # Additional Substitutions:
    # - {array_name} = will be replaced with the array definition section name
    #topic: '{array_name}'

    ### Pixel Count
    # The number of pixels in your array (not necessarily LEDs, see next option)
    count: 71

    ### LEDs per Pixel
    # Allows you to have more than one LED handled as a single pixel.
    # Ex. A bulb with 3 LEDs in it can be treated as a single pixel in the array.
    # Total number of LEDs in the array should be 'count' x 'leds per pixel'
    #leds per pixel: 1

    ### Initial Brightness
    # The initial brightness of the array, can be 0-255
    #brightness: 255

    ### Color Order
    # The byte order for the color data sent to the LEDs.
    # See the 'test.order' animation for how to determine this
    #color order: '{default}'

    ### Interface Specific Options
    # Each interface may have some options specific to it
    # consult the wiki page for the interface for details.

Trying to start it as a service doesn’t work as well, even with the LED module deactivated:

[20:52:10] openhabian@openhab:/opt/mqttany$ sudo systemctl daemon-reload
[20:52:24] openhabian@openhab:/opt/mqttany$ sudo systemctl enable mqttany
Created symlink /etc/systemd/system/ → /etc/systemd/system/mqttany.service.
[20:52:34] openhabian@openhab:/opt/mqttany$ sudo systemctl start mqttany
[20:52:55] openhabian@openhab:/opt/mqttany$ sudo systemctl status mqttany
● mqttany.service - MQTTany connects things to MQTT
Loaded: loaded (/etc/systemd/system/mqttany.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2020-03-12 20:52:55 GMT; 7s ago
Process: 3426 ExecStart=/usr/bin/python3 (code=exited, status=1/FAILURE)
Main PID: 3426 (code=exited, status=1/FAILURE)

Thanks in advance,

You have the array name line as a value, but it’s a section name.

Instead of

  array_name: 'testarray'

You should have


You will also need to look at the Raspberry Pi page for specific options like the GPIO pin option.

I actually went for your solution and I absolutely love WLED. Thanks a lot.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.