Originally posted by travis010
View Post
I accomplish the switch from Run/Hold to ESM by running an immediate script when my virtual device changes to Unoccupied status. The script is "&hs.ExecX10("H99", "Off")" where H99 is the device code for the thermostat. Use "On" if you want to switch it from ESM to Run/Hold.
To make it easy to switch from the Status Web Page, I added two buttons to switch the device. I manually executed the following script for each of my Thermostats to add the buttons:
PHP Code:
Extract of thermostats.vb --> see attachment
Public Sub ThermostatSetupDevice(ByVal Parms As Object)
'Private Sub ThermostatSetupDevice(ByVal Parms As Object)
' ============================================================================
'
' ThermostatSetupDevice
'
' Go through devices for specified Home Code and apply special attributes:
' - Device Buttons on Status Page
' - Device Values
'
' Parameter:
' Device: HS Device (e.g. s01)
' ============================================================================
Dim theDevice As String
Dim dv As Object
Dim dvRef As Integer
Dim ScriptCommand As String
theDevice = Parms.ToString
' Set Message Buttons
'
'- Special Chars:
' CHR(1) seperates each button
' CHR(2) seperates ref and name values
' CHR(4) in the button name creates a new line after that button
'
' Sample: hs.DeviceButtonAdd("z1", "speak_script.txt(""speak"",""hello"")", "Speak Now")
' Remove old values
hs.DeviceButtonRemove(theDevice, HS_DEV_STATUS_RUN_HOLD)
hs.DeviceButtonRemove(theDevice, HS_DEV_STATUS_AWAY)
' Add in New Values
ScriptCommand = "&hs.ExecX10(""" & theDevice & """,""On"")"
hs.DeviceButtonAdd(theDevice, ScriptCommand, HS_DEV_STATUS_RUN_HOLD & Chr(4))
ScriptCommand = "&hs.ExecX10(""" & theDevice & """,""Off"")"
hs.DeviceButtonAdd(theDevice, ScriptCommand, HS_DEV_STATUS_AWAY)
' Set Device Value to IOTYPE_CONTROL so default buttons don't show
dvRef = hs.GetDeviceRef(theDevice)
If dvRef > 0 Then
dv = hs.GetDeviceByRef(dvRef)
Else
'LogIt("Error - Could not find the reference for the device specified.")
Exit Sub
End If
dv.iotype = IOTYPE_CONTROL
End Sub
This approach is subpar because the device code is hard-coded in the script. You could also use BLStat.
Prior to 2.5.0.1 the thermostats appeared in the device drop down of On/Off commands so you didn't have to go through these gyrations. I'm hopeful a) the RUN/Hold <=> ESM operation will be a standard Thermostat function; or b) the Thermostats device will allow ON/OFF commands, or c) the Device Commands will show the thermostat devices so the On/Off can be done via a Device Command. [I'd really like to be able to have the Thermostat plugin be able to download the Schedule for centralized control with Distributed operation.]
Comment