Announcement

Collapse
No announcement yet.

Set the colour from a vb.net script

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

    Set the colour from a vb.net script

    I've just started to try the Ikea plugin which initially looks great but I'm struggling with scripting in vb.net.
    I can use a simple CAPI command to turn a Tradfri light on or off, but how do I set the colour in a script? Does anyone have a simple example?

    #2
    For color you actually use the device string, not value, i.e. #FF0000.

    I tested now - it doesn't work from event. Looks like HS4 bug. spud?

    Comment


      #3
      Actually it does work. It was 1:30 AM when I was trying this🙄

      Comment


        #4
        I've tried loads of things but I can't use script (vb.net) to set a colour. Please can you give me an example that I can try?
        Thanks very much.

        Comment


          #5
          here is a C# example for a Hue bulb

          Code:
          public object Main(object[] parms)
          {
          hs.WriteLog("Script","Running huecontrol.cs");
          int colorControlFeatRef = 4468;
          string color = "001199";
          
          CAPI.CAPIControl[] controls = hs.CAPIGetControlEx(colorControlFeatRef, true);
          CAPI.CAPIControl ctrl = Array.Find(controls, c => (c.ControlType == Enums.CAPIControlType.Color_Picker));
          
          if (ctrl != null)
          {
          ctrl.ControlString = color;
          if (hs.CAPIControlHandler(ctrl) != CAPI.CAPIControlResponse.All_Success)
          {
          hs.WriteLog("Script", string.Format("Problem while trying to set device {0} to {1}", colorControlFeatRef, color));
          }
          }
          else
          {
          hs.WriteLog("Script", string.Format("Can't find color picker control for device {0}", colorControlFeatRef));
          }
          
          return 0;
          }

          Comment


            #6
            Thanks spud , I don't really get what's going on in your example? Can't we just directly set device string (status) to the string "001199"?

            Jez - if you can't get it working, I can expose a plugin function for setting color.

            Comment


              #7
              Originally posted by alexbk66 View Post
              Thanks spud , I don't really get what's going on in your example? Can't we just directly set device string (status) to the string "001199"?
              Updating a feature value does not send a control request to the plugin. Using the SDK you have to use SendControlForFeatureByValue to control a feature.
              It's the same thing for strings and color picker controls, updating the feature string will not control it, we need a SendControlForFeatureByString which does not exist yet. (There is already an existing feature request for this addition, https://forums.homeseer.com/forum/de...23#post1393923)

              So because of that you can't use the SDK for this, that's why my script above shows how to do it using the old HS3 API and CAPIControl (which still work with HS4 devices BTW)

              Comment


                #8
                Thank you for the explanation spud

                Comment


                  #9
                  I'd give it another try but I'm getting lots of warnings in the log: "Plugin AK Ikea is not responding but it is still running, not restarting yet."
                  I've tried to disable and re-enable the plugin to no avail.
                  Any ideas what's gone wrong?

                  Comment


                    #10
                    Sometimes HS can't stop the plugin and you need to kill it using task manager. If it keeps happening again, I need to investigate.

                    Comment


                      #11
                      Originally posted by alexbk66 View Post
                      Sometimes HS can't stop the plugin and you need to kill it using task manager. If it keeps happening again, I need to investigate.
                      Sorry for the delay in replying.

                      I've had a look at Spud's code but I find CAPI baffling beyond the command I use to turn a device on or off! So, please can you expose a plugin function for setting the colour.

                      Thanks very much.

                      Comment


                        #12
                        Originally posted by Jez View Post
                        I've had a look at Spud's code but I find CAPI baffling beyond the command I use to turn a device on or off! So, please can you expose a plugin function for setting the colour
                        Sure, I will have to refresh my mind as I haven't done it since HS3.

                        [EDIT]

                        Do you call any (other) plugins functions?

                        Comment


                          #13
                          Originally posted by alexbk66 View Post

                          Sure, I will have to refresh my mind as I haven't done it since HS3.

                          [EDIT]

                          Do you call any (other) plugins functions?
                          Yes, I call plugin functions in the JowieHue and Pushover plugins.

                          By the way, I've killed the Tradfri plugin in task manager and restarted the plugin and I'm still getting this in the log: "Plugin AK Ikea is not responding but it is still running, not restarting yet."

                          Comment


                            #14
                            Originally posted by Jez View Post

                            Yes, I call plugin functions in the JowieHue and Pushover plugins.

                            By the way, I've killed the Tradfri plugin in task manager and restarted the plugin and I'm still getting this in the log: "Plugin AK Ikea is not responding but it is still running, not restarting yet."
                            Ok, so this isnt going well! I saw you've released a new version so I installed it.
                            Then I enabled the plugin.
                            In the log I get this....

                            Code:
                            Finished initializing plug-in AK Ikea
                            Starting Plug-In
                            AK Ikea loaded in 443 milliseconds
                            Starting Plug-In
                            Plugin AK Ikea started successfully in 82 milliseconds
                            24/05/2021 14:28:15 AK Ikea ver. 4.0.0.20 (4.0.1.29)
                            Starting Plug-In
                            Initializing plugin AK Ikea ...
                            Plugin AKIkea with instance AK Ikea has connected. IP:127.0.0.1:62344
                            Interface AK Ikea is running as a trial, 25 days remaining.
                            
                            Then....
                            [2106] gw-c4ac59ea82cf: Supported CoAP endpoints: //15001, //15001/65539, //15001/65540, //15001/65541, //15001/65542, //15001/65544, //15001/65545, //15001/65546, //15001/65547, //15001/65548, //15001/65549, //15001/65550, //15001/65551, //15004, //15004/131073, //15004/131074, //15004/131075, //15004/131076, //15004/131077, //15004/131078, //15004/add, //15004/remove, //15005, //15005/131073, //15005/131073/196608, //15005/131073/196613, //15005/131074, //15005/131075, //15005/131076, //15005/131077, //15005/131078, //15006, //15010, //15011/15012, //15011/9030, //15011/9031, //15011/9034, //15011/9063, //15011/9094, //15011/9095, //15011/9102, //15011/9104, //15011/9110, //15011/9110/add, //15011/9110/remove, //15011/9110/update, //15011/9210, //sonos
                            Saved device: [Bridge] gw-c4ac59ea82cf (192.168.1.30:5684)
                            and finally.....
                            Plugin AK Ikea with ID: AKIkea and Instance: has disconnected

                            Code:
                            System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
                            at: System.Collections.Generic.Dictionary`2.get_Item(TKey key)
                            at: Tmds.MDns.NetworkInterfaceHandler.HandlePacketServiceInfos()
                            at: Tmds.MDns.NetworkInterfaceHandler.OnReceive(IAsyncResult ar)
                            at: System.Net.LazyAsyncResult.Complete(IntPtr userToken)
                            at: System.Net.ContextAwareResult.CompleteCallback(Object state)
                            at: System.Threading.ExecutionContext.RunInternal(ExecutionConte xt executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
                            at: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
                            at: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
                            at: System.Net.ContextAwareResult.Complete(IntPtr userToken)
                            at: System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
                            at: System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortC allback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
                            at: System.Threading._IOCompletionCallback.PerformIOCompletionCa llback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
                            
                            KeyNotFoundException - UnhandledException!!!: The given key was not present in the dictionary.
                            
                            The plugin then has:
                            CRITICAL: Plugin has disconnected.

                            Comment


                              #15
                              Thanks for posting the error, I'll check. Since the error is in Tmds.MDns library (used for device discovery) - I recommend to use Bonjour Print Services for Windows instead - after installing the service and restarting the plugin it should use Bonjour instead of Tmds, which is better option anyways.

                              Comment

                              Working...
                              X