Created
August 2, 2014 14:22
-
-
Save inabhi9/8e701a029f41e0ff6520 to your computer and use it in GitHub Desktop.
Control AC using Virtual Thermostat temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get Virtual Thermostat here: http://forum.micasaverde.com/index.php?topic=8363.0 | |
local lul_vdev_thermostat = 48 | |
local lul_dev_sensor = 43 | |
local lul_dev_ac = 37 | |
local DEFAULT_COOL_SP = 26 | |
-- Desired temperature mode in Virtual Thermostate | |
local modeStatus = luup.variable_get ("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "ModeStatus", lul_vdev_thermostat) | |
-- Desired temperature set in Virtual Thermostate | |
local coolSp = tonumber (luup.variable_get ("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", lul_vdev_thermostat), 10) or DEFAULT_COOL_SP | |
-- Current temperature from the sensor | |
local currentTemperature = tonumber (luup.variable_get ("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", lul_dev_sensor), 10) | |
-- Device Switch state | |
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lul_dev_ac) | |
luup.log("---------- AC switch using Virtual Thermostat -----------") | |
luup.log("Virtual Thermostate mode: " .. modeStatus) | |
luup.log("Virtual Cool point set: " .. coolSp) | |
luup.log("Current temperature: " .. currentTemperature) | |
-- Check of the Virtual Thermostate mode, it must be "CoolOn" | |
if (modeStatus ~= "CoolOn") then | |
luup.log("Thermostate mode is not in CoolOn mood. Returning...") | |
return False | |
end | |
-- Check for temperature | |
if (currentTemperature > coolSp) then | |
-- Temperature is higher than desired, so need to turn on the device | |
luup.log("Temperature is higher than cool set point. Turning on the device...") | |
-- Checking device switch state, if it's off | |
if (switchOnOff == "0") then | |
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, lul_dev_ac) | |
end | |
elseif (currentTemperature <= coolSp) then | |
-- Temperature is lower than the desired, so need to turn off the device | |
luup.log("Temperature is lower than cool set point. Turning off the device...") | |
-- Checking device switch state, if it's on | |
if (switchOnOff == "1") then | |
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, lul_dev_ac) | |
end | |
end | |
luup.log("-- EOF: AC using Virtual Thermostate -----------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment