thermostat-pi-dht
Version:
A Node.js framework (standalone app + lib) to control a heating system with a Raspberry Pi using DHT11 or DHT22/AM2302 sensors and GPIO actuators.
111 lines (110 loc) • 6.13 kB
TypeScript
import { SensorType } from './SensorType';
import { ThermostatConfiguration } from './ThermostatConfiguration';
import { ThermostatData } from './ThermostatData';
/** An implementation of a thermostat on a Raspberry Pi using
* - a DHT11 or DHT22/AM2302 sensor and
* - a GPIO as actuator.
*
* Once activated, a thermostat regularly measures the current [[temperature]] (and relative [[humidity]]). It then activates or deactivates the [[actuatorPin | actuator GPIO]] (which in turn should control the heating, e.g. by using a relay) by comparing the current [[temperature]] with the given [[setpoint]]:
* - if the [[temperature]] is below the [[setpoint]], it activates the actuator and
* - if the [[temperature]] is equal to or above the [[setpoint]], it deactivates the actuator.
*
* ## Common measuring loop
* Note that this implementation uses a *common measuring loop* for all configured thermostats, hence the [[samplingInterval]] as well as the measurement [[timeout]] is configured globally (i.e. as static variables).
*
* ## Power rail activation/deactivation
* The implementation optionally supports a (common) *power rail activation/deactivation*: If a [[sensorPowerPin]] is specified, power to the DHT sensors will be switched on prior to a measurement and switched off after measurements finished (or timed out). The [[sensorWarmUpTime]] determines, how long (in seconds) the software will wait until starting a measurement after power has been activated.
*/
export declare class Thermostat {
/** Sampling interval (in seconds) for all thermostats.
*
* This is the interval ranging from
* - the finalization (or timeout) of a measurement run to
* - the next start of the measurement run. */
static samplingInterval: number;
/** Delay (in seconds) between sensor power on and start of measurements. */
static sensorWarmUpTime: number;
/** Timeout after which all measurements will be stopped. */
static timeout: number;
/** GPIO pin controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on. */
static get sensorPowerPin(): number;
/** GPIO pin controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on. */
static set sensorPowerPin(pin: number);
/** The default temperature (in °C) to be maintained by a newly created thermostat, if no such value is configured on creation. */
static defaultSetpoint: number;
/** The default sensor type for a new thermostat. */
static defaultSensorType: SensorType;
private static remainingMeasurements;
private static activeInstances;
private static nextInternalId;
/** Constructs a new thermostat based on the supplied configuration. */
constructor(config: ThermostatConfiguration);
/** A string to uniquely identify a thermostat. */
readonly name: string;
/** The desired temperature (in °C) to be maintained by the thermostat. */
get setpoint(): number;
/** The desired temperature (in °C) to be maintained by the thermostat. */
set setpoint(temperature: number);
/** The sensor's type. Must be either 11 (DHT11) or 22 (DHT22/AM2302). */
readonly sensorType: SensorType;
/** A simple correction of the measured temperature by a fixed summand. */
readonly temperatureSummand: number;
/** UNIX timestamp (in milliseconds) of the latest measurement. */
get timestamp(): number;
/** Raw temperature (in °C) measured in the latest measurement. */
get rawTemperature(): number;
/** Temperature (in °C) measured in the latest measurement; possibly with correction summand applied. */
get temperature(): number;
/** Relative humidity (in %) measured in the latest measurement. */
get humidity(): number;
/** Determines whether the heating is currently on. */
get heatingIsOn(): boolean;
/** Determines whether the thermostat is active. */
get isActive(): boolean;
/** GPIO pin controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on. */
private static _sensorPowerPin;
/** GPIO controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on. */
private static _sensorPowerGpio;
/** The main measurement loop.*/
private static main;
/** Activates the main measurement loop for all active thermostats. */
private static activate;
static deactivateAll(): void;
/** Used to uniquely track instances internally. */
private internalId;
/** The desired temperature (in °C) to be maintained by the thermostat. */
private _setpoint;
/** A sensor to measure the temperature (and humidity). */
private sensor;
/** GPIO pin to which the sensor is connected. */
private sensorPin;
/** A GPIO controlling the heating device. */
private actuator;
/** GPIO pin to which the actuator is connected. */
private actuatorPin;
/** UNIX timestamp (in milliseconds) of the latest measurement. */
private _timestamp;
/** Raw temperature (in °C) of the latest measurement. */
private _rawTemperature;
/** Temperature (in °C) of the latest measurement; possibly with correction summand applied. */
private _temperature;
/** Relative humidity (in %) of the latest measurement. */
private _humidity;
/** Determines whether the thermostat is active. */
private static _isActive;
/** Determines whether the heating is currently on. */
private _heatingIsOn;
/** Handles new temperature/humidity data. */
private onData;
/** Checks if heating needs to be switched on/off */
private check;
/** Activates the thermostat. */
activate(): void;
/** Deactivates the thermostat.
* @param heatingOn Determines whether after deactivation of the thermostat the heating is off (default) or on (if set to true).
*/
deactivate(heatingOn?: boolean): void;
configurationToJSON(): ThermostatConfiguration;
toJSON(): ThermostatData;
toString(): string;
}