AppDaemon calculating smooth dimming curve @ ~30ms intervals?

Hello! I am using AppDaemon so that I can send RGB pixel data over my local network using sACN (E1.31) and I have it working and controlling the pixels in my backyard!! (Currently only unicast is working … I haven’t gotten multicast working yet…maybe a VM problem)

So if I want to use AppDaemon to generate a continuously smooth fading rainbow, what is the best way? I can use the scheduler and a for loop to load all the pixels with data that morphs along the string… but how do I keep updating it at ~30fps? Do I call the scheduler at 30ms intervals or do I need to setup some kind of childprocess that does the smooth dimming curve calculations? Any guidance on the best approach would be helpful. Thx!

VoltVisionFrenchy (aka Steve French)

Are you talking about a synced cascading rainbow across multiple different rgb controllers? This is not easy, maybe It can be done with python idk. Typically this is achieved with a separate program like xlights.

Lets talk about timing only and not worry about quantity of lights. Lets just say I have one white light. Can I use AppDaemon to do smooth dimming on this light and have access to the brightness variable in AppDaemon as it fades? The HASS “light” integration has a notion of “transition time”. When you turn the light on/off it does a very smooth fade with no noticeable stepping, this must kick off some form of parallel process alongside HA that runs in a fast loop? Is this possible in AD? If I have access to this “smoothly changing variable”, then ideally I can programmatically do things with it @ ~30fps. It might run the processor a little hot during the transitions, but I can manage that tradeoff.

PS - When you say “multiple different RGB controllers”, that is all handled by the sACN multicast pub/sub protocol, so you reminded me that my question really is not about the number of lights, but is about the timing of smooth dimming for just one light. Also, thanks for sharing xLights! That looks great. For this particular project I want to try to keep it HA-only without any external addons (except official AD). There are plenty of processor cycles to spare!!

I understood this as a function of the firmware of the light. That a time transition value is sent and the bulb’s firmware controls the steps. Rather than sending multiple commands for each step.

Taking a quick look that seems to be the case. In order to do this yourself you’d have to define each step. It’s always possible something has changed or there is some under documented service call that can.

I just thought of ledfx and it’s part python. Perhaps you can find something in the code. Otherwise it may be something to use rather than xlights. It has an api.

@Mikefila thanks for the pointers and references! I have it working!! I actually read that first thread a few weeks ago, but I guess I didnt understand what @ReneTode was saying when he said “you could try it wit time.sleep in between the commands but i dont think you get the effect you like.” …but I understand now.

I tried what he said and I have it working with very smooth rainbow fade!! I set up a “run_every” to happen every 3.5sec…then when it runs, I do a for loop with 255steps and time.sleep(0.01). So each for loop should take 2.55sec, but I am actually seeing this:

2021-05-31 09:19:48.498613 INFO FrenchyLightSynth: Measure Duration: 0:00:03.480803
2021-05-31 09:19:51.440105 INFO FrenchyLightSynth: Measure Duration: 0:00:02.920692
2021-05-31 09:19:55.495802 INFO FrenchyLightSynth: Measure Duration: 0:00:03.483780
2021-05-31 09:19:59.109597 INFO FrenchyLightSynth: Measure Duration: 0:00:03.592148
2021-05-31 09:20:02.309427 INFO FrenchyLightSynth: Measure Duration: 0:00:03.176102
2021-05-31 09:20:05.675508 INFO FrenchyLightSynth: Measure Duration: 0:00:03.157337
2021-05-31 09:20:09.461620 INFO FrenchyLightSynth: Measure Duration: 0:00:03.449947
2021-05-31 09:20:12.904251 INFO FrenchyLightSynth: Measure Duration: 0:00:03.381226
2021-05-31 09:20:16.514972 INFO FrenchyLightSynth: Measure Duration: 0:00:03.501479
2021-05-31 09:20:19.822997 INFO FrenchyLightSynth: Measure Duration: 0:00:03.291157
2021-05-31 09:20:23.772217 INFO FrenchyLightSynth: Measure Duration: 0:00:03.753606
2021-05-31 09:20:27.332304 INFO FrenchyLightSynth: Measure Duration: 0:00:03.543118
2021-05-31 09:20:30.734339 INFO FrenchyLightSynth: Measure Duration: 0:00:03.373076

So I am starting to think about things in terms of a musical sequencer…the beginning of each measure kicks off a “run_every”, then the for loop does smooth calculations for that measure. The only challenge is that the timing isnt deterministic. The AppDaemon “info tab” is saying 3.5% CPU usage, so not sure why the above timing is so loose. I dont think its a CPU problem.

I will play around with this to see if I can make it work. Having been a professional bass player for years, I know that as long as the beginning of the measure is OK (the one), then the end of the measure can be sloppy…as long as the one comes back around at the right time!

Thanks again. I will try to post a video of the smooth rainbow later tonight.

PS - You were correct pointing out that the “transition” of the HASS light integration is intended to fire off a fade that is calculated inside of the actual light’s firmware…but the reason that does not apply here is because I am actually sending out brightness data over a network protocol that was designed and intended to receive updates @ ~30fps…so I dont think @ReneTode’s comment applies when he commented that firing off lots of “turn_off” commands “will put quite a load on your system”. I am just publishing data to a network-based protocol which was built for this.

I believe drift is to be expected hence the need for dedicated sequencing software, especially across multiple instances. Ledfx has a decent music sequencer, it’s why I use it.

The effects are written in python and the ones labeled reactive sync with music. You should be able to gain some insight of different methods to manipulate color/brightness.

Mikefila,
When I was building this system earlier this year I was challenging myself to do everything inside of home assistant because I was running the supervised version and as such, did not have access to the standard Linux command line to install independent apps like the LedFX program that you mentioned.

Do you run LedFX alongside HA? Do they talk to each other ?

Ps- I had my AppDaemon program running all summer at a festival site and the smooth rainbow fades were awesome, but I had to reboot AppDaemon every couple of days (before concert events) because it would start getting jittery and throwing log messages like this:

2021-06-04 22:42:09.696497 INFO AppDaemon: thread-2 - qsize: 74144 | current callback: idle | since 2021-06-04T22:42:04-04:00, | alive: True, | pinned apps: [‘FrenchyLightSynth’]

2021-06-04 22:42:09.700042 WARNING AppDaemon: Found stale callback for FrenchyLightSynth - discarding

2021-06-04 22:42:14.701224 INFO AppDaemon: Previous message repeated 16004 times

I had AppDaemon controlling two 100ft outdoor pixel strings and about 20 different large dmx washlights in the trees … all working together in sync. People loved it and the smooth rainbow was a hit for pride weekend.

I am still intrigued about building a multi universe sACN pixel system inside HA, but as a hardware guy, I am often doing things that would make real programmers cringe. Wled is interesting, but only does sACN slave, not master.

Thx!
VoltVisionFrenchy (aka Steve French)

The wash lights in the trees would smoothly change along with the smooth pixel string rainbow…the theme was “smooth slow moving rainbow”… next year I hope to have different presets that people can choose from a public-facing phone ui…

1 Like

Lighting effects was my first attempt at writing code and what got me into coding. I have all sorts of effects.

Here is an example piece of lighting effect code I wrote for appdaemon that does an auroa effect. This code is very old I would refactor it with numpy for faster calculations ,but it shows you that anything is possible.

Auroa Appdaemon