# WiFiThermostat

ESP8266 based, WiFi connected set-point thermostat designed as replacement for electric room thermostats used for most domestic heating systems. 

## Features
* current temperature/humidity measurement using DHT22 sensor with value smoothing
* thermostat with configurable hysteresis and 2 modes with different set-point temperatures (normal and reduction)
* control unit with LCD and 3 pushbuttons
* power unit with power supply and relais for heating control
* telemetry via WiFi/MQTT (set temp, heating mode, heating on/off, PIR-sensor)
* web interface for configuration and control
* configuration and value changes also via MQTT and UART commands
* PIR movement sensor for room surveillance can be attached, status is pushed via MQTT
* initial configuration via WiFi AP mode with captive portal
* non blocking WiFi and MQTT connection
* built-in 2-way support for [Domoticz](https://domoticz.com/) Home Automation controller over MQTT
	* set point and mode can be controlled from Domoticz
	* local changes sending updates to Domoticz
	* current temperature/humidity is reported to Domoticz
	* PIR sensor state changes (if connected) are pushed to Domoticz
	* designed to use Domoticz as the "intelligent" controller for schedules etc.
* value changes (set point and mode, both from local and remote) can be automatically saved to flash

## Hardware

### Control Unit
To be installed instead of normal room thermostat. Uses 3 wires directly connected with Power Unit (+5V, GND, HEATING).

consists of: 
* small wall mount case
* 2x16 char LCD display
* 3 buttons (plus, minus, mode)
* DHT22 temperature/humidity sensor
* ESP8266 MCU (Wemos D1 mini)
* transistor for relay

### Power Unit
To be installed near or inside the actual heating. 
Power supply must be connected to power (230V), heating relay (2 wires) connects to room thermostat terminals on the heating controller. 
Supports all 5-240V AC/DC (but requires extra relay to switch high loads such as an electric heating!).

consists of: 
* power supply module (5V/3W)
* 5V close-circuit relay for heating control


## Libraries

### ESP8266 core for Arduino 2.4.0
* ESP8266WiFi.h
* WiFiClient.h
* ESP8266WebServer.h
* ESP8266mDNS.h
* ESP8266HTTPUpdateServer.h
* DNSServer.h
* FS.h (SPIFFS)
* Wire.h (I2C library)

https://github.com/esp8266/Arduino

### ArduinoJson 5.13.0
from library manager

### Adafruit DHT-sensor-library (DHT.h)
Used unmodified for reading the DHT22 sensor. 

https://github.com/adafruit/DHT-sensor-library

### Adafruit Sensor 1.0.2
Not really used, but has to be installed when using Adafruit DHT-sensor-library (even if I dont use the DHT_U.h version included in this lib, but gives compile error if not installed).

https://github.com/adafruit/Adafruit_Sensor

### r-downing PersWiFiManager 3.0.1
AP with captive portal for initial (WiFi-) configuration. 
Used with modification - added #define WIFI_HTM_PROGMEM to PersWiFiManager.cpp (turns off SPIFFS usage and stores HTML page to PROGMEM)

https://github.com/r-downing/PersWiFiManager

### knolleary PubSubClient 2.6
MQTT client for Arduino. Used with the following modified DEFINEs in PubSubClient.h: 
* MQTT_MAX_PACKET_SIZE: increased to 512, needed for receiving/parsing domoticz/out topic
* MQTT_SOCKET_TIMEOUT: decreased to 2, to improve non-blocking operation

https://github.com/knolleary/pubsubclient

https://pubsubclient.knolleary.net/

### LiquidCrystal I2C (commit e3701fb, Mar 9 2017)

https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

### r89m Button + PushButton
Button handling library with callbacks on press, release, hold, hold-repeat.
PushButton.h extends Button.h.

https://github.com/r89m/PushButton

https://github.com/r89m/Button

### Bounce2
used by r89m Button/PushButton.

https://github.com/thomasfredericks/Bounce2