Possible to change LED effects from controller/domoticz?



  • I found a site with several led-effects for ws2812b strips. Is it possible somehow to "store" multiple effects in an arduino sketch and then somehow decide witch effect to run from the controller/domoticz?

    one effect looked like this:

    void loop() {
      SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
    }
    
    void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
      setAll(red,green,blue);
      
      int Pixel = random(NUM_LEDS);
      setPixel(Pixel,0xff,0xff,0xff);
      showStrip();
      delay(SparkleDelay);
      setPixel(Pixel,red,green,blue);
      showStrip();
      delay(SpeedDelay);
    }
    

    Another like this:

    void loop() {
      RunningLights(0xff,0xff,0x00, 50);
    }
    
    void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
      int Position=0;
      
      for(int i=0; i<NUM_LEDS*2; i++)
      {
          Position++; // = 0; //Position + Rate;
          for(int i=0; i<NUM_LEDS; i++) {
            // sine wave, 3 offset waves make a rainbow!
            //float level = sin(i+Position) * 127 + 128;
            //setPixel(i,level,0,0);
            //float level = sin(i+Position) * 127 + 128;
            setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                       ((sin(i+Position) * 127 + 128)/255)*green,
                       ((sin(i+Position) * 127 + 128)/255)*blue);
          }
          
          showStrip();
          delay(WaveDelay);
      }
    }
    


  • What I did for my thermostat controller to set the thermostat mode (Off, Heat, Cool, Auto) was to create a dummy switch as a selector.
    alt text
    When creating a selector switch, you can create custom selector levels. This is where I would put your different pattern selections.
    selector switch
    On the MySensors side, create a child node using S_INFO and V_TEXT. In my case, I named that "Furnace Mode" on the domoticz side. This is just the device that will pass the information to your MySensors device to do the switching. I then use a lua script in Domoticz that looks like this:

    --
    -- Thermostat mode switch to MySensors
    --
    commandArray = {}
    
    --if (devicechanged['Thermostat Mode'] ~= nil and (devicechanged['Thermostat Mode'] ~= otherdevices['Furnace Mode'])) then
    --   commandArray['Furnace Mode'] = devicechanged['Thermostat Mode']
    --   print('Setting thermostat mode to ' .. devicechanged['Thermostat Mode'])
    --end
    
    --if (devicechanged['Furnace Mode'] ~= nil and (devicechanged['Furnace Mode'] ~= otherdevices['Thermostat Mode'])) then
    --   commandArray['Thermostat Mode'] = devicechanged['Furnace Mode']
    --   print('Setting furnace mode to ' .. devicechanged['Furnace Mode'])
    --end
    
    if (devicechanged['Thermostat Mode'] == 'Off') then
        ttidx = otherdevices_idx['Furnace Mode']
        -- print("Furnace Mode idx: " .. ttidx)
        commandArray['UpdateDevice'] = ttidx..'|0|O'
        print("Furnace Mode = O")
    elseif (devicechanged['Thermostat Mode'] == 'Heat') then
        ttidx = otherdevices_idx['Furnace Mode']
        -- print("Furnace Mode idx: " .. ttidx)
        commandArray['UpdateDevice'] = ttidx..'|0|H'
        print("Furnace Mode = H")
    elseif (devicechanged['Thermostat Mode'] == 'Cool') then
        ttidx = otherdevices_idx['Furnace Mode']
        -- print("Furnace Mode idx: " .. ttidx)
        commandArray['UpdateDevice'] = ttidx..'|0|C'
        print("Furnace Mode = C")
    elseif (devicechanged['Thermostat Mode'] == 'Auto') then
        ttidx = otherdevices_idx['Furnace Mode']
        -- print("Furnace Mode idx: " .. ttidx)
        commandArray['UpdateDevice'] = ttidx..'|0|A'
        print("Furnace Mode = A")
    end
    
    return commandArray
    

    This is what takes the information from the dummy switch and converts it to the MySensors node. As you see the "|0|O", |0|H", "|0|C", "|0|A" , the O, H, C, and A are what you would test for in your MySensors node under your receive() function. The O, H, C and A can be anything you want, so you could name them "pattern1", "pattern2", etc... and in your lua script you would format like:

    commandArray['UpdateDevice'] = ttidx..'|0|pattern1'
    

    Hope that helps some.



  • Nice. I did not know about the selector switch in Domiticz. I will have to give it a try.

    I have an LED array that I keep by my bedside with 3 patterns. The primary is a sunrise alarm. Domoticz tells it when to turn on and then it gradually lightens in a sunrise like pattern. The next is a fake TV that I have Domoticz turn on randomly when away. The third is just a dimmable light -- It is supposed to respond to a button on the node itself, but I haven't made the hardware upgrade yet.

    I used a more brute force method. I present a different sensor ID for each pattern, then have three corresponding switches in Domoticz. To select a particular pattern, just turn that switch on in Domoticz. When the node receives a message, it checks which sensor ID the message is for and sets the corresponding pattern on or off as the message dictates.

    When your node switches patterns, have it send an Off message for the previously running pattern back to Domiticz, or the Domoticz switches will get out of sync.

    The selector switch seems more elegant, but having separate switches for each function is another approach.



  • The selector switch is a dummy switch device. Make sure you have "Dummy Devices" added under Setup > Devices. Under Type, select "Dummy (Does nothing, use for virtual switches only)". Then when you go to your "Switches" tab, click the "Manual Light/Switch" button at the top.



  • @AWI has a nice piece of code that is exactly what you are looking for, try searching for mood light here on the forum.


Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 20
  • 4
  • 9
  • 9

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts