Announcement

Collapse
No announcement yet.

CAPI Controls To Call Script

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

  • CAPI Controls To Call Script

    I suspect I am going a little crazy here and missing something obvious but I'll be damned if I can figure it out and wondering if anyone can help me.

    All I want is a device with a slider on it and then when this slider is moved a script is called to do something (which may be to then some serial data). I have done this a number of times with plugins but for a couple of reasons I don't really want to use a plugin.

    I create three VSPair's on a device, two buttons for on/off and another with the type of slider. All the pairs add correctly and have the right values, 0 for off, 100 for on and 1-99 for the dim level.

    I know in a plugin then when the device is touched it will call into the SetIOMulti function of the plugin which matches the .interface property. I've done it countless times in a plugin and know from there to look at the data, potentially set the device value from there or do something about it.

    I looked at the .ScriptName/.ScriptFunc properties however these seem to be only called when the value/string changes (eDeviceType_Script.Run_On_Value_Change etc).

    I think the issue is that when the CAPI control is manipulated then the value is not changed and the .ScriptName function never gets called, I am not quite sure as to the purpose of that function in that case other than to call a script when something else changes that devices value? Not really sure how often that would happen in practice and you could not just use a callback instead.

    I know there are commands like DeviceScriptButton_AddButton but I don't want a button for the dim I want a slider - surely it is possible to have a slider call a script?

    Thanks guys...
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

  • #2
    Hi Adam,

    Could you not run an event that triggers a script when the device value is changed?

    Cheers
    Al
    HS 3.0.0.532: 1963 Devices 1141 Events
    Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

    Comment


    • #3
      Hi Al...I think I may be getting closer (a problem written down sometimes helps) the problem I think is linked to the one I was having the other day whereby the status images show regardless of what the pairs are set to.

      If I specify an entry in the .Interface property then HS thinks that this device belongs to a plugin - fine - the documentation says that "This property holds the name of the plug-in that owns/manages this device. If the property is null or an empty string, the device is not managed by a plug-in." so that is to be expected. If I set this to something then the devices when changed must be trying to find a plugin matching the Interface property to call into SetIOMulti.

      Setting it to nothing now calls my script so I can confirm this does work as I expected it to. *However* even if I set up the VSPair's to my own settings the HS UI seems to have a difference in what to display which relates back to the other day when I was seeing status images that I did not want to see (http://forums.homeseer.com/showthread.php?t=166047) and setting the .Interface property solved that.

      As per the screenshot the Status Graphics page should be that the device has no prefix and a 'widgets' as the suffix. If I control the devices you can see that these settings are not what appears in the device and they still have their respective legacy Dim xxx % status's.

      I am not sure if this is a bug somewhere or perhaps something missing from the documentation so I have put it in a Bugzilla request #2487.

      Device Creation Code:

      Code:
      Sub CreateDevices()
      
          Dim CurrRef As Integer = 0
          Dim BaseRef As Integer = 0
          Dim dv As Scheduler.Classes.DeviceClass = Nothing
          Dim root_dv As Scheduler.Classes.DeviceClass = Nothing
      
          Try
              Log("Devices Do Not Exist - Creating")
              'four devices need to be created, root, current location, current time, am I at home
              For i As Byte = 0 To 5 'needs to be four new devices
                  Select Case i
                      Case 0
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("Root"))
                          dv.Address(hs) = DAddS & "-Root"
                          BaseRef = dv.Ref(hs)
                      Case 1
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("LED Channel 1"))
                          dv.Address(hs) = DAddS & "-Channel1"
                      Case 2
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("LED Channel 2"))
                          dv.Address(hs) = DAddS & "-Channel2"
                      Case 3
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("LED Channel 3"))
                          dv.Address(hs) = DAddS & "-Channel3"
                      Case 4
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("All LED Channels"))
                          dv.Address(hs) = DAddS & "-AllChannels"
                      Case 5
                          dv = hs.GetDeviceByRef(hs.NewDeviceRef("Fade Rate"))
                          dv.Address(hs) = DAddS & "-FadeRate"
      
                  End Select
      
                  dv.Location(hs) = "WifiRGB"
                  dv.Last_Change(hs) = Now
                  dv.Device_Type_String(hs) = DAddS & " Device"
                  'dv.Interface(hs) = DAddS
      
                  If i <> 0 Then dv.can_dim(hs) = True
      
                  Dim DT As New DeviceTypeInfo
      
                  DT.Device_API = DeviceTypeInfo.eDeviceAPI.Script
                  DT.Device_Type = DeviceTypeInfo.eDeviceType_Script.Run_On_Value_Change
      
                  dv.DeviceType_Set(hs) = DT
      
                  dv.ScriptName(hs) = "HS3RGBWifi.vb"
                  dv.ScriptFunc(hs) = "test"
      
                  Log("VSPair Clear: " & hs.DeviceVSP_ClearAll(dv.Ref(hs), True))
      
                  If i = 0 Then 'on the base device do this, set up the relationships between the devices
                      root_dv = dv
                      dv.Relationship(hs) = Enums.eRelationship.Parent_Root
                  Else
                      If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
                      dv.Relationship(hs) = Enums.eRelationship.Child
                      dv.AssociatedDevice_Add(hs, BaseRef)
                  End If
      
                  Select Case i
                      Case 0
                          hs.setdevicestring(dv.Ref(hs), "Root Device", True)
                      Case 1 To 5
                          Dim Pair As VSPair
      
                          Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                          Pair.PairType = VSVGPairType.Range
                          Pair.RangeStart = 1
                          Pair.RangeEnd = 99
                          Pair.RangeStatusSuffix = " Widgets"
                          Pair.Render = Enums.CAPIControlType.ValuesRangeSlider
                          pair.RangeStatusDecimals = 0
                          'Pair.ControlUse = Enums.ePairControlUse._Dim 'HSTouch?
                          hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
      
                          If i <> 5 Then                  
      
                              Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                              Pair.PairType = VSVGPairType.SingleValue
                              Pair.Status = "Off"
                              Pair.Value = 0
                              Pair.Render = Enums.CAPIControlType.Button
                              'Pair.ControlUse = Enums.ePairControlUse._Dim 'HSTouch?
      
                              hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
      
                              Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                              Pair.PairType = VSVGPairType.SingleValue
                              Pair.Status = "On"
                              Pair.Value = 100
                              Pair.Render = Enums.CAPIControlType.Button
                              'Pair.ControlUse = Enums.ePairControlUse._Dim 'HSTouch?
      
                              hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
      
                          End If
      
                          dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
      
                          hs.setdevicevaluebyref(dv.Ref(hs), 0, True)
      
                  End Select
      
                  hs.saveeventsdevices()
              Next
      
              Log("End Of Create Devices Routine - Calling Main Again")
              Main(Nothing)
          Catch ex As Exception
              Log("Create Devices Exception: " & ex.message.tostring)
          End Try
      
      End Sub
      Thanks for listening!
      Last edited by mrhappy; August 2nd, 2015, 04:52 AM.
      My Plugins:

      Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
      Yeelight 3P | Nanoleaf 3P

      Comment


      • #4
        How completely sh*t is it that this issue still exists two years later?

        I want a slider on the control screen for my device.
        I want it to run a script on change - just like buttons can!
        I do not want to have an event as a proxy (as the device is also updated external to HS and this would trigger the event)
        I do not want to write a plugin.

        I just want the dev's to provide working software that I paid $500 for.
        Hell, knowing they are even alive and not just drinking beers on my hard earned money would be good. I have submitted a ticket in my 30 day priority support period and nada.

        Or am I wrong? Can I have a slider that (directly) executes a script?

        Comment


        • #5
          Originally posted by davros View Post
          How completely sh*t is it that this issue still exists two years later?

          I want a slider on the control screen for my device.
          I want it to run a script on change - just like buttons can!
          I do not want to have an event as a proxy (as the device is also updated external to HS and this would trigger the event)
          I do not want to write a plugin.

          I just want the dev's to provide working software that I paid $500 for.
          Hell, knowing they are even alive and not just drinking beers on my hard earned money would be good. I have submitted a ticket in my 30 day priority support period and nada.

          Or am I wrong? Can I have a slider that (directly) executes a script?
          Well the value change script feature is broken as of late versions of HS so it's not a feature that works in any case. Unfortunately that's just the way it is and I've posted about it twice. Development/fixing old issues seems to have visibly slowed down and quite probably since Rick has less involvement with HS (or no involvement) Rich probably has his work cut out just keeping the lights on which is unfortunate but not sure what the answer is.
          My Plugins:

          Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
          Yeelight 3P | Nanoleaf 3P

          Comment


          • #6
            It's rather annoying though one must admit.

            Were it not for you and a few stallwarts...me thinks this place would consist of a lot of single posts!

            Comment


            • #7
              Had a look at the bugzilla and it's listed as "Enhancement" !

              Yes, we intended it to not work....ummmm....

              Importance: --- enhancement
              Assigned To: Richard Helmke

              Comment

              Working...
              X