Options
All
  • Public
  • Public/Protected
  • All
Menu

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 actuator GPIO (which in turn should control the heating, e.g. by using a relay) by comparing the current temperature with the given setpoint:

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.

Hierarchy

  • Thermostat

Index

Constructors

Properties

name: string

A string to uniquely identify a thermostat.

sensorType: SensorType

The sensor's type. Must be either 11 (DHT11) or 22 (DHT22/AM2302).

temperatureSummand: number

A simple correction of the measured temperature by a fixed summand.

defaultSensorType: SensorType = 22

The default sensor type for a new thermostat.

defaultSetpoint: number = 18

The default temperature (in °C) to be maintained by a newly created thermostat, if no such value is configured on creation.

samplingInterval: number = 120

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.
sensorWarmUpTime: number = 4

Delay (in seconds) between sensor power on and start of measurements.

timeout: number = 5

Timeout after which all measurements will be stopped.

Accessors

  • get heatingIsOn(): boolean
  • Determines whether the heating is currently on.

    Returns boolean

  • get humidity(): number
  • Relative humidity (in %) measured in the latest measurement.

    Returns number

  • get isActive(): boolean
  • Determines whether the thermostat is active.

    Returns boolean

  • get rawTemperature(): number
  • Raw temperature (in °C) measured in the latest measurement.

    Returns number

  • get setpoint(): number
  • set setpoint(temperature: number): void
  • The desired temperature (in °C) to be maintained by the thermostat.

    Returns number

  • The desired temperature (in °C) to be maintained by the thermostat.

    Parameters

    • temperature: number

    Returns void

  • get temperature(): number
  • Temperature (in °C) measured in the latest measurement; possibly with correction summand applied.

    Returns number

  • get timestamp(): number
  • UNIX timestamp (in milliseconds) of the latest measurement.

    Returns number

  • get sensorPowerPin(): number
  • set sensorPowerPin(pin: number): void
  • GPIO pin controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on.

    Returns number

  • GPIO pin controlling the power supply for all connected DHT sensors. If undefined, power is assumed to be always on.

    Parameters

    • pin: number

    Returns void

Methods

  • activate(): void
  • Activates the thermostat.

    Returns void

  • deactivate(heatingOn?: boolean): void
  • Deactivates the thermostat.

    Parameters

    • heatingOn: boolean = false

      Determines whether after deactivation of the thermostat the heating is off (default) or on (if set to true).

    Returns void

  • toString(): string
  • Returns string

  • deactivateAll(): void
  • Returns void

Generated using TypeDoc