An independent temperature sensor as part of the IoT thermostat

As mentioned in one of my previous posts, a typical thermostat can be broken down into four subsystems:

  1. HVAC controller for activating heater/ac/fan
  2. Temperature sensor
  3. Temperature set point: interface for setting desired temperature
  4. Thermostat: logic for determining the the hvac state to achieve the desired temperature

The purpose of the temperature sensor is to provide the current temperature for the thermostat API so that it can determine whether or not the home needs to be heated or cooled. Potentially, multiple temperature sensors could be in various rooms to help determine how well the heating/cooling system is distributing the temperature across the house. While the hvac controller is an actuator (it acts on the physical world), the temperature sensor reports information on the physical world. That being said, the hardware, software, and API for the temperature sensor are actually very similar to that of the hvac controller.


Wemos D1 Mini ESP8266

  • TMP36GZ temperature sensor


  • Power source

Currently the power source is just from a usb adapter, however, I intend on exploring powering the device from battery in the future. This may be useful: I need to do more research, but I have made some rough calculations on battery life for the device.

  • ESP idle current: 70mA
  • ESP sleep current: <1mA (microamps)
  • ESP sending current: 70 – 140 mA… around 80 mA most of the time
  • Time to wakeup, connect to WiFi, and send state: ~5.5 seconds
  • Battery life (assuming 1000mAh battery, very rough estimates)
    • Sending data once a minute: ~1 week battery life
    • Sending data once an hour: ~1 year battery life

Also, I may include a schematic in the future, but for now I will include a picture, as well as a description of the connections.

ESP8266 Pins

  • A0 (analog pin) –> TMP36GZ pin 2 (voltage out, middle pin)
  • G (ground) –> power source ground and TMP36GZ pin 3 (right pin)
  • 3V3 (VCC) –> power source 3.3V and TMP36GZ pin 1 (left pin)
Temperature Sensor Wiring

Temperature Sensor Wiring


The software for the esp8266-based temperature sensor is also very similar to that of the hvac controller. The principal differences are that the temperature sensor uses PUT requests to send data to its API and update its state, whereas the hvac controller uses GET requests to retrieve its state. The software was created in the Arduino IDE, which was also used to flash the image onto the esp8266 over USB.

  1. Connect to WiFi
  2. Read temperature from analog pin
  3. Send temperature to API
  4. Parse response and update state as needed
  5. Wait/sleep for a set time (update_period)
  6. Repeat from step 2


Diagram of IoT Thermostat APIs

The REST API for the temperature is also very similar to the hvac controller API. Below is a brief summary of the API.

Code for API:



The main parameter of the temperature sensor state is–unsurprisingly–the temperature. This is the only parameter that the device updates.

  • temperature:  A number representing the temperature
  • temperature_scale: A string indicating “fahrenheit” or “celsius”.
  • area (String): A string indicating the area in the home that the temperature sensor is responsible for. Ex) “Family Room”
  • update_period (Number): How often (in seconds) the physical device should query the api to update its state.
  • uuid (String): A unique ID representing the sensor.


"update_period": 10,
"uuid": "6d6f37fbae8947979cd6a95098649875", 
"area": "test_area", 
"temperature": 67, 
"temperature_scale": "fahrenheit"

API Resources & Methods






Leave a Reply

Your email address will not be published. Required fields are marked *