Scripting help

Posted on
Fri Jan 28, 2022 11:09 pm
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Scripting help

I'm trying to write a simple script that will allow me to programmatically set RGB on bulb.

In the indigo-host interpreter, I can run
Code: Select all
indigo.dimmer.setColorLevels(169830322, 100,0,100)

and that works fine.

But when I create a script to run by indigo-host with parameters like this:
Code: Select all
import sys
indigo.dimmer.setColorLevels(169830322, sys.argv[1],sys.argv[2],sys.argv[3])


I get
Code: Select all
main.py: 'module' object has no attribute 'argv'


What gives?

Posted on
Sat Jan 29, 2022 7:40 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Scripting help

You're trying to write a script to run outside of Indigo to do this?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jan 29, 2022 12:46 pm
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

Yes, I'd like to set my light's RGB from a script

Posted on
Sat Jan 29, 2022 12:47 pm
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

Unless there is a way to trigger an Indigo Action remotely and pass parameters?

Posted on
Sat Jan 29, 2022 1:45 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help

I think you need to describe more fully what you're trying to do. Indigo python scripts must run in a special process (IndigoPluginHost). You can't pass command-line args directly to that, though you can pass a script itself. I suspect there are a variety of ways of solving your issue, but you need to be specific about what you're trying to do.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 30, 2022 9:02 am
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

Thank you for your response,
What I'm trying to do is modify an LEDFX script to change my bulb's RGB programmatically based on the current song, which means it's quite dynamic in nature. I'd also like to sync the bulb to a string of RGB lights running WLED.

Those two instances are really just the beginning.. I'm really looking at ways for external programs to modify the color / brightness of my bulb.

One alternative could be that I could use the REST Api, perhaps that would not incur much overhead and I can send rapid commands to change the bulb color brightness.

Posted on
Sun Jan 30, 2022 9:44 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Scripting help

Can you post the full script and explain the inputs ?

Posted on
Sun Jan 30, 2022 9:53 am
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

I haven't written a full script yet since I was just at the point of making sure the 'plumbing' worked before I head down this road.

Inputs would be four parameters:
red, green, blue (int: 0-255)
and brightness (float: 0-1)

Then, the various animation scripts I have written for NeoPixel (for example) could just add a call to the RGB bulb.. and example is this..

Here is a NeoPixel animation I wrote:
Code: Select all
class Rain(ColorCycle):
    """
    :param pixel_object: The initialised LED object.
    :param sky_color: The current color of the sky
    :param is_stopping: If the animation is stopping we gently fade to sky color
    """

    def __init__(self, pixel_object, current_sky_color: Tuple, is_stopping=False):
        self.is_stopping = is_stopping
        self.rain_sky_color = current_sky_color
        self.splash_color = (
            current_sky_color[0]*2,
            current_sky_color[1]*2,
            current_sky_color[2]*2
        )
        self.num_rain_drops = len(pixel_object) // 4
        super().__init__(pixel_object, 0.2, self.rain_sky_color)
        self.fill(self.rain_sky_color)
        self.show()

    def draw(self):
        # generate random raindrops
        if self.is_stopping:
            while self.num_rain_drops > 2:
                self.num_rain_drops = self.num_rain_drops - 5
                self.do_rain_effect()
                self.show()
                time.sleep(0.1)
            return
        self.do_rain_effect()

    def do_rain_effect(self):
        self.fill(self.rain_sky_color)
        for i in range(self.num_rain_drops):
            self.pixel_object[
                random.randrange(0, len(self.pixel_object))
            ] = self.splash_color


    def reset(self):
        self.fill(self.rain_sky_color)


You could imagine that on each animation loop I could set the LED bulb to the current animated color to sync with the LED Pixels I have.

Posted on
Sun Jan 30, 2022 10:37 am
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help [set color through REST?]

Following up after playing with the RESTful Api, is there any way to set the color of an RGB bulb through the REST interface?

The only attributes that show are:
Code: Select all
name : Office Overhead RGB Bulb
address : 0
addressStr : unknown
brightness : 85
classID : 2
desc : 003 - RGBW LED Bulb (LZW42)
devProtocol : 999
displayInUI : True
displayLongState : 85%
displayRawState : 85
folderID : 728699053
hasStateToDisplay : True
id : 169830322
isOn : True
lastChanged : 696846863
lastChangedDateStr : 2022-01-30
lastChangedRFC3339 : 2022-01-30T16:34:23Z
lastChangedRFC822 : Sun, 30 Jan 2022 16:34:23 GMT
lastChangedTimeStr : 08:34:23 AM
type : RGBW LED Bulb (LZW42)
typeFlags : 1555
typeIsDimmer : True
typeIsHVAC : False
typeIsLock : False
typeIsMultiIO : False
typeIsOpenClose : False
typeIsSensor : False
typeIsSpeedControl : False
typeIsSprinkler : False
typeSupportsDim : True
typeSupportsEnergyMeter : False
typeSupportsHVAC : False
typeSupportsIO : False
typeSupportsOnOff : True
typeSupportsSensorValue : False
typeSupportsSpeedControl : False
typeSupportsSprinkler : False
versByte : 0

Posted on
Sun Jan 30, 2022 11:11 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help

Unfortunately, no, we haven't added setting the color to the REST API.

I'm still unclear on the pieces that you are trying to hook together. Where are the inputs coming from? What technology is used to retrieve/calculate the inputs? We really need the whole picture in order to figure out the best solution.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 30, 2022 12:26 pm
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

The whole picture is this:

My current setup:
  • I have an RGB Light Strip controlled with an ESP8266 with WLED installed
  • I use https://www.ledfx.app which interfaces with WLED to send Music synchronized light effects. (sends each pixel individual RGB / Brightness values .. performing animations, etc...)
My goal
    Have a 'fill' color for bigger effects that syncs with the 'bass drop' as well as other low-end parts of songs using RGB bulbs in a diffusers
My steps
  • I purchased a few z-wave RGB bulbs.
  • I purchased a z-wave controller (aeon gen5+)
  • Added the controller and bulb to Indigo
  • I modified LedFX to send RGB / brightness for bass frequencies to an arbitrary device (JSON to a file right now)
  • Searched (in vein?) for a way to send those RBG / brightness values to my z-wave RGB light bulbs

At the end of the day, all I need is a simple way to QUICKLY update my lightbulb's RGB / brightness. Since my light is in Indigo via the Gen5 z-wave controller, then I would have hoped that I could just 'tell' Indigo to update my lightbulb's values from an external application.

Posted on
Sun Jan 30, 2022 3:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help

What I'm not understanding is which piece of the setup determines what the correct color should be? I don't know any of the specifics of those components so I may just have a fundamental lack of understanding with them...

[EDIT] - ok, after my 3rd reading maybe I get it. Let me think on it a bit...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 30, 2022 4:14 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help

Ok, so doing a little searching I think I have your solution. It looks like LedFX has an API, so what I propose is that you write an Indigo script to talk to that API to get the values, then update the devices appropriately. You could then run the script from a schedule as often as you like.

I did notice that apparently we have failed to update the IOM docs with the correct command to set the color of a device. This is what you would do:

Code: Select all
indigo.dimmer.setColorLevels(YOURDEVICEID, redLevel=0, greenLevel=100, blueLevel=0)


Basically, you were looking to push the color change to Indigo. Since we don't have that in the REST API yet, you'll need to pull the change from LedFX into Indigo. This is why I was asking so many questions about what you were doing in detail. :)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 30, 2022 4:27 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help

I suppose since you already have some JSON written out to a file that has the values, your script could instead of using an API just open the json file (if it's there), grab the values, set the device(s), then delete the file.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 30, 2022 9:00 pm
johnofcamas offline
Posts: 36
Joined: Jan 30, 2014

Re: Scripting help

jay (support) wrote:
I suppose since you already have some JSON written out to a file that has the values, your script could instead of using an API just open the json file (if it's there), grab the values, set the device(s), then delete the file.

I think that might be the ticket!

Thanks

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests

cron