Correcting RGB Color Value Scales for FLUX LED Strip plugin devices in Indigo – Python Scripting

Standard

I ran into a very frustrating problem last night while trying to work on some scripting within Indigo for controlling the LED colors of a new LED strip. I had no problem with actually controlling colors using the built-in UI tools for updating colors, but a slightly more complex usage presented a major problem.

The issue started with a need to save the current state of the individual RGB values in the LED strip, before I apply a change, such as when a notification occurs. This is to ensure that after a notification “flash” occurs that the colors will go back to the same values they were before the notification.

Via scripting, I had no problem getting the values. The problem occured when I went to restore the values. As it turns out, I struggled with this issue most of the night until I finally figured out that it was a difference between how the UI treats RGB values and how they are actually stored in the device.

The problem is that I was retrieving RGB values that were based on a scale with a minimum of 0 and a maximum of 255, but when I passed these values back the UI was converting those numbers, incorrectly, into values on a scale of 0 to 100. Eventually, I realized that before I can restore the individual color values, I must first convert them to the UI’s scale.

In addition, and perhaps I confused this with that issue, before I figured it out, I also had problems changing the color more than once in the same script. This may have been more of a timing issue (a kind of race condition) so I split the two scripts into seperate actions with a 5 second dely for the second script.

Here’s the first script that reads the LED strip’s color values and stores them into Indigo variables. The last line changes the RGB settings to display a yellow color, for notifications.

dev = indigo.devices[1681458792]
indigo.variable.updateValue(indigo.variables[872936515],value=unicode(int(dev.redLevel)))
indigo.variable.updateValue(indigo.variables[770189775], value=unicode(int(dev.greenLevel)))
indigo.variable.updateValue(indigo.variables[753658911], value=unicode(int(dev.blueLevel)))
indigo.variable.updateValue(indigo.variables[1059165341], value=unicode(int(dev.brightness)))
indigo.dimmer.setColorLevels(dev, 100, 100, 0, 0)

The first ID used represents the Indigo ID for the LED strip. The other four IDs are for the Indigo variables. All of these devices are unique to my Indigo setup, my devices and my variables. The correct values can easily be acquired by right-clicking (or Control-click) on the item within Indigo to select the ‘Copy ID’ option.

The next part of the script restores the value of the individual color variables. It first converts each value to an integer (all Indigo variables are stored as strings, so they must be converted for this type of usage) and then do some simple math to convert the RGB values to the appropriate scale. The original equation I found had more components but I removed them since the minimum value in both scales is always zero; by removing the zeros it had no effect on the final calculation.

Note that RGB values being set should be integers as well, before being used to actually change the color values.

dev = indigo.devices[1681458792]
valRed = ((int(indigo.variables[872936515].value) * 100) / 255)
valGreen = ((int(indigo.variables[770189775].value) * 100) / 255)
valBlue = ((int(indigo.variables[753658911].value) * 100) / 255)
indigo.dimmer.setColorLevels(dev, int(valRed), int(valGreen), int(valBlue), 0)

So far, this seems to be working properly.

Restarting an Active Plugin in Indigo 7 – Python Scripting

Standard

The Indigo Smart Home platform supports plugin development. In addition to the built-in plugins, my setup also has a few custom plugins developed by third-parties. Every now and then the plugins need to be restarted (reloaded). I decided to setup a scheuled proces to restart a plugin and fortunately, this can easily be one via scripting within Indigo.

For security reasons it is only possible to reload an active plugin. One cannot load a plugin that isn’t already enabled.

The python script required to do this is very simple, within Indigo.

plugin = indigo.server.getPlugin("uk.co.greensky.flux")
if plugin.isEnabled():
 plugin.restart()

In this example I’m restarting the FLUX LED plugin. You’ll need to replace uk.co.greensky.flux with the appropriate plugin ID. I wasn’t able to find the plugin IDs directly within Indigo but they can be obtained by looking at the plugin filenames located inĀ /Library/Application Support/Perceptive Automation/Indigo 7/Preferences/Plugins/ and leaving off the “.indiPref” file extension.

 

 

Using a Multi-Color LED Bulb to Visually Indicate the High Temperature Range for the Day (Zipato RGBW LED & Indigo 6)

Standard

IMG_1324

In the morning, when I first get up, I walk past a motion sensor. A moment later a lamp with a color-changing bulb illuminates, glowing a specific color to indicate the temperature range that will include today’s forecast high temperature. With just one glance I know whether or not I should take a jacket before I step outside.

It’s been a long time since I last spent any significant amount of time focused on home automation but I recently made up for lost time by eliminating the last of my Insteon gear. All of the home automation gear is now Z-Wave compatible. But why stop there and not take the opportunity to add new enhancements?

In general, I’m uninterested in bulbs that can be directly controlled themselves, such as Z-Wave or wifi enabled light bulbs. They certainly have their applications but I don’t find them very practical for normal use. They still require that a light switch is left in the ON position in order to function. This breaks down very quickly when guests come to visit. For example, even with a remotely controlled lamp on an appliance or dimming module I often discover that instead of using the provided remotes our guests have simply turned the guest room lamp off using the traditional lamp switch. It’s just a normal, reasonable action.

My reason for purchasing a Z-Wave controlled, color-changing LED bulb certainly wasn’t a typical one. In this case I purchased one to use with my home automation system as a supplemental notification method, though for this particular project it is actually the only notification method used.

Continue reading