Announcement

Collapse
No announcement yet.

Setting RGBW value directly with a script?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I use the FastLED library on the Arduino and i use snippets found on the net (source not known anymore)
    I hope i got everything together her for you. I had to piece it together out of a larger chunck i made.

    Global variables
    Code:
     
    // PULSE Variables
    uint8_t hueA;
    uint8_t satA;
    float valueMin;
     uint8_t hueB;
    uint8_t satB;
    float valueMax;
     
    uint8_t hue;
    uint8_t sat;
    float val;
    uint8_t hueDelta;
    static float delta;
     static float PulseSpeed;
    
    CHSV objHSVStart;  
    CHSV objHSVEnd;  
      
     CRGB colorRGBStart;
    CRGB colorRGBEnd;
    Methode configuration. Need to do this only once
    Code:
     void SetupEffect()
    {
          colorRGBStart.r = R;
         colorRGBStart.g = G;
         colorRGBStart.b = B;
      
          colorRGBEnd.r = R;
         colorRGBEnd.g = G;
         colorRGBEnd.b = B;
      
       objHSVStrat = rgb2hsv_approximate(colorRGBStart);
      objHSVEnd = rgb2hsv_approximate(colorRGBEnd);
      
       hueA     = objHSVStart.h;
      satA     = objHSVStart.s; 
      valueMin = objHSVStart.v
       hueB     = objHSVEnd.h;
      satB     = objHSVEnd.s;
      valueMax = objHSVEnd.v;
      if((valueMin + 20) > valueMax) {
        valueMax = valueMin + 20;
        if(valueMax > 255) valueMax = 255;
      }
       hue = hueA; 
      sat = satA; 
      val = valueMin;
      hueDelta = hueA - hueB; 
      delta = (valueMax - valueMin) / 2.35040238;  // Do Not Edit 
     }
    And call this methode each time in main()
    Code:
     
    void DoEffect(){  
       float dV = ((exp(sin(PulseSpeed * millis()/2000.0*PI)) -0.36787944) * delta); 
       val = valueMin + dV; 
       hue = map(val, valueMin, valueMax, hueA, hueB);  // Map hue based on current val 
       sat = map(val, valueMin, valueMax, satA, satB);  // Map sat based on current val 
        leds0[0] = CHSV(hue, sat, val); // This controles the LEDstring but you have to convert HSV back to RGB here end send that value to the device
    }
    VBscript code voor RGB to HSV to RGB conversie

    http://stackoverflow.com/questions/3...b-color-to-hsv

    Or

    http://www.xtremevbtalk.com/tech-dis...b-hsv-rgb.html

    Or

    http://stackoverflow.com/questions/4...b-color-values
    Last edited by AshaiRey; October 6th, 2016, 03:19 AM. Reason: Update

    Comment


    • #17
      Figured it out. There is a special property to use for setting custom color values, it is ControlString instead of ControlValue. It takes the hex string.

      Here is a method I use in C# - same way you were doing it, just with the new property:

      Code:
      public void SetRgbColor(int device, string color) 
      {	
      
      	HomeSeerAPI.CAPI.CAPIControl capiControl;
      
      	capiControl = hs.CAPIGetSingleControl(
      		device, 
      		true, 
      		"Custom Color(value)", 
      		false, 
      		false);
      
          capiControl.ControlString = color;
          hs.CAPIControlHandler(capiControl);       
      }
      The values you set are hex strings in the format #ff9000.

      Comment


      • #18
        Originally posted by skg View Post
        Figured it out. There is a special property to use for setting custom color values, it is ControlString instead of ControlValue. It takes the hex string.

        Here is a method I use in C# - same way you were doing it, just with the new property:

        Code:
        public void SetRgbColor(int device, string color) 
        {	
        
        	HomeSeerAPI.CAPI.CAPIControl capiControl;
        
        	capiControl = hs.CAPIGetSingleControl(
        		device, 
        		true, 
        		"Custom Color(value)", 
        		false, 
        		false);
        
            capiControl.ControlString = color;
            hs.CAPIControlHandler(capiControl);       
        }
        The values you set are hex strings in the format #ff9000.

        Fantastic! Thank you!
        HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
        Running on Windows 10 (64) virtualized
        on ESXi (Fujitsu Primergy TX150 S8).
        WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

        Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

        Comment


        • #19
          No script experience... so pardon the ignorance.

          Could you use this to create a custom animation that moved between 2 (or more) colors?

          Comment


          • #20
            Originally posted by Tomgru View Post
            No script experience... so pardon the ignorance.

            Could you use this to create a custom animation that moved between 2 (or more) colors?
            Yes you can!
            At least... sort of.

            HomeSeer is not made to be a DMX-controller, so you have to do a bit of cheating. I would set the fade time of the Z-wave node to a looong interval, and then add a recurring event that triggers every "interval" seconds to the new color.
            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
            Running on Windows 10 (64) virtualized
            on ESXi (Fujitsu Primergy TX150 S8).
            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

            Comment


            • #21
              Okay, my script doesn't work any more.

              Code:
              Sub Main(ByVal params As String)
                      Dim input() As String = params.Split(",")
                      Dim customRef As Integer = input(0)
                      Dim generator As New Random
              
                      Dim color(2) As Integer
                      For i As Integer = 0 To color.GetLength(0) - 1
                          color(i) = generator.Next(0, 255)
                      Next
              
                      Dim colorString = "#" & color(0).ToString("X2") & color(1).ToString("X2") & color(2).ToString("X2")
                      Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(customRef, True, "Custom Color(value)", False, False)
                      cc.ControlString = colorString
                      Dim ret = hs.CAPIControlHandler(cc)
                      hs.Writelog("Random Color", ret.ToString)
                  End Sub
              As far as I can tell it stopped working after updating the Z-wave plugin to version .190, but I can't figure out why it's not working.

              EDIT: It's funny. Right after posting this, I found the solution. Set the color string to this:
              Code:
              Dim colorString = color(0).ToString("X2") & color(1).ToString("X2") & color(2).ToString("X2")
              ... and it works again.
              HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
              Running on Windows 10 (64) virtualized
              on ESXi (Fujitsu Primergy TX150 S8).
              WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

              Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

              Comment


              • #22
                I am apparently a total noob on the scripting portion. I have a color selector for my qubino RGBW controller.
                I'm not following these scripts. I was just hoping to setup a virtual device and have a dozen preset colors for my controllers. Then I could just have a script that when I called for Red it would change the color selector to ff0000.
                Anyone know the best way to do that?
                I'm tried to copy and past those codes into a script but I feel like I am missing some parameters I need somewhere or some portions of the code.
                Thanks,

                Ok I wasn't able to figure out how to use the color selector but I did make a script that uses the Red blue and green selectors individually.
                I will include it here for those who need it. I have it setup with a slider, but you could do a drop down bar.
                This uses 5 parameters. one for the virtual device slider. One for the Light off (set as the 0) then one for each red green and blue slider levels. Click image for larger version

Name:	rgb slider.png
Views:	1
Size:	11.0 KB
ID:	1260421

                Code:
                Imports System.Text.RegularExpressions
                
                'The script requires 3 parameters to be passed to it separated by commas:  Slider Controller, Light Off Switch, Red, Green, Blue.
                    '    - Red is the red level value.
                    '    - Green is the green level value.
                    '    - Blue is the Blue level value.
                
                    Public Sub Main(ByVal Parms As Object)
                Dim ParmArray() As String = Parms.tostring.split(",")        'split parameter into an array
                    Dim Control As Integer = CInt(ParmArray(0))    
                        Dim Turnoff As Integer = CInt(ParmArray(1))
                        Dim Red As Integer = CInt(ParmArray(2))
                        Dim Green As Integer = CInt(ParmArray(3))
                        Dim Blue As Integer = CInt(ParmArray(4))
                        Dim Color As Integer= hs.CAPIGetStatus(Control).Status
                If Color = 1
                        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 255
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 255
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 255
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 2 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 255
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 0
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 0
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 3 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 255
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 86
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 170
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 4 
                      Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 212
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 170
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 255
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 5 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 212
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 0
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 255
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 6 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 86
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 170
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 255
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 7 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 0
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 0
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 255
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 8 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 0
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 255
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 0
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 9 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 255
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 255
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Blue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 0
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 10 
                 Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Red, True, "Red Level (value)", False, False)
                        cc.ControlValue = 255
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                
                        Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(Green, True, "Green Level (value)", False, False)
                        cd.ControlValue = 127
                        Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
                
                        Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(BLue, True, "Blue Level (value)", False, False)
                        ce.ControlValue = 0
                        Dim ct As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ce)
                
                Elseif Color = 0
                       Dim ce As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIControlHandler(hs.CAPIGetSingleControl(Turnoff,True,"Off",False,False))
                    End If
                    End Sub
                Last edited by Dekirts; November 18th, 2018, 06:16 PM.

                Comment

                Working...
                X