Announcement

Collapse
No announcement yet.

DeviceScriptButton_Add Sample Script

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

    DeviceScriptButton_Add Sample Script

    For those of you wanting to try the new hs.DeviceScriptButton_Add feature, I made this quick script to create a test device with 3 buttons. Main() creates the device and then the buttons are pressed, the ButtonPress Sub is called with a Parm. Hope it helps someone.


    Code:
    Public Const ScriptName = "Add Button Test"
    
    
    Sub Main(parm as object)
    	Dim TestDeviceCodeName = "TestDevice001"
    	Dim a As Boolean
    	Dim ButtonInfo() As String
    	Dim DV As Object
    	Dim DT As New DeviceTypeInfo
    	Try
    		DV = hs.NewDeviceEx(TestDeviceCodeName)
    		DV.Location(hs) = "Test"
    		DV.Location2(hs) = "Test"
    		DV.Code(hs) = TestDeviceCodeName
    		dv.DeviceType_Set(hs) = DT
    		hs.SaveEventsDevices
    		DT = Nothing
    		DV.Status_Support(hs) = True
    		DV.Can_Dim(hs) = False
    		DV.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100
    		DV.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10
    		DV = Nothing
    
    		hs.WriteLog(ScriptName, "Test Device " & TestDeviceCodeName & " created") 			
    	Catch ex As Exception
    		hs.WriteLog(ScriptName, "Error C: " & ex.Message)
    	End Try
    
    	Dim DevExists As Integer
    	DevExists = hs.DeviceExistsCode(TestDeviceCodeName)
    	
    	
    	a = hs.DeviceScriptButton_Add(DevExists, "Button 1", "test_device_creation.vb", "ButtonPress", "Button1", 1, 1, 1)
    	If a  Then 
    		hs.writelog(ScriptName,"Device Script for Button 1 Successfully Added")
    	Else
    		hs.writelog(ScriptName,"Error: Device Script for Button 1 NOT Added")
    	End If
    	a = hs.DeviceScriptButton_Add(DevExists, "Button 2", "test_device_creation.vb", "ButtonPress", "Button2", 1, 1, 1)
    	If a  Then 
    		hs.writelog(ScriptName,"Device Script for Button 2 Successfully Added")
    	Else
    		hs.writelog(ScriptName,"Error: Device Script for Button 2 NOT Added")
    	End If
    	a = hs.DeviceScriptButton_Add(DevExists, "Button 3", "test_device_creation.vb", "ButtonPress", "Button3", 1, 1, 1)
    	If a  Then 
    		hs.writelog(ScriptName,"Device Script for Button 3 Successfully Added")
    	Else
    		hs.writelog(ScriptName,"Error: Device Script for Button 3 NOT Added")
    	End If
    	
    
    	ButtonInfo = hs.DeviceScriptButton_List(DevExists)
    	hs.Writelog(ScriptName,"Button 1 created with following info " & ButtonInfo(0))
    	hs.Writelog(ScriptName,"Button 2 created with following info " & ButtonInfo(1))
    	hs.Writelog(ScriptName,"Button 3 created with following info " & ButtonInfo(2))
    
    	
    	
    End Sub
    
    
    Sub ButtonPress(Input As Object)
    	Dim DevID As Integer = Input(0) 						'Integer - The device reference ID.
    	Dim ScriptCallParm As String = Input(1)					'String - Script Parm Passed from Button
    
    	If ScriptCallParm = "Button1" Then
    		hs.Writelog(ScriptName,"Button 1 has been pressed!")
    	End If
    
    	If ScriptCallParm = "Button2" Then
    		hs.Writelog(ScriptName,"Button 2 has been pressed!")
    	End If
    
    	If ScriptCallParm = "Button3" Then
    		hs.Writelog(ScriptName,"Button 3 has been pressed!")
    	End If
    End Sub

    #2
    Madmax,

    Thanks, this helped me getting it work in my scripts.

    However i think we have a bug in hstouch. When we select one of the buttons in hstouch with the device browser, its always triggers the same parameter, in your case button 3 pressed. Do you also have this issue?

    Tonight im trying to create also identical valuepairs, maybe this solves this issue.

    regards

    bart
    Regards Bart
    ------------------------------------------
    Win7 64Bit on Intel NUCI7 with SSD
    HSPRO 3.
    Devices; 1370 Events; 691

    Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

    Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

    Comment


      #3
      Hi, I haven't tried this with HSTouch yet.

      Comment


        #4
        Guys,

        Rick has corrected the issue with DeviceScriptButton_Add not working in HSTouch which will be available in the next version of HS3.

        The bad news is that there will be a new parameter added to the command so you need to update your code. This new parameter is a unique value which is not used in another button or value/status pair for that device.
        Jon

        Comment


          #5
          Hi jon00

          Great news. So I can update my scripts. I guess thedevices need to be removed and recreated by the script? In addition the documentation will be updated as well?

          So jon u need also to update the hue plugin i guess? Thnx again for the great support

          Regards

          Bart
          Regards Bart
          ------------------------------------------
          Win7 64Bit on Intel NUCI7 with SSD
          HSPRO 3.
          Devices; 1370 Events; 691

          Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

          Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

          Comment


            #6
            Can anyone get the DeviceScriptButton_Add function to work with the new value parm? I'm having trouble

            This doesn't work:
            a = hs.DeviceScriptButton_Add(DevExists,"Button 1",204000,"test_device_creation.vb","ButtonPress","Button1", 1,1,1)

            I just added a random 204000 value for the sample button


            http://homeseer.com/support/homeseer...button_add.htm

            Comment


              #7
              You need to use hs.DeviceScriptButton_AddButton NOT hs.DeviceScriptButton_Add
              Jon

              Comment


                #8
                Thanks jon00

                This now works with newer versions of HS:

                Code:
                Public Const ScriptName = "Add Button Test"
                
                
                Sub Main(parm as object)
                	Dim TestDeviceCodeName = "TestDevice001"
                	Dim a As Boolean
                	Dim ButtonInfo() As String
                	Dim DV As Object
                	Dim DT As New DeviceTypeInfo
                	Try
                		DV = hs.NewDeviceEx(TestDeviceCodeName)
                		DV.Location(hs) = "Test"
                		DV.Location2(hs) = "Test"
                		DV.Code(hs) = TestDeviceCodeName
                		dv.DeviceType_Set(hs) = DT
                		hs.SaveEventsDevices
                		DT = Nothing
                		DV.Status_Support(hs) = True
                		DV.Can_Dim(hs) = False
                		DV.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100
                		DV.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10
                		DV = Nothing
                
                		hs.WriteLog(ScriptName, "Test Device " & TestDeviceCodeName & " created") 			
                	Catch ex As Exception
                		hs.WriteLog(ScriptName, "Error C: " & ex.Message)
                	End Try
                
                	Dim DevExists As Integer
                	DevExists = hs.DeviceExistsCode(TestDeviceCodeName)
                	
                
                	
                	
                	a = hs.DeviceScriptButton_AddButton(DevExists, "Button 1", 204000, "test_device_creation.vb", "ButtonPress", "Button1", 1, 1, 1)
                	If a  Then 
                		hs.writelog(ScriptName,"Device Script for Button 1 Successfully Added")
                	Else
                		hs.writelog(ScriptName,"Error: Device Script for Button 1 NOT Added")
                	End If
                	a = hs.DeviceScriptButton_AddButton(DevExists, "Button 2",204001, "test_device_creation.vb", "ButtonPress", "Button2", 1, 1, 1)
                	If a  Then 
                		hs.writelog(ScriptName,"Device Script for Button 2 Successfully Added")
                	Else
                		hs.writelog(ScriptName,"Error: Device Script for Button 2 NOT Added")
                	End If
                	a = hs.DeviceScriptButton_AddButton(DevExists, "Button 3",204002, "test_device_creation.vb", "ButtonPress", "Button3", 1, 1, 1)
                	If a  Then 
                		hs.writelog(ScriptName,"Device Script for Button 3 Successfully Added")
                	Else
                		hs.writelog(ScriptName,"Error: Device Script for Button 3 NOT Added")
                	End If
                	
                
                	ButtonInfo = hs.DeviceScriptButton_List(DevExists)
                	hs.Writelog(ScriptName,"Button 1 created with following info " & ButtonInfo(0))
                	hs.Writelog(ScriptName,"Button 2 created with following info " & ButtonInfo(1))
                	hs.Writelog(ScriptName,"Button 3 created with following info " & ButtonInfo(2))
                
                	
                	
                End Sub
                
                
                Sub ButtonPress(Input As Object)
                	Dim DevID As Integer = Input(0) 						'Integer - The device reference ID.
                	Dim ScriptCallParm As String = Input(1)					'String - Script Parm Passed from Button
                
                	If ScriptCallParm = "Button1" Then
                		hs.Writelog(ScriptName,"Button 1 has been pressed!")
                	End If
                
                	If ScriptCallParm = "Button2" Then
                		hs.Writelog(ScriptName,"Button 2 has been pressed!")
                	End If
                
                	If ScriptCallParm = "Button3" Then
                		hs.Writelog(ScriptName,"Button 3 has been pressed!")
                	End If
                End Sub

                Comment


                  #9
                  I tried this unchanged and got the below logs. My goal is to create a virtual device with a drop list to select from 1-10, and "+1" and "-1" buttons to increment or decrement the current value. I did already create the virtual device with drop list manually, but need the script buttons to increment & decrement the value.

                  I need to be able to use the AddDeviceActionToEvent function from another script to add an action to an event to increment the value of this virtual device. I originally had a regular counter device holding this value, but found there apparently is no CAPIControl to increment the counter. It looks like this DeviceScriptButton_AddButton function does add CAPIControls which I could then reference in the AddDeviceActionToEvent function. Any help is greatly appreciated.

                  Jul-03 7:27:30 PM Error 1 Running script /usr/local/HomeSeer/scripts/AddButtonTest.vb :Exception has been thrown by the target of an invocation.Object reference not set to an instance of an object
                  Jul-03 7:27:30 PM Add Button Test Error: Device Script for Button 3 NOT Added
                  Jul-03 7:27:30 PM Add Button Test Error: Device Script for Button 2 NOT Added
                  Jul-03 7:27:30 PM Add Button Test Error: Device Script for Button 1 NOT Added
                  Jul-03 7:27:30 PM Add Button Test Error C: Cannot find the requested class member.
                  Jul-03 7:27:23 PM Event Running script in background: /usr/local/HomeSeer/scripts/AddButtonTest.vb
                  Jul-03 7:27:23 PM Event Event Trigger "Tests VirtualDev with scriptButtons"
                  Jul-03 7:27:23 PM Event Event Tests VirtualDev with scriptButtons triggered by the event page 'Run' button.

                  John

                  Current Date/Time: 7/3/2016 7:45:31 PM
                  HomeSeer Version: HS3 ZEE S2 Edition 3.0.0.291
                  Linux version: Linux HomeTrollerZeeS2 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux System Uptime: 9 Days 2 Hours 58 Minutes 43 Seconds
                  IP Address: 192.168.0.32
                  Number of Devices: 221
                  Number of Events: 195
                  Available Threads: 399

                  Enabled Plug-Ins
                  3.0.0.27: EasyTrigger
                  3.0.0.68: HSTouch Server
                  3.0.5959.34353: UltraM1G3
                  3.0.0.50: weatherXML
                  3.0.1.83: Z-Wave

                  Comment


                    #10
                    I just tried the script here and works fine on a Windows version of Homeseer. Sorry but I cannot test on Linux.

                    Remove or remark the following lines and see if the error persists:

                    Dim DT As New DeviceTypeInfo
                    dv.DeviceType_Set(hs) = DT
                    hs.SaveEventsDevices
                    DT = Nothing
                    DV.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10

                    Also change this:

                    DV.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100

                    To

                    DV.MISC_Set(hs, &H100) 'This is &H100
                    Jon

                    Comment


                      #11
                      Same log errors after those changes. I just loaded VS Express, so I'll start playing with (no experience with it yet) that to try to understand better where the problems might be. Thanks.

                      John

                      Comment

                      Working...
                      X