Site Tools


Sidebar

FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

Domaines :
en:domotique:garagebox

Why I want home automation for my separate garages too

As William would say : “Why not ?” LOL

The spot installed on the front of the garages is kept turned on because the movement sensor is more or less broken. I tried to adjust the small potentimeters but it still malfunction.
As the spot itself is still working I'd rather reuse it. But I never found the sensor as spare parts so it's a perfect excuse to try to DIY something and learn now things. Moreover I'll have to make it weatherproof and that's a fun challenge.

Last but no least, I'll be able to add new functions and make all of that talk with my home automation server!

What I want to achieve

The bare minimum functions would be :

  • sense humans presence near the garage
  • sense if it's dark enough to allow to turn on the spot
  • being able to turn on and off light(s)
  • sends informations to Home Assistant

Cool functions easy to add :

  • thermometer and hygrometer to have some local weather informations

If it's really too easy I could also try to add :

  • a thermometer in the garage
  • a human presence detector in the garage
  • being able to turn on and off the lights inside the garage
  • control the automated garage doors

But I'll have to think on how to have the sensors and actuators far away from the core of the system.

Tech choices

At first I wanted to buy ready to use zigbee modules. But most of them are running on batteries and I'll probably forget to change them in time. I could make some changes on the devices to add photovoltaic panels but it's hard to keep everything weatherproof.
So I searched other solutions. The simplest one I've found would be a ESPHome based system.
It runs on ESP32, ESP8366 and even RP2040 (with some restrictions on the model) and I can use available breakout boards for compatible sensors and actuators.

Connection to the server would be done over wifi (I'll have to check if house wifi also cover the garage).

What's cool is that the microcontroller can do standalone automation. The connection to home assistant would only serve to get sensor readings, change settings, modify automation or be used as remote for lights.

Another solution would be to use zigbee ready ESP32 like ESP32-C6 (high performances) or ESP32-H2 (low power consumption). It would be a bit more complex but it has the benefit of using the meshed network already deployed in our house. And if done right, it would be able to be used the same as any standard module.

Moreover those ESP32 are also Matter compatible. So it would be possible to flash a new firmware matter compatible.

Parts selection

I used ESPHome's listing to choose the modules. It's mainly based on capabilities described and prices of the modules.

Core

This is a ESP32 Wifi/BLE devboard (it should be compatible with ESPHome).

This is the core of the small home automation installation. Sensors and actuators will be connected with various data bus (I²C, UART, SPI) or on GPIO.

Those boards can often be powered with a large array of voltages. I'll probably use a 12V DC power brick.

Some version of those ESP32 come with an ipex connector instead of the PCB antenna. Allowing us to move the antenna away from the ESP and to use a more efficient external antenna to get better radio signal. I'd rather use that one for the garage since they're quite far away from main house and moreover there are a few walls in the way.

Light and UV sensor

These LTR390 can not only measure light intensity but also measure UV intensity. UV aren't useful for my project, but it's a nice addon for weather informations. This sensor will allow to check if ambient light is low enough for the spot to be turned on or not.

It talk to the MCU using I²C bus.

Presence sensor

The LD2420 doesn't detect movements (like FIR) but it uses millimeter wave radar to detect presence of things that aren't usually there. It allows to fine tune various parameters to detect only what you really want to detect. Those parameters are accessible with ESPHome so I'm going to have loads of fun playing with them.

As it's not a movement detector even if people stay still their presence is detected. So timer is less useful than with movement detector. It integrates some off delay to prevent tuning off then back on if people are on the outer fringe of the area covered by the detector.

It's connected using UART.

Temperature, pressure and humidity sensor

A BME280 will allow to collect weather informations. It's not useful for my project. But the sensor is cheap and it's fun to add more informations to use on my Home Assistant server.

It speaks I²C.

Light actuator

I need at least a relay that can be actuated by 3.3V and can pilot the 230V needed to power my light(s). There are loads of those available on the various webshop. Most of them isolate the 3.3V from the 230V using optocoupler. That way electronic is protected if 230V circuit malfunction in a way or another.

GPIO is the only language it talks.

Attempts

I bought “some” parts. Enough to be able to make multiple prototypes in parallels without having to take apart the previous ones. Here is the “short” list :

  • 5 ESP32
  • 1 ESP32-C6 (zigbee)
  • 1 ESP32-H2 (zigbee)
  • 2 LD2420 (radar)
  • 1 LTR390 (light)
  • 2 BME280 (t°)
  • 5 relays
  • 2 solar kits with 18650 socket
  • 1 DC-DC converter that takes 1 to 6V on input and spits a stable 3.3V on the output.

Test001 ESPHome

I'll start directly trying to use I²C bus. I don't want to loose time trying to read/write GPIO since it's too easy. So I'll try to plug a BME280 on the ESP32.

If I get that to work most of the hardest work will be done.

I'll directly power the whole thing using ESP32's USB.

Firmware

I never used ESPHome so I need some time to get used on how things are coded and how to get that code into the ESP32.

Initialise the ESP

At first I used ESPHome Device Builder's GUI from my Home Assistant using chromium. It allowed me to easily upload a mostly void program into one ESP32-WROOM-32U now named “test001”.

But as soon as I added some bus and sensor definitions, the rapberry pi running Home Assistant gave up on life while trying to compile code. xD

To fix this, I installed ESPHome's CLI tools on one of my beefier computers. It's far faster and I can still upload the new program either using USB or over the air.

Let's take a peek at the code

esphome:
  name: test001
  friendly_name: test001

esp32:
  board: esp32dev
  framework:
    type: arduino
 
# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret ota_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
 
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test001 Fallback Hotspot"
    password: !secret fallback_wifi_password

captive_portal:
    
time:
  - platform: homeassistant
    id: homeassistant_time

We have here the basic setup of the ESP32. I added time sync because I may add some (local) automation using time of the day. And it's easy to add syncing with HA server.

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

Initialising the I²C bus, getting it all sweet and ready to talk with some peripherals.

sensor:
  - platform: bme280_i2c
    address: 0x76
    temperature:
      name: "BME280 Temperature"
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"

We first define the kind of sensor, here a BME280 using I²C.
Then I had to define the 0x76 address because the default one is 0x77 so the ESP couldn't establish the connection to the BME. I had to use an address sniffer sketch on a arduino to get the right address from the BME.
Finally we define the names that will be shown in Home Assistant for the various readings made by the sensor.

Hardware

Wiring I²C devices is really simple. You only need 4 wires :

  • GND on GND
  • 3.3V on 3.3V
  • SDA on gpio 21
  • SCL on gpio 22

Résultats

As I said earlier the default I²C address wasn't the one used by my BME so at first I had that result :

After using the right address :

Huge success! (I'm making a note here)

Adding a LTR390

It's quite trivial since it also use I²C bus. Once again 4 wires connected on the same 4 pins on the ESP32 side and a bit of code are needed :

  - platform: ltr390
    uv_index:
      name: "UV Index"
    uv:
      name: "UV Sensor Counts"
    light:
      name: "Light"
    ambient_light:
      name: "Light Sensor Counts"

And it just works.

Addind a LD2420

This radar isn't harder to wire than the previous two devices :

  • 3.3V on 3.3V
  • GND on GND
  • RX on TX0 ESP
  • OT1 on RX0 ESP (on older LD2420 firmware TX may be on OT2)

Then you need to initialize the UART. Since we already use an UART for logs, you have to keep them from mixing up.

logger:
  id: logz
[]
uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  id: radar

That prevents from getting logs on the sensor channel and inversely.
I'd rather define UART speed myself than hope the default is the good setting. As for the OT2 pin, if your LD2420 is on older firmware you may need to set it to 256000.

The rest of the code isn't complex but there are a lot of parameters so it's quite lengthier than the previous devices. Moreover it's the default code I found on ESPHome website I did no change on it. So as of now, I'll only put what I change in the code to prevent having boring large slabs of code everywhere.

So, with all this the sensor works surprisingly well. Let me be clear, distance readings are all over the place. But even if the PCB is facing the ceiling it detects me everywhere in the room. I had to go out of the room and move away from the door opening to be undetected.
I guess in an open space like in front of the garage and with a well calibrated sensor it should return more accurate readings.

Automation

Now the same using zigbee

I want to evaluate how harder it would be to make the same device using “classic” code and zigbee communication. Because most of my current devices are using that radio communications, so it would be great to keep going with it.

en/domotique/garagebox.txt · Last modified: 2025/02/18 15:21 by kodein