OnTrue
// Put your trigger code logic here.
// To execute the Code To Run,
// use a 'return true' or 'return false' otherwise.
Program.Setup(()=>{
Program.AddControlWidget("homegenie/generic/thermostat");
Program.AddInputField("TemperatureModule", "", "Module to read temperature from");
Program.AddInputField("SwitchModule", "", "Module to switch on/off on set point");
//Program.AddInputField("ScheduleCheck", "", "Scheduler expression constraint");
});
return true;
// CSharp Automation Program Plugin
// Example for using Helper Classes:
// Modules.WithName("Light 1").On();
const int HOLDING_MODE_DIFF = 1;
var temperature = Program.Parameter("Sensor.Temperature");
var operatingState = Program.Parameter("Thermostat.OperatingState");
var thermostatMode = Program.Parameter("Thermostat.Mode");
var heatSetPoint = Program.Parameter("Thermostat.SetPoint.Heating");
var holdingMode = false;
var ThermostatLogicRun = new Func<bool>(()=>{
string domainAddress = "";
string domain = "";
string address = "";
// Get a reference to the temperature module
domainAddress = Program.InputField("TemperatureModule").Value;
if (domainAddress != "" && domainAddress.IndexOf(":") > 0)
{
domain = domainAddress.Split(':')[0];
address = domainAddress.Split(':')[1];
}
var temperatureModule = Modules.InDomain(domain).WithAddress(address).Get();
if (temperatureModule == null)
{
Program.Notify("Generic Thermostat", "Please specify a valid temperature module.");
return false;
}
// Update Thermostat module Temperature field
temperature.Value = temperatureModule.Parameter("Sensor.Temperature").Value;
// get a reference to the switch/relay module
domainAddress = Program.InputField("SwitchModule").Value;
if (domainAddress != "" && domainAddress.IndexOf(":") > 0)
{
domain = domainAddress.Split(':')[0];
address = domainAddress.Split(':')[1];
}
var switchModule = Modules.InDomain(domain).WithAddress(address).Get();
if (switchModule == null)
{
Program.Notify("Generic Thermostat", "Please specify a valid switch module.");
return false;
}
// Heat Mode logic
if (thermostatMode.Value == "Heat")
{
if (temperature.DecimalValue < heatSetPoint.DecimalValue - (holdingMode ? HOLDING_MODE_DIFF : 0))
{
if (switchModule.IsOff)
{
holdingMode = false;
Program.RaiseEvent("Thermostat.OperatingState", "Heating", "Eden Thermostat");
}
// Heating
switchModule.On();
}
else
{
// Store last time the switch was set to On
if (switchModule.IsOn)
{
holdingMode = true;
Program.RaiseEvent("Thermostat.OperatingState", "PendingHeat", "Eden Thermostat");
}
// Waiting
switchModule.Off();
}
}
else
{
if (operatingState.Value != "Off" && operatingState.Value != "Idle")
{
Program.RaiseEvent("Thermostat.OperatingState", "Idle", "Eden Thermostat");
holdingMode = false;
}
// Off
switchModule.Off();
}
return true;
});
// implement Web API calls as defined in the Thermostat widget
When.WebServiceCallReceived(Program.Module.Domain + "/" + Program.Module.Address + "/Thermostat.SetPointSet", (args)=>{
if (args.ToString().Split('/')[0] == "Heating")
{
Program.RaiseEvent("Thermostat.SetPoint.Heating", args.ToString().Split('/')[1], "Eden Thermostat");
holdingMode = false;
ThermostatLogicRun();
}
return true;
});
When.WebServiceCallReceived(Program.Module.Domain + "/" + Program.Module.Address + "/Thermostat.ModeSet", (args)=>{
Program.RaiseEvent("Thermostat.Mode", args.ToString().Split('/')[0], "Eden Thermostat");
holdingMode = false;
ThermostatLogicRun();
return true;
});
while (Program.IsEnabled)
{
Pause(30);
ThermostatLogicRun();
}
[]
true
true
HomeAutomation.HomeGenie.Automation
78
Generic Thermostat
Use any temperature sensor and relay switch module to implement Thermostat device logic.
Module must be specified in the form <i><domain>:<address></i>, eg: HomeAutomation.ZWave:5
Weather and Enviroment
2014-11-28T21:47:11.387839Z
2014-11-28T21:47:11.728661Z
CSharp
true