Announcement

Collapse
No announcement yet.

Setting a Custom Color w/RGB Bulb

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

    Setting a Custom Color w/RGB Bulb

    This is one that has been on the backburner for a while, but recently the wife asked why she can't get the color she wants. I suppose now I'll have to look into it again.

    I created a simple color picker box that sends the desired hex code to the Monoprice RGB bulb from HSTouch.

    Click image for larger version

Name:	Color Picker.PNG
Views:	151
Size:	35.8 KB
ID:	1427754

    The code gets there ok as you can see from the device below on device 452:

    Click image for larger version

Name:	Monoprice RGB Device.PNG
Views:	84
Size:	58.5 KB
ID:	1427755

    The problem is, the bulb won't change color unless I go to the the HS3 device screen, press the color picker box to the right of the hex code, then press OK on the color picker dialog box. Not even close to ideal for the WAF!

    Obviously, I want it to do all of this via HSTouch.

    I've tried events, & scripting. Scripts have been hs.device... or capi control.

    None of it works.

    I don't typically use capi control, so I went to TenScriptAid to get the proper syntax, but when I hit execute in the app for the Custom Color device, the app hangs and has to be killed.

    Does anyone have any suggestions for the Monoprice bulb? Is there a different RGB bulb that anyone has had success controlling through HSTouch?

    #2
    I would try creating a virtual device to hold the custom color value. Then use an event 'if virtual device had a value just set or changed' then set monoprice bulb custom color to that value.
    HS4 Pro on Shuttle NC10U, Win10; Z-NET
    Number of Devices: 449
    Number of Events: 210

    Plug-Ins: Arduino, BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, WeatherXML, Worx Landroid, Z-Wave

    External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

    Comment


      #3
      Thanks for the suggestion. Just tried that real quick before work, but didn't work. Use this script to put the value into the virtual device:

      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("Alexa RGB Bulb")
      
      '	hs.SetDeviceValueByRef(BulbREF, Result, True)
      
      '	hs.SetDeviceStringByName("Alexa Living Room TGB",User1Name,true)
      
      	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)
      
      '	hs.TriggerEvent("Turn On Custom RGB Bulb")
      
      End Sub
      The commented out lines were other ways I tried to make it work.

      Using easy trigger to set the Custom RGB to the virtual device value did not change the value in the bulb's device. Also didn't work using a direct script in an event.

      I'm sure I got the syntax wrong, but I'll try again tonight.

      The original script I had did put the value in the device - it just didn't turn on the bulb.

      Comment


        #4
        Does the bulb support MQTT? Successfully deployed an HStouch color picker here via MCSMQTT.

        Comment


          #5
          Originally posted by jgreenberg01 View Post
          Thanks for the suggestion. Just tried that real quick before work, but didn't work. Use this script to put the value into the virtual device:

          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("Alexa RGB Bulb")
          
          ' hs.SetDeviceValueByRef(BulbREF, Result, True)
          
          ' hs.SetDeviceStringByName("Alexa Living Room TGB",User1Name,true)
          
          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)
          
          ' hs.TriggerEvent("Turn On Custom RGB Bulb")
          
          End Sub
          The commented out lines were other ways I tried to make it work.

          Using easy trigger to set the Custom RGB to the virtual device value did not change the value in the bulb's device. Also didn't work using a direct script in an event.

          I'm sure I got the syntax wrong, but I'll try again tonight.

          The original script I had did put the value in the device - it just didn't turn on the bulb.
          If all it didn't do was turn on the bulb, then make an event that monitors for the color value to change and then turn it on.

          HS4 Pro on Shuttle NC10U, Win10; Z-NET
          Number of Devices: 449
          Number of Events: 210

          Plug-Ins: Arduino, BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, WeatherXML, Worx Landroid, Z-Wave

          External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

          Comment


            #6
            Originally posted by jmaddox View Post

            If all it didn't do was turn on the bulb, then make an event that monitors for the color value to change and then turn it on.
            That's the problem, there is no On/Off switch for the custom RGB control, you have to open the dialog box and hit OK. Red, Green, and Blue each have their own, so maybe there's a way to get the individual vales to get to the color I want.

            Or maybe I'll just try another bulb because this is way down on my priority list - although it's on my wife's radar (which kinda affects my priority list).

            On another note - you successfully deployed a color picker in HSTouch? Is it a simple one like mine or the full blown version?

            I'd love to see it if you don't mind!

            Comment


              #7
              does the switch multilevel not turn the light on/off?

              I use events to control my RGB outside lighting. Although I feel your pain. I spent one night with the wife while she picked out every months color and if the lights should all be the same or alternate colors.

              I have one other thought. if the custom color is not working for you. Perhaps utilize the color channels. She picks the color, you convert to channels and set those instead of the custom color. Should be dead simple with preset options. However I'll bet there is some formula to use to convert a hex color to individual color channels.
              HS4 Pro on Shuttle NC10U, Win10; Z-NET
              Number of Devices: 449
              Number of Events: 210

              Plug-Ins: Arduino, BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, WeatherXML, Worx Landroid, Z-Wave

              External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

              Comment


                #8
                Originally posted by jgreenberg01 View Post

                you successfully deployed a color picker in HSTouch? Is it a simple one like mine or the full blown version?

                I'd love to see it if you don't mind!
                Here it is: https://www.youtube.com/watch?v=sRu0...ature=youtu.be

                It is a complete version with HSB selection, CT when available and standard presets colors.
                Sliders and/or any element can change color based on current setting.
                As mentioned, it's based on MQTT so the devices have to support it.

                MQTT doesn't require to confirm commands, the settings are applied the second they are published.

                The last thing I'm working on is to change presets on the fly based on currently set color.
                I have all the working pieces, just need to assemble the scripts/events.
                Should be done soon.



                Comment


                  #9
                  Thank you @123qweasd - that video is really impressive. I'll try that next.

                  I got it to work without MQTT by changing the R, G, and B devices values. Using the HSTouch color picker box shown in the first post, the hex code is sent to a script which changes it to the proper decimal individual RGB numbers then changes the channels with Capi Control commands I got from TenScriptAid.

                  Interestingly enough, the hs.SetDevice commands in the following script would change the individual RGB device values but not turn on the bulb. Turning the multilevel switch on off and on also had no effect either. Only Capi Control worked:

                  Code:
                  'HS3 Script 2020-10-24  JG
                  Sub Main(ByVal parm As Object)
                  
                  	' Get Hex color from HSTouch
                  	Dim HexColor = parm(0).ToString
                  
                  	' Extract the hexidecimal R, R, B values
                  	Dim H1 = mid(Hexcolor, 1, 2)
                  	Dim H2 =  mid(Hexcolor, 3, 2)
                  	Dim H3 =  mid(Hexcolor, 5, 2)
                  
                  	' Convert hex to decimal values
                  	Dim R As Integer = Convert.ToInt32(H1, 16)
                  	Dim G As Integer = Convert.ToInt32(H2, 16)
                  	Dim B As Integer = Convert.ToInt32(H3, 16)
                  
                  '	These only change the device values, but do not affect the bulb
                  '	hs.SetDeviceValueByName("Color Control Red Channel", R)
                  '	hs.SetDeviceValueByName("Color Control Green Channel", G)
                  '	hs.SetDeviceValueByName("Color Control Blue Channel", B)
                  
                  	hs.writelog("BulbColor",CStr("Red changed to: " & R & ", Green changed to: " & G & ", Blue changed to: " & B))
                  
                  	' Capi Control commands for each color channel
                  
                  	Dim ccR as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(449, True, "Red Level (value)", False, False)
                  	ccR.ControlValue = R
                  	Dim crR as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ccR)
                  
                  	hs.waitsecs(0.1)
                  
                  	Dim ccG as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(450, True, "Green Level (value)", False, False)
                  	ccG.ControlValue = G
                  	Dim crG as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ccG)
                  
                  	hs.waitsecs(0.1)
                  
                  	Dim ccBl as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(451, True, "Blue Level (value)", False, False)
                  	ccBl.ControlValue = B
                  	Dim crBl as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(ccBl)
                  
                  End Sub
                  Next up when I have time (or wife wants 16m colors), sliders like in the video!

                  Thanks for all the help guys, this forum is the best!!!

                  Comment

                  Working...
                  X