Announcement

Collapse
No announcement yet.

Immediate update of Status Field on button press

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

  • scott12v
    replied
    Originally posted by jono View Post
    Scott,
    Did you post your script for the Digital Loggers Web Power Switch?
    I'm interested in having Homeseer reboot my cable modem, router, LAN switches etc using the Web Power Switch based on certain conditions.

    I'm really looking for a script that would cycle power outlet 1, another script to cycle power outlet 2. Do you happen to have that handy?
    Thanks
    Jono
    Jono,

    Here is the script that I ended up writing...


    Code:
    CONST Outlet_Device_HC = "U"
    CONST Outlet_Device_DC_Start = "1"
    CONST Outlet_Device_Count = "8"
    
    CONST SurgeURL = "132.111.1.230:80"
    CONST Username = "xxxxx"
    CONST Password = "xxxxx"
    
    
    Sub Main(parm as object)
    
       dim dv
       dim i as integer
    
    '*****************Create HomeSeer Devices if they do Not Exist*************
       For i = Outlet_Device_DC_Start to Outlet_Device_Count
          If hs.deviceexists(Outlet_Device_HC & i) = -1 then
             hs.writelog("SurgeControl", "Creating HomeSeer Devices")
             dv = hs.NewDeviceEx("Surge Outlet " & i)
             dv.hc = Outlet_Device_HC
             dv.dc = i
             dv.location2 = "Surge Control"
             dv.dev_type_string = "Surge Control"
             dv.misc = &h10
          End if
    '*****************Add Buttons to HomeSeer Devices***************************
             hs.DeviceButtonRemove(Outlet_Device_HC & i, "On")
             hs.DeviceButtonRemove(Outlet_Device_HC & i, "Off")
             hs.DeviceButtonRemove(Outlet_Device_HC & i, "Cycle")
    
             dim command
             command = i & "On"
             hs.DeviceButtonAdd(Outlet_Device_HC & i,"SurgeControl.vb(""OutletControl"",""" & Command & """)","On")
             command = i & "Off"
             hs.DeviceButtonAdd(Outlet_Device_HC & i,"SurgeControl.vb(""OutletControl"",""" & Command & """)","Off")
             command = i & "Pulse"
             hs.DeviceButtonAdd(Outlet_Device_HC & i,"SurgeControl.vb(""OutletControl"",""" & Command & """)","Cycle")
       Next
    End Sub
    
    
    
    sub OutletControl(parms as object)
    
       Dim Outlet_DC                        'Device Code of the Outlet We are Controlling
       Dim Outlet_Command                   'Command that we are sending
       Dim Debug as String                  'Variable to Control Debug Setting ("On" / "Off")
    
       Outlet_DC = left(parms, 1)
       Outlet_Command = right(parms, len(parms)-1)
       Debug = "On"
    
       If Debug = "On" Then
          hs.writelog("SurgeControl", Outlet_DC)
          hs.writelog("SurgeControl", Outlet_Command)
          hs.writelog("SurgeControl", parms)
       End If
    
       Dim strAppPath
       Dim strEXEPath
    
    '*****************Get the Path to the UU.W32.exe Executable that controls the switch*************
       strAppPath = hs.GetAppPath
       If (Right(strAppPath, 1) <> "\") Then strAppPath = strAppPath & "\"
       strEXEPath = strAppPath & "UU.W32.exe"
       If Debug = "On" Then
          hs.writelog("SurgeControl", strEXEPath)
       End If
    
    '*****************Launch the UU.W32.exe Executable that controls the switch***********************
       hs.Launch(strEXEPath, SurgeURL & " " & UserName & ":" & Password & " " & parms)
       hs.writelog("SurgeControl", "Outlet " & Outlet_DC & " " & Outlet_Command)
       If Debug = "On" Then
          hs.writelog("SurgeControl",SurgeURL & " " & UserName & ":" & Password & " " & parms)
       End If
    
    '*****************Update Device Status************************************************************ 
       hs.writelog("SurgeControl", Outlet_Command)
       If Outlet_Command = "On" Then
         hs.writelog("SurgeControl", Outlet_Command & " - Got Here On")
         hs.setDeviceString(Outlet_Device_HC & Outlet_DC, "On")
       Else If Outlet_Command = "Off" Then
         hs.writelog("SurgeControl", Outlet_Command & " - Got Here Off")
         hs.setDeviceString(Outlet_Device_HC & Outlet_DC, "Off")
       End If
       hs.SetDeviceLastChange(Outlet_Device_HC & Outlet_DC, now())
    
    End Sub
    You do need the executable UU.W32.exe to run the script...unfortunately, I don't recall where I got this from. I assume from the vendors website?

    Also, I can't remember if I ever got the "Cycle" option to work...I don't think I did, but I also don't think it would be a huge deal to make it work.

    I am not a developer, so this code is probably not the best .

    Good Luck!

    If you can't find the executable, let me know.

    Leave a comment:


  • jono
    replied
    Scott,
    Did you post your script for the Digital Loggers Web Power Switch?
    I'm interested in having Homeseer reboot my cable modem, router, LAN switches etc using the Web Power Switch based on certain conditions.

    I'm really looking for a script that would cycle power outlet 1, another script to cycle power outlet 2. Do you happen to have that handy?
    Thanks
    Jono

    Leave a comment:


  • YoYo
    replied
    The fact that the correct device status does not update in the same fashion as the built-in buttons, is a serious bug in my opinion.

    Really screws with the WAF and makes them almost useless if you ask me...

    I would lobby HS to get this fixed soon.

    Leave a comment:


  • bdraper
    replied
    After reviewing all the text, pressing the refresh button looks kinda easy...

    Leave a comment:


  • jon00
    replied
    In the end it was too much effort - so no!

    Leave a comment:


  • bdraper
    replied
    Thanks Jon, I'll give it a look. Were you ever successful at getting something to work?

    Leave a comment:


  • jon00
    replied
    This thread may assist you.

    Leave a comment:


  • scott12v
    replied
    Originally posted by bdraper View Post
    I believe the difference is a standard button that is automatically created by HomeSeer vs. a button that you have created using the API... I have never been able to get the status to reflect the correct status after pressing a button created with the API unless I do a screen refresh.

    If it is possible, I'm missing the same thing you are...
    Thanks...at least I know I'm not completely crazy. Do you know if you can assign scripts to Homeseer's ON/OFF buttons? I didn't see a way to do that either...

    Leave a comment:


  • bdraper
    replied
    I believe the difference is a standard button that is automatically created by HomeSeer vs. a button that you have created using the API... I have never been able to get the status to reflect the correct status after pressing a button created with the API unless I do a screen refresh.

    If it is possible, I'm missing the same thing you are...

    Leave a comment:


  • scott12v
    started a topic Immediate update of Status Field on button press

    Immediate update of Status Field on button press

    I am writing a script to control the Web Power Switch II from Digital Loggers. I have things pretty much the way I want them, but can't figure out one item. I use hs.DeviceButtonAdd to add three new buttons - On, Off, and Cycle.

    When you press On, the outlet turns On. When you press Off, the Outlet turns Off. Cycle is supposed ot turn it Off and then On.

    The buttons work fine and trigger my script as appropriate. As part of the script, I update the Homeseer Device Status to On or Off based on the button I pressed (I hope to eventually read the status from the device, but for now, it is just based on the button press).

    This works, BUT when I press ON to turn the Device ON, the Status field does not update until I refresh the screen. I guess this wouldn't be so terrible, but if I press On and then Off, the status actually shows On since pressing the Off button refreshed the screen. If I manually refresh, then it is correct.

    If I look at any of my lighting controls, as soon as I press the On button to turn on a light, the status turns to On as expected without any screen refresh.

    So how do I make my custom buttons behave like the built-in On/Off buttons???


    Thanks,
    Scott
Working...
X