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 6, 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:	175
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 18, 2018, 06:16 PM.

                Comment


                  #23
                  I too hve been trying to create a color picker in HSTouch for a while also. I've temporarily given up in favor of mimicking the HS3 screen with only 72 color options:

                  Click image for larger version

Name:	Color Picker Screen.PNG
Views:	83
Size:	6.7 KB
ID:	1362187

                  When HSTouch sends the chosen hex code to the script:

                  Code:
                  'HS3 Script 2020-02-12  JG
                  Sub Main(ByVal parm As Object)
                  
                      Dim HexColor = parm(0).ToString ' Get Hex color from HSTouch
                  
                      Dim i, Length, Value, Temp, Result
                  
                      Length = len(HexColor)
                      for i = 0 to Length - 1
                          'get the characters one at a time (right to left)
                          Value = mid(HexColor, Length - i, 1)
                  
                          if (Value >= "0") and (Value <= "9") then
                          Temp = cInt(Value)
                          elseif (Value >= "A") and (Value <= "F") then
                          Temp = cInt(Asc(value) - 55)
                          elseif (Value >= "a") and (Value <= "f") then
                              Temp = cInt(Asc(Value) - 87)
                          else
                              ' if we get here then an illegal value was passed in
                              Result = -1
                              exit for
                          end if
                          Result = Result + Temp * 16^i
                      next
                  
                      Dim BulbREF = hs.GetDeviceRefByName("Custom RGB")
                      hs.SetDeviceValueByRef(BulbREF, Result, True)
                  
                      hs.writelog("BulbColor",CStr("Color changed to: " & HexColor & " (Hex), " & Result & " (Decimal)"))
                  
                      Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(BulbREF, True, "Custom Color(value)", False, False)
                      cc.ControlValue = Result
                      Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                  
                  End Sub
                  Regardless of whether I use hs.SetDeviceValueByRef or CapiControl (or in the case above - both methods... because I'm annoyed!), HS3 changes the color in the device screen as expected, but does not change the bulb color:

                  Click image for larger version

Name:	HS3 Bulb Device.PNG
Views:	93
Size:	50.5 KB
ID:	1362189

                  I still have to go into the color picker screen and hit OK before the bulb will actually change:

                  Click image for larger version

Name:	Color Confirm.PNG
Views:	86
Size:	40.1 KB
ID:	1362188

                  I've tried having the script send the OFF, ON, and LAST commands after the color change, but still no joy. In all cases, manually hitting that OK button in HS3's device screen is required to get the bulb to change to the desired color.

                  I'm using a Monoprice Z-Wave Plus RGB Smart Bulb.

                  Any idea what step I'm missing?

                  Comment

                  Working...
                  X