Announcement

Collapse
No announcement yet.

Understanding Virtual Devices

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

    Understanding Virtual Devices

    Hi all,

    So, I'm trying to understand virtual devices, but have been unable to find anything that really lays it out. Specifically (for example), I'm working on trying to use a virtual device to keep track of (and potentially change) the status of the resolution of an IP Camera.

    Separately, I'm working on getting a script working to query the cam and get it's status. Once obtained, I want to set the virtual device and use it to keep track of, display, and/or change the resolution.

    The camera may return one of 3 codes:
    2: really low res (not in use)
    8: low res
    32: hi res

    If I simply set the device value to 8 or 32, it displays in the virtual device status as 8 or 32.

    What I'd like to do is have the Status actually display as Lo-Res or Hi-Res, and have a pull-down on the right that lets me set the status.

    It *looks* like I should be able to use the "Edit Value-Status /Graphic Pairs" to make this happen, setting the value of 8 to Lo-Res and 32 to Hi-Res, and checking the Show Status Values checkbox. However, all that happens if I do this is the pull down on the right displays Lo and hi res, but the Status still only shows 8 or 32, and changing the drop down box doesn't change Status.

    Am I misunderstanding how the Value-Status pairs work? Further to that, is there any good documentation that talks about virtual devices? (Can you set up parent/child devices, etc, etc)

    Many thanks!

    Paul

    #2
    Value-Status pairs option is more to do with when you want to translate what HS may show into something more useful, as an example I have an X10 RF PIR configured in HomeSeer. When there is no motion HomeSeer reports its status/string of 'Off' and a value of '0'. When there is motion HomeSeer reports its status/string as 'On' and a value of '100'. To the casual observer this will mean very little, status pairs then allows you to specify alternate strings/images based on a different status, so I then have

    Value - Display Status - Graphics File
    0 No Motion /homeseer/nomotion.png
    100 Motion /homeseer/motion.png

    It allows you to translate what HomeSeer may show by default into something more user friendly - you can use it to do what you are after, but there is a slightly easier way. In the script test what the value is and then translate it into a friendlier name so;


    Select Case (VarDevice)
    Case 8
    hs.setdevicestring("Z17", "Low Resolution", True)
    hs.setdevicevalue("Z17", 0)
    Case 32
    hs.setdevicestring("Z17", "High Resoltion", True)
    hs.setdevicevalue("Z17", 1)
    End Select

    The drop down boxes are always interesting and it may be slightly easier to instead use some buttons using hs.devicebuttonadd, you could have two buttons to set the resolution, these are easier as when you set the buttons you can call directly into a script and change what you need to. IMHO and this may be an unpopular opinion I hold in that I think using drop down boxes are more for use with a plugin as you can call directly back into the plugin when you change the drop down. To notify a script that you have changed the drop down box would require you to create an event that triggered on the changing of this value, and then you would need to check the device and perform any neccessary action - it would not be instant.

    Hope i've explained that OK, if not tell me...

    Comment


      #3
      I think you've explained it quite well. From what you're describing it does sound like it might make more sense for me to use a couple of buttons rather than a pull-down, I'll explore that.

      From the Status display perspective, indeed while I can set the Status string from within my script (as we've been doing in the test code you provided me in my other thread), I was considering that there might be other situations (perhaps not for this specific circumstance, but for other options with the camera) where I might be better off setting the device status to just the numerical value that is returned, in which case using the Value - Display Status setting seems to make sense. When I set up the pair above, however, it doesn't seem to be working.

      ie. If I set the Status to 8 (by script or otherwise), and have a Value - Display pair that says when the Status is 8 to show "Hi Res", it did seem to me that "Hi Res" should be what displays in the Status line on the Status page, but it still shows "8".

      Just wondering if I might still be missing something.

      Many thanks!

      Comment


        #4
        You may not be setting the device value, what shows in the device is not usually the value it is the string. A quick run down, every device can hold any one or combination of the following;

        Value = 0,1,2,3 to whatever (either integer or long, can't remember probably 64000ish)
        Status = On/Off/Dim/Unknown
        String = "The temp is 24C" (with Html pictures/formatting)

        As a test if you create a virtual device on an unused code you should see a question mark and 'unknown' in the webpage. Execute this command &hs.setdevicevalue("X18", 15) you should find it still says 'unknown' but if you click on the device, then click additional information at the top you should find in the value row it shows 15. These values are what triggers the edit-status-value pairs function, the string you can set as hs.setdevicestring("X15", "Fifteen") now has the string of 'fifteen' but the value of 15 - they are both independent - I think this is what you are seeing, you will need to set the value using hs.setdevicevalue aswell as hs.setdevicestring in any scripts

        Status can only hold On/Off/Dim/Unknown and is more suitable for input/output stuff

        Comment


          #5
          Ahhh..... that makes much more sense now. I think that is exactly what I'm seeing. I will adjust accordingly.

          Many thanks!

          Paul

          Comment


            #6
            I ended up taking the Value/Status pair approach anyways, but ensuring I set the Value rather than the string from my script. Reason being that I had to add quite a bit of code to the script to deal with the different cases for each device to set the String from the script, but only a single line of code to simply set the value for the device, and then have the cases configured in the Value/Status pair.

            I do really appreciate your clarification on how it all works, it was a big help!

            Paul

            Comment

            Working...
            X