In a self-made IOT stack, several applications provide, parse, and store data. You might have all applications running on the same or several machines. You might have different sensors providing data, and different methods to access and store this data. For a hobby project, this is all well until the point where things are not running anymore.
In my IOT enabled home, I have several sensors that continuously provide environmental data such as the temperature, humidity, or air quality. In addition, I have experimented with movement sensors and light automation with the goal of activating light during the night when motion is detected. Another idea that sparked my curiosity is motion detection with a video camera or webcam. One camera that I used for permeant video streaming is the ESP32 Camera board: Very compact, very minimal, very low FPWS, and also very simply integrated with ESP Home. However, there is no motion detection feature available.
Building an IOT sensor with the ESP8266 and ESP32 boards can be done in two ways. Either you are starting with a basic sketch that accesses your sensor, and then add the IOT integration (WIFI, MQTT, InfluxDB message). Or you use an integrated System such as ESPHome or Home Assistant with which integration boils down to defining the correct configuration. After an initial sketch for a DHT11 sensor that I programmed completely with Arduino code, the next sensor should be integrated directly into ESPHome and Home Assistant. Following this approach, I want to see how different the approaches are, and in general how much work needs to be done.
When you install IOT sensors inside your house, you will have plenty main power outlets, USB adapters etc. to power your boards. But when sensors should be mobile, or should be used at places without power supply, they need to be powered by batteries. Its easy to provide the correct voltage, but how can you approximate the remaining battery power to ensure continuous operation?
My IOT enabled home grows sensor by sensor. In one of the last articles, I explained which new devices I want to integrate: Power switches and Wi-Fi lightbulbs. Starting with power switches, I made the experience of disassembling, soldering connection lines, and manual flashing. It required some dexterity to solder the connecting pins to the board, but it was possible. Then, manually flashing them with Tasmotizer, and they were available in my Home Assistant application.
In your smart home, controlling and access sensors and devices is an essential capability. From a functional viewpoint, smart power switches just offer a remote control for enabling or disabling power. But from a smart home perspective, these devices allow powerful and creative use cases, like time-based scheduling of other sensors, or the activation and deactivation based on events.
What started with a ESP8266 board and DHT11 temperature sensor to store data in a timeseries DB evolved to a Home Assistant based environment with air quality, temperature, and movement sensors and more than 5 boards. In my journey to extend the home automation systems and further learn about the fascinating and rich Home Assistant ecosystem, I want to add smart lights and smart power switches too. But which protocols do these (proprietary) devices use? Can they be integrated with home assistant?
An MQTT message broker is the standard way to transfer information between different IOT devices. Home Assistant has a powerful MQTT integration for receiving, sending, and processing data. One powerful feature is to use MQTT messages as configuration instructions. The basic idea: Retained messages on the queue are read by devices to change their configuration.
Especially when running your ESP boards on battery, conserving energy is an important aspect. ESPHome controlled boards can be configured for deep sleep, in its most simple form two values for sleep duration and run duration. Yet there are some subtleties to regard: Ensure the run time is appropriate for making WIFI connections, activate all connected sensors, and send data e.g. via MQTT. Once configured, the deep sleep behavior repeats. What will you do if you need to change it? Do you get the sensor, connect it via USB, and upload a new program? Do you hope for an OTA update during the limited time that the sensor is online?
When using Home Assistant to integrate with ESPHome managed devices, connection timeouts can occur. Normally this means that the device could not be reached temporarily only, and will eventually get connected again. However, a particular behavior creates quite a disturbance: Upon reconnection, all configured sensors are activated immediately. This triggers for example motion sensors, sending a false alert. If you have sophisticated automations running, working with false positives is quite a nuisance. So, how can we prevent this?