Announcement

Collapse
No announcement yet.

Learning HS3 - Virtual Device Question

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

    Learning HS3 - Virtual Device Question

    Hello all,

    My question is about general strategy in reference to controlling serial devices.

    I'm not sure if my approach is the correct/best way but this is what I've figured out. I'd like to know if I'm doing it right or not.

    I have an amplifier I'm controlling with a serial cable. I have the serial scripts written to do:
    1. Turn on
    2. Turn off
    3. Volume control (values 0-38)


    I have created a device, then created 3 statuses:
    1. value=0 , All Off
    2. value=100, All On
    3. value=10-48 (value offset 10 to make it 0-38), volume control



    Then, I have created an event group that runs the appropriate script based on the value of the device.



    For basic on/off (ie values 0 or 100), the event works fine running the script which turns the device on/off. I intended on doing the same for the volume control, but I thought I would ask if my approach is the correct method.

    In summary, is the way one would control devices by
    1. Creating the device
    2. Populating the appropriate values
    3. Create event to execute script based on value changes

    Please enlighten me.

    thanks,

    Marco
    Attached Files

    #2
    Don't see anything particularly wrong with that approach, the devices can be as powerful or as simple as you want them but I am unsure whether you are better keeping the volume and on/off as separate devices - can you set the volume before you turn the zone on? There is the ability to create devices by script (rather than you have to create 12 or however many by hand) but this can get a little complex in places.

    There are also options with using functions like http://homeseer.com/support/homeseer...pe_script.html which could potentially eliminate the need for the events and also the possibility of running a single script rather than separate ones but if you are happy with what you are doing there is nothing wrong with it...

    Comment


      #3
      Originally posted by mrhappy View Post
      Don't see anything particularly wrong with that approach, the devices can be as powerful or as simple as you want them but I am unsure whether you are better keeping the volume and on/off as separate devices - can you set the volume before you turn the zone on? There is the ability to create devices by script (rather than you have to create 12 or however many by hand) but this can get a little complex in places.
      Ahh...thank you. Glad to hear i'm not doing something way-off. Your feedback makes sense. Thank you.

      My background is mainframes and unix systems, so not very fluent in vbs. However, i'm sure i can look at examples and write a function that can handle different permutations as a way to minimize devices/events.

      As far as device management goes, if I was to follow down this path, and lets say i split out volume to another device, i could conceivably end up with 20-50 devices. Device management will then be a concern. Is floor/room really the only (or best) way to organize all of the amp-related devices? How many devices can HS3 handle on something like a hometroller S6 (celeron)? That also means there would be 20-50 events monitoring the devices. Seems messy. Thoughts?

      Comment


        #4
        Originally posted by marco500 View Post
        Ahh...thank you. Glad to hear i'm not doing something way-off. Your feedback makes sense. Thank you.

        My background is mainframes and unix systems, so not very fluent in vbs. However, i'm sure i can look at examples and write a function that can handle different permutations as a way to minimize devices/events.

        As far as device management goes, if I was to follow down this path, and lets say i split out volume to another device, i could conceivably end up with 20-50 devices. Device management will then be a concern. Is floor/room really the only (or best) way to organize all of the amp-related devices? How many devices can HS3 handle on something like a hometroller S6 (celeron)? That also means there would be 20-50 events monitoring the devices. Seems messy. Thoughts?
        Now it has been a while since I tested this but this was a similar route (albeit it was for a Wifi RGB controller not an amplifier) I was going down with a set of devices and when I changed the value in the devices it run the script directly, when this script ran I then checked the value of the device and then set the outputs accordingly. In your situation a similar approach could eliminate the need for the events entirely because the moment the device changes value the script runs rather than going device>event>script. I can't honestly remember whether it worked or not and as I say there is most probably no noticeable difference in performance with your solution to this one and if you are happy with doing things (you might be able to quicken the process up with a copy device and copy event).

        The event scheduler is pretty quick and even though I am not someone who knows anything about the HomeTroller I think you will be good for a few hundred devices/events (although this does depend on a lot of factors) before you need to worry about things.

        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")
                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"
        
                    'Log("VSPair Clear: " & hs.DeviceVSP_ClearAll(dv.Ref(hs), True)) 'does not do anything
        
                    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 4
                            Dim Pair As VSPair
        
                            Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                            Pair.PairType = VSVGPairType.Range
                            Pair.RangeStart = 1
                            Pair.RangeEnd = 99
                            Pair.RangeStatusSuffix = " %"
                            Pair.Render = Enums.CAPIControlType.ValuesRangeSlider
                            pair.RangeStatusDecimals = 0
                            Pair.ControlUse = ePairControlUse._Dim 'HSTouch?
                            hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
        
                            Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                            Pair.PairType = VSVGPairType.SingleValue
                            Pair.Status = "Off"
                            Pair.Value = 0
                            Pair.Render = Enums.CAPIControlType.Button
                            Pair.ControlUse = ePairControlUse._Off '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 = ePairControlUse._On 'HSTouch?
        
                            hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
        
                            dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
        
                            hs.setdevicevaluebyref(dv.Ref(hs), 0, True)
        
                        Case 5
                            Dim Pair As VSPair
        
                            Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                            Pair.PairType = VSVGPairType.Range
                            Pair.RangeStart = 1
                            Pair.RangeEnd = 128
                            Pair.RangeStatusPrefix = "Value: "
                            Pair.Render = Enums.CAPIControlType.ValuesRangeSlider
                            pair.RangeStatusDecimals = 0
                            hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
        
                            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

        Comment

        Working...
        X