Device Buttons

Adding buttons to a device causes the buttons to display on the device status page, and when a button is pressed, ButtonPress or ButtonPressEx is called in your plug-in.

 

To add buttons to devices call the HS interface function:

hs.DeviceButtonAdd(device as string, ref as string, name as string)

 

The parameters to this function are:

device = the device reference like "A1" or "[1" or whatever device code you assigned to devices that your plug-in created.

ref = the name of your plug-in. This is the same string that you return for the .name property. This is used by HomeSeer so it knows who owns the button.

name = the name string you want displayed on the button

Note that this information is saved in the "buttons" property of a device. It will then be saved to the HomeSeer configuration file. Therefore, you should only assign buttons when you first configure your device.

You can also assign buttons when you create devices. Simply add the buttons to the .buttons property of the device.

Note that the ref and name values are separated with a CHR(2) character and each button is separated with a CHR(1) character.

The following example adds 2 buttons to the device "[1":

dv.buttons = IFACE_NAME & Chr(2) & "Arm" & Chr(1) & IFACE_NAME & Chr(2) & "Disarm"

 

Note: When you assign your own buttons to a device, you may not want any of the standard buttons to appear. To avoid displaying the standard buttons, set the iotype property of the device to IOTYPE_CONTROL.
    e.g.: dv.iotype = IOTYPE_CONTROL
Note (last one, I promise): If you want a little more control over the format of the buttons when the device is displayed on the status screen, a CHR(4) in the button name will indicate to HomeSeer that you want a new line after that button.  Thus, putting a CHR(4) in every button name would result in a vertical stack of buttons rather than buttons that move when the browser window width is changed.

The hs.DeviceButtonAdd() function can also be used to execute a script function when a button is pressed. Set the "ref" parameter to a script file and function. To execute the function "speak" in the script "speak_script.txt" and assign this to the device "z1" and label the button "Speak Now" use:

 

hs.DeviceButtonAdd "z1","speak_script.txt(""speak"",""hello"")","Speak Now"

 

To remove a button from a device call:

 

hs.DeviceButtonRemove DEVICE,NAME

 

The button with the given housecode/unitcode and name label will be removed.