Version 4 (modified by solivas, 11 years ago) (diff)

Copied forum information over, and re-formatted for this wiki.

WDSC HVAC Control Plugin

(a.k.a If door is opened for 5 minutes...turn off air)

Code originally posted to: http://forum.micasaverde.com/index.php/topic,15982.msg121764.html#msg121764


Features

-Will turn HVAC system to Off, HeatOn, CoolOn, Energy Savings Mode, or do nothing when any of a defined set of sensors are tripped. Optionally will use my Twilio plugin to send an SMS message when a sensor is tripped, regardless of HVAC off control setting.

-Will restore HVAC system to Off, AutoChangeOver, HeatOn, CoolOn, Normal Mode (turn off Energy Saving Mode), or do nothing when sensors are no longer in a tripped state.

Here are the variables that the plugin will expose after it initializes:

Sensors = a list of Sensors that will be checked.

* Format: Needs to be entered in the format of [sensor id#]="name"
Example:

42=UPHall_W, 31=GRFrnt_D, 41=GRLanai_D, 38=UPLBckBR_W, 39=UPRBckBR_W, 36=MastBR_D, 32=LFrtBR_D, 34=LBkBR_D, 35=LwHall_D, 40=LwHall_W

Thermostats = a list of thermostats that will be controlled by this plugin.

* Format: Needs to be entered in the format of [thermostat id#]="name" Example:

4=GRThermostat, 20=LHThermostat

Refresh = number of seconds to wait between checking the sensors and controlling the thermostats. Default is set to 300 seconds (5 minutes). Min = 300, Max = 86400. Anything set/passed outside the min/max range will be ignored, and the default of 300 will be used. Setting this to 0 will disable the automatic polling.

OnMode = What mode should thermostats be restored to when sensors are closed (no longer tripped)

Valid modes are:
0 = Off
1 = AutoChangeOver
2 = HeatOn
3 = CoolOn
4 = Normal mode (turns off Energy Savings Mode) 99 = Do nothing (default)

OffMode = What mode should thermostats be set to when sensors are open (tripped)

Valid modes are: 0 = Off
1 = HeatOn
2 = CoolOn
3 = Energy Savings Mode
99 = Do nothing (default)

NotifyMode = Toggles use of Twilio Plugin to send SMS message

Valid modes are:

0 = Disabled
1 = Use Twilio Plugin to send SMS

TwilioNumber = Phone number to send SMS message to
TwilioMessage = Message for SMS
TwilioPluginID = Device ID of Twilio plugin

VerboseDebug - Turns on the logging of additional messages for troubleshooting

0 = Off (default)
1 = On

-- This will dump the contents of the String 2 Table routines as it converts the information in Sensors and Thermostats, useful for troubleshooting if you have entered something wrong in these variables.

All log messages start with "WDSC HVAC" for easy identification.

StartupCheck - Normally, the plugin will wait 300 seconds (5 minutes) when it starts before doing a check of the sensors. You can set this variable to run a check right after it has finished initializing.

0 = Off (default)
1 = On


Functions exposed:

ForcePoll = Allows for you to call the polling/checking option in your own scripts/scenes

RestartPolling = Allows you to change to interval for polling. Same rules apply as for setting Refresh variable. You can use this to start or stop polling in your own code/scenes.

Example:

luup.call_action("urn:wdsc-hvac-org:device:WDSC_HVAC1", "RestartPolling",{ delay= 0 }, 66)

This code would turn off polling for your WDSC device (assuming your plugin is device #66)


Warnings

]
-- ******************************************************
-- Window, Door, and Sensor HVAC Control (WDSC HVAC) plugin v1.0 (or WDSC for short)
-- Code originally by mcvflorin and posted to
-- http://forum.micasaverde.com/index.php/topic,4327.45.html
-- Packaged in plugin form by SOlivas, with modifications 
--
-- History:
-- 1.0 - Initial version released. 
--       mcvflorin's code with modifications to turn thermostats to specified modes (On or Off) during check if
--       door or window sensor is tripped.  Currently does not support internal motion sensors in this 
--       version.  May be added in a future release.
--
-- While I do not claim copyright for this plugin, I do feel that the following from the BSD license
-- is appropriate, since this is controlling your thermostat connected to your HVAC equipment and there 
-- is always possibility for things to not work in the way in which they were intended.
--
-- ** USE AT YOUR OWN RISK!!  IF YOUR HVAC EQUIPMENT MELTS DOWN, BREAKS, OR CATCHES FIRE OR EXPLODES
-- ** YOU HAVE BEEN WARNED!  
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
--WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
--ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
--TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
--HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
--POSSIBILITY OF SUCH DAMAGE.
--
-- Information:
--
-- ** Implements code from the following:
-- 
-- ** A modified version of the String 2 Lua code found at: 
-- **    http://www.gymbyl.com/programming/s2t.html
--
-- ******************************************************

Bug fixes:

  1. Made a fix to the string 2 table code and added in a verbose debug flag for troubleshooting.

  1. Fixed an error where device ID number was not being converted to a number, but passed as a string when using luup.call_action and luup.variable_get, causing them to fail.
  1. Fixed the format of what the strings in Sensors and Thermostats should be, before I just re-formatted what was in the old code without realizing the the routine I use to convert won't remove the square brackets around the numbers.
  1. There was a piece of code held over from my implementation in a scene, so that if the Thermostat was Off, it would never change to the state specified in OnMode. This has been fixed.
  1. Added in checks to see what the thermostat is already set at, and if it is the same setting as the target mode for OnMode or OffMode, it skips setting the thermostat again to the same mode. Shouldn't make a difference, but it is a precaution if your thermostat does something each time it changes into a certain mode.