Translations:Rule Examples/225/en

var hysteresis = 0.5; function Termostat(name, temp, setpoint, TS, TS_onoff) { defineRule(name, {

 whenChanged: temp, //when the sensor state changes
 then: function (newValue, devName, cellName) { // do the following
   if (dev[TS_onoff]) {
   if ( newValue < dev[setpoint] - hysteresis) { //if the sensor temperature is less than the setpoint - hysteresis
     dev[TS] = true;
   }
   if ( newValue > dev[setpoint] + hysteresis) { //if the sensor temperature is greater than the virtual setpoint + hysteresis
     dev[TS] = false;
   }
   }
   else dev[TS] = false;
 }

}); }