Announcement

Collapse
No announcement yet.

How to Change Status/Value/Graphics Pairs of Plug-In Devices?

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

    How to Change Status/Value/Graphics Pairs of Plug-In Devices?

    I have several devices which I would like to use alternate status strings than those provided by the PI author.


    An example is in UltraM1G I have sensors on my garage doors which are used for autmoation only, ot for alarm purposes. The status for thise devices are:
    • Normal
    • Violated
    • Trouble
    • Unknown
    I would like to be able to substitute "Closed" for "Normal" and ""Open" for "Violated".


    Since I did not create the device I cannot manually edit the status/value/graphics pairs. I looked at the documentation for UltraStatus but that appears to be able to substitute only for On and Off.

    Am I missing something?

    The only clumsy way I could figure out is to create my own virtual tracking device and events that change its status based on the undlerlying device.

    Any advice would be appreciated.

    Regards,
    Vector

    #2
    If you are up to a little scripting, here is code from one of my plugins that set up the value/string pairs for a device. It also stores a note into the device note fied.

    Code:
     '' Create Device:  Battery Flag
            dv = CreateADevice("Battery Flag")
            dv.hc = gBaseCode
            dv.dc = dev_code.ToString
            'dv.misc = dv.misc & &H100           ' allow DeviceValuesAdd
            hs.DeviceValuesAdd(dv.hc & dv.dc, _
                               "High" & Chr(2) & "1" _
                               & Chr(1) _
                               & "Low" & Chr(2) & "2" _
                               & Chr(1) _
                               & "Critical" & Chr(2) & "4" _
                                & Chr(1) _
                               & "Charging" & Chr(2) & "8" _
                               & Chr(1) _
                               & "Charging,High" & Chr(2) & "9" _
                               & Chr(1) _
                               & "Charging,Low" & Chr(2) & "10" _
                               & Chr(1) _
                               & "Charging,Critical" & Chr(2) & "12" _
                                & Chr(1) _
                               & "No Battery" & Chr(2) & "128" _
                               & Chr(1) _
                               & "Unknown" & Chr(2) & "255", _
                               True)
            hs.SetDeviceStatusByName(IFACE_NAME & " Battery Flag", 17)
            hs.SetDeviceString(dv.hc & dv.dc, "Unknown")
            hs.SetDeviceValueByName(IFACE_NAME & " Battery Flag", 255)
            dv.UserNote = "Valid Device Values are:" & vbCrLf & vbCrLf & _
                                "1   High: > 66%" & vbCrLf & _
                                "2   Low: < 33%" & vbCrLf & _
                                "4   Critical: < 5%" & vbCrLf & _
                                "8   Charging" & vbCrLf & _
                                "9   Charging,High" & vbCrLf & _
                                "10  Charging,Low" & vbCrLf & _
                                "12  Charging,Critical" & vbCrLf & _
                                "128 No Battery" & vbCrLf & _
                                "255 Unknown"
            hs.WriteLog(IFACE_NAME, "Device Created: " & dv.hc & dv.dc & " (" & IFACE_NAME & " " & dv.Name & ")")
            dev_code += 1
    tenholde
    tenholde

    Comment


      #3
      Thanks Tenholde,

      My scripting skills are VERY limited, but I will try to muddle through. Would you mind explaining what each section is doing?

      Regards,
      Vector

      Comment


        #4
        Code:
                        hs.DeviceValuesAdd("A1", _
                                   "High" & Chr(2) & "1" _
                                   & Chr(1) _
                                   & "Low" & Chr(2) & "2" _
                                   & Chr(1) _
                                   & "Critical" & Chr(2) & "4" _
                                   & Chr(1) _
                                   & "Unknown" & Chr(2) & "255", _
                                   True)
        The DeviceValuesAdd call adds a list of String:Value pairs to device "A1".

        The status screen will now display the related string when the device has one of the values:

        1 "High"
        2 "Low"
        4 "Critical"
        255 "Unknown"

        Hope that helps,

        tenholde
        tenholde

        Comment


          #5
          Thanks Tenholde,

          With your explanation and reading the Help text for DeviceValueAdd, I am starting to get it!

          Regards,
          Vector

          Comment

          Working...
          X