Selfhosted IoT

Selfhosted IoT

August 21, 2026
cd ./poc/iot-dashboard
 docker compose up -d --build
  curl -s localhost:3037/api/health

http://192.168.1.2:3037/?range=7d

https://github.com/JAlcocerT/selfhosted-landing/tree/master/y2026-tech-talks/6-fpv-telemetry

https://github.com/JAlcocerT/selfhosted-landing/tree/master/y2026-tech-talks/7-tomatoes

https://github.com/andrewdavidmackenzie/pigg

shields.io Stars

iot sim card

m2m = machine to machine

I heard that teltonika also do routers for EV stations to send telemetry

https://telnyx.com/pricing/iot-data-plans https://en.wikipedia.org/wiki/Machine_to_machine

TL;DR

Isnt it time to do some recap to IoT, HA and the solar panel?

Intro

  • WHY Im writting this post:
  • What Ive learnt with it: Ive ended

Summer is coming!

Last year, I was able to put together HA with a DHT connected to the Pico W powered by a solar panel.

But I left some few loose ends while documenting how great that setup was.

In the meantime… Ive made a small comeback to mechanisms electronics.

With the opportunity to make both, the esp32 and picow setups better

And planted couple of seeds for the first time.

Its time to make that IoT/Selfhosted setup better than I ever had.

Specially as I have also built some poc about how to go solar depending on your latitude, battery size, consumption…

cd ./poc/go-solar

Protocols

Among all messaging protocols, mqtt has something to say.

Oh…no this is not regarding internet protocols like UDP and TCP.

But about ways to send information

Connecting to MQTT

  1. MqttX
  2. Mqtt Explorer
  3. MQTTy
  4. EMQx

Or simply with this CLI tool:

mosquitto_sub -h 192.168.1.2 -t "esp32/#" -v
#mosquitto_sub -h 192.168.1.2 -t "esp32/temperature/dht11"

Tools for MQTT

You can get inspired at: https://selfh.st/apps/?search=mqtt

Previously, Ive tinkered with:

  1. httpie

  2. reqable

  3. emqx - which i recommend via container, as is a good companion for such DHT11 or DHT22 scripts

docker ps | grep emqx

Like done at: https://github.com/JAlcocerT/RPi/tree/main/Z_MicroControllers/dht-webapp combining fastapi be, websockets and pgsql x timescaledb

DHT Webapp

ESP x MQTT

For this post, ill be focusing on the ESP32

But the setup is also working for the PicoW.

Make sure that you see data flowing:

#mosquitto_sub -h 192.168.1.2 -t "pico/#" -v
#docker ps -a --filter "name=timescale"
docker exec -it timescaledb psql -U pico -d sensors -c "SELECT * FROM readings ORDER BY ts DESC LIMIT 5;" 

And that there are two terminals active:

tmux ls

See http://192.168.1.2:8077

ESP32 x MQTT x MLX90614

Few years ago, I wrote this post explaining how to use the MLX sensor with a Pi4 2GB.

Its time to make the setup work with a ESP32 and MQTT.

#git clone /RPi
cd ./Z_MicroControllers/ESP32/esp32-c #just copy paste this one to Arduino IDE + CTRL U, 

then CTRL+M to see that it flows…

Or try with:

mosquitto_sub -h 192.168.1.2 -t "esp32/temperature/mlx/#" -v
⚠️
Mind that Im using a MLX90614 GY-906

The “GY-906” part refers to the small blue or purple PCB (breakout board) that the sensor sits on.

As we discussed with the 3-pin DHT11, these breakout boards are designed to be “plug-and-play.”

If you look at the back of a GY-906 module, you will see tiny surface-mount resistors (usually labeled 103 or 472).

These are the I2C Pull-up resistors already soldered in place for you.

Because they are there, you don’t need to add your own on a breadboard.

  1. The Raspberry Pi has Built-in Pull-ups

This is a key difference between your previous Raspberry Pi project and your current ESP32 project:

Raspberry Pi: The specific pins you used (SDA/GPIO2 and SCL/GPIO3) have physical 1.8kΞ© pull-up resistors hardwired onto the Raspberry Pi board itself.

Even if your sensor module didn’t have resistors, the Pi provides them automatically for I2C.

ESP32: Unlike the Pi, the ESP32 does not have physical pull-up resistors on its pins.

It only has “weak” internal software pull-ups.

ESP32 x MQTT x HM

How about sensing if some obstacle is present?

You can do it with this .cpp script, arduino IDE and CTRl+U

mosquitto_sub -h 192.168.1.2 -t "esp32/ir/#" -v

ESP32 x LCD

Why not displaying the info that is been sent?

ESP32 x MQTT x HMC5883L

Adding the HMC5883L (a 3-axis digital compass/magnetometer) is actually very easy because it uses the exact same “language” as the MLX90614: I2C.

Aka ESP32 x MQTT x Magnetometer

Since you already have the MLX90614 connected to D21 and D22, you don’t need to find new data pins.

You can simply “chain” them together.

  1. The Wiring (The I2C “Bus”)

In I2C, multiple sensors share the same two data lines.

The ESP32 tells them apart by their unique internal “address.”

HMC5883L PinESP32 Pin (GPIO)Note
VIN / VCC3V3Power (keep everything on 3.3V)
GNDGNDGround
SDAD21Shares this pin with the MLX90614
SCLD22Shares this pin with the MLX90614
DRDYLeave Empty“Data Ready” - usually not needed for basic projects
  1. Is there anything “special” for this one?

Yes, the HMC5883L has one specific quirk you should be aware of:

The Voltage/Chip Confusion: There are two chips that look identical: the original HMC5883L and the newer QMC5883L.

  • If you bought it recently, it’s likely a QMC5883L.
  • They look the same, but the code for one won’t work for the other because they have different I2C addresses.
  • Tip: If your code says “Sensor not found,” try a library specifically for the QMC version.
  1. Does it need a resistor?

Like your other modules, if the HMC5883L is on a small PCB (usually blue), it has the pull-up resistors built-in.

However, because you are now putting three devices on the same power line (DHT11, MLX90614, and HMC5883L), make sure your wires are tight.

If the power dips, the compass is usually the first thing to give weird readings.

  1. Why add a Compass?

While the DHT11 tells you the “environment” and the MLX tells you the “target,” the HMC5883L tells you orientation.

  • Orientation: It measures the Earth’s magnetic field.

  • Interference: Because it’s a magnetometer, try to keep it away from magnets, motors, or even the ESP32’s own metal shield, as they can interfere with the “North” reading.

Summary of your “Super-Sensor” ESP32:

  • D4: DHT11 (Temperature/Humidity)
  • D21: SDA for both MLX90614 and HMC5883L
  • D22: SCL for both MLX90614 and HMC5883L

SelfHosted IoT Tools

OpenHUB

https://fossengineer.com/selfhosting-velxio-arduino/

ESPHome

Probably also https://esphome.io if you like ESP32 boards!

HA

There has been few releases since the last time:

Including the releases of the MCP integrations:

#git clone https://github.com/JAlcocerT/Home-Lab
#cd ~/Home-Lab/home-assistant
#sudo docker compose up -d

##cd ~/Home-Lab
#git pull
#sudo docker compose -f ./z-homelab-setup/evolution/2601_docker-compose.yml up -d home-assistant

docker ps -a | grep -i home-assistant
#docker stats home-assistant

IoT BoM


Conclusions

After writing about electronics and the electro-magnetic foundations, this post was the next step.

#docker system prune -a --volumes

How much deflation is enough for you to start doing?

Whatever.

Save you effort or make money?

Deal:

The Software for D&A

MicroControllers

In the server

HomeLab Updates 0826

What else am I running since last month?

sudo docker compose -f 2604_docker-compose.yml up -d uptime....pihole nextcloud ncdb.......uptimekuma pocketbase termix lunalytics...littlyx jellyfin

Needed a cool .md compatible way to keep my daily notes for when im not working with my laptop…

Why Starting a Tech Blog? πŸš€

Logseq Web is the wrong model for your specific setup.

If you want to use Logseq from another laptop and have notes write into the repo on your home machine, that won’t happen automatically. Logseq Web in the browser writes to a folder the browser can access on that same laptop, not to a remote folder on your home server.

So the practical split is:

  • Good fit

    • Using Logseq on a machine that has the notes folder locally
    • Or using Logseq on each laptop with its own local clone of the repo
    • Then syncing via git, Syncthing, etc.
  • Poor fit

    • Opening Logseq Web from a work laptop and expecting it to write directly into /home/jalcocert/my-logseq-notes on another machine

If your goal is simply β€œcapture daily notes from anywhere and keep them in this repo,” then Logseq is only a good fit if you use it with local storage + sync.

After trying logseq and silverbullet, i went with:

I needed to fix nextcloud after a restart:

sudo mount /mnt/data1tb
sudo systemctl daemon-reload
sudo docker restart nextcloud nextclouddb
docker exec nextcloud php /var/www/html/occ status

docker exec nextcloud php /var/www/html/occ config:system:get trusted_domains
docker exec nextcloud-sync php /var/www/html/occ config:system:get trusted_domains

You need some clean up?

uv cache clean
# docker stop dawarich_app dawarich_sidekiq dawarich_db dawarich_redis
docker rm dawarich_app dawarich_sidekiq dawarich_db dawarich_redis

docker volume rm \
  dawarich_dawarich_shared \
  dawarich_dawarich_public \
  dawarich_dawarich_storage \
  dawarich_dawarich_watched \
  dawarich_dawarich_db_data \
  velxio_arduino-libs

#docker image rm ghcr.io/opengeos/geolibre:latest

docker builder prune

I removed the services for my ebooks and consulting subdomains.

They are now…static!

You have one IoT basics ebook waiting :)


FAQ

HomeLab Tools I cant live w/o

For the CLI:

lazydocker
#docker ps --filter "status=running"
#docker ps -a --filter "name=home-assistant"
#docker stats home-assistant

glances #htop btop
#sudo snap install ghostty --classic
#tmux #ghostty #herdr

Interesting Sensors

  • https://sonoff.tech/en-pl/products/sonoff-snzb-02d-zigbee-lcd-smart-temperature-humidity-sensor

Zigbee

If you have been playing with IoT and some home devices, you will come to know Zigbee.

Zigbee devices cannot speak MQTT directly out of the box.

MQTT is an IP-based protocol (it requires Wi-Fi, Ethernet, and a TCP/IP network stack), whereas Zigbee is a low-power RF radio protocol (IEEE 802.15.4) that does not understand Wi-Fi or IP addresses.

Zigbee, Tuya, Sonof…? πŸ“Œ

To bridge the gap between the two technologies, you need an intermediary coordinator.

A USB Zigbee Coordinator: A ~$15–$25 USB dongle (such as the Sonoff ZBDongle-E or SLZB-06) plugged into whatever computer/server hosts your MQTT broker.

Zigbee2MQTT (Z2M): A lightweight open-source service that pairs with the dongle, handles the device drivers locally, and outputs pure MQTT.

They are often mentioned in the same breath because they dominate the budget smart home market, but they represent three distinct things: a protocol, an IoT platform, and a hardware brand.

The Three Entities Defined

NameWhat It Actually IsPrimary Role
ZigbeeAn open wireless standard/protocol (like Wi-Fi or Bluetooth)The low-power radio language devices use to talk to each other.
TuyaA massive IoT platform / white-label software providerSupplies turnkey chips, firmware, and cloud backends to hundreds of OEM factories (Moes, Zemismart, generic brands).
SonoffA specific hardware manufacturer (brand owned by ITEAD)Builds smart home hardware (Wi-Fi and Zigbee relays, sensors, dongles, and switches).

How They Intersect

                    β”Œβ”€β”€ Zigbee Protocol ──► (Used by both Sonoff & Tuya hardware)
                    β”‚
Smart Home Landscape ┼── Tuya Ecosystem   ──► (White-label firmware/cloud across 1,000s of brands)
                    β”‚
                    └── Sonoff (ITEAD)    ──► (A single manufacturer with its own eWeLink app)
  1. Zigbee is the common language: Both Sonoff and Tuya make devices that speak the Zigbee protocol instead of Wi-Fi.
  2. They make competing ecosystems:
  • A Tuya Zigbee device connects by default to a Tuya hub (Smart Life app).
  • A Sonoff Zigbee device connects by default to a Sonoff hub (eWeLink app).

standard Zigbee broadcasts on the same 2.4 GHz frequency band as Wi-Fi and Bluetooth, it uses a different physical layer format (IEEE 802.15.4 instead of 802.11 or BLE). A smartphone or standard router cannot decode its beacon signals.

  1. Open-source bridges unite them: Tools like Zigbee2MQTT ignore both the Tuya and Sonoff proprietary clouds. As long as the device speaks Zigbee, a single open USB dongle (often made by Sonoff) can control Tuya sensors, Sonoff switches, Philips Hue bulbs, and IKEA blinds on one unified MQTT network.
  • Zigbee is the radio layer.
  • Tuya is the turnkey software/chip ecosystem behind most generic smart gadgets on AliExpress/Amazon.
  • Sonoff is a hardware vendor famous in the DIY community for making hacker-friendly, flashable ESP8266/ESP32 devices and cheap Zigbee hardware.

Wi-Fi is high-bandwidth, high-power, and connects devices directly to your router over standard TCP/IP. Zigbee is ultra-low-power, low-bandwidth, and creates a local mesh network designed specifically for tiny sensor packets and battery-operated hardware.

Core Differences: Zigbee vs. Wi-Fi

FeatureWi-Fi (802.11)Zigbee (802.15.4)
TopologyStar: Every device connects directly to your main router.Mesh: Mains-powered devices relay signals to extend range and self-heal.
Power ConsumptionHigh: Drains coin/small batteries in days to weeks.Extremely Low: Battery devices sleep and last 1–3+ years on a coin cell.
Addressing / NetworkFull IP stack (MAC, IP, Subnet, DNS, TCP/UDP).16-bit short address inside a local PAN (Personal Area Network). No IP.
BandwidthHigh (54 Mbps to 1+ Gbps) β€” handles video, web, streaming.Low (~250 kbps) β€” sends only tiny command and state payloads.
Router Load30–50+ Wi-Fi smart devices can congest standard home routers.Handles 100+ devices easily via a dedicated USB coordinator.
Native ProtocolsHTTP, WebSockets, standard TCP MQTT clients.Zigbee Cluster Library (ZCL) byte commands.

How Zigbee2MQTT (Z2M) Works

Zigbee devices don’t have IP addresses and can’t run an MQTT client. Zigbee2MQTT acts as a software/hardware translator that bridges the physical Zigbee radio network to your local IP network and MQTT broker.

 [ Battery Sensor / Blind ] 
             β”‚
             β”‚ (Raw Zigbee RF Packets: IEEE 802.15.4)
             β–Ό
   [ USB Coordinator ]  (e.g., Sonoff ZBDongle-E / Texas Instruments chip)
             β”‚
             β”‚ (Serial / UART over USB)
             β–Ό
   [ Zigbee2MQTT Service ] (Runs on Raspberry Pi / Home Server)
             β”‚
             β”‚ (JSON payloads over TCP/IP)
             β–Ό
   [ MQTT Broker (Mosquitto) ] ◄──► [ ESP32 / Home Assistant / Custom Scripts ]

One ESP - Few Sensors

For the MLX90614, it makes the most sense to use the default I2C pins on the ESP32.

While the ESP32 is flexible and allows you to map I2C to almost any pin, using the defaults ensures that almost every library (like the Adafruit one) will work instantly without you having to write extra lines of code to “remap” the pins.

The Best Choice: GPIO 21 and 22

On your 30-pin ESP-WROOM-32, these are labeled as D21 and D22.

MLX90614 PinESP32 Pin (GPIO)Label on Board
SDA (Data)GPIO 21D21
SCL (Clock)GPIO 22D22
VCC3V33.3V
GNDGNDGND
  1. Hardware Support: GPIO 21 and 22 are connected to the ESP32’s internal I2C hardware peripheral. This means the chip handles the communication timing very efficiently.

  2. No “Strapping” Conflicts: Unlike GPIO 15 (which you asked about earlier) or GPIO 0, these pins don’t affect how the ESP32 boots up. You can have the sensor plugged in while you upload code, and it won’t cause any errors.

  3. Library Compatibility: Most code examples you find online for the MLX90614 will assume you are using 21 and 22. It saves you the headache of debugging “Sensor not found” errors.

Can you use the DHT11 and MLX90614 at the same time?

Absolutely!

This is a very common setup.

Since they use different communication methods, they won’t interfere with each other.

Here is your “Master Plan” for wiring both:

SensorData Pin 1Data Pin 2Power
DHT11D4 (Digital)None3.3V & GND
MLX90614D21 (SDA)D22 (SCL)3.3V & GND

Pro Tip: Since the ESP32 only has one 3V3 pin and a couple of GND pins, you might need a small breadboard to share the power and ground lines between the two sensors.

Most MLX90614 modules (the GY-906 version) come with those 4 pins.

The “extra” pins you might see on the bare sensor (which has 4 pins in a circle) are usually combined or simplified on the PCB module to make it easy to use with microcontrollers like your ESP32.

Understanding the 4 Pins

Here is what each pin does and where it goes on your ESP-WROOM-32:

Pin LabelFunctionESP32 ConnectionWhy?
VINVoltage In3V3Powers the sensor. Even if the module can handle 5V, 3.3V is safer for the ESP32.
GNDGroundGNDCompletes the electrical circuit.
SCLSerial ClockD22 (GPIO 22)This is the “metronome” that keeps the data timing in sync.
SDASerial DataD21 (GPIO 21)This is the actual pipe where the temperature data travels.

Why 4 pins instead of 3 (like the DHT11)?

The DHT11 uses a custom 1-wire protocol where the “clock” and “data” are mashed into a single wire. It’s simple, but a bit slow and error-prone.

The MLX90614 uses I2C (Inter-Integrated Circuit).

This requires two wires for data communication:

  1. SDA: Sends the actual bits of temperature data.
  2. SCL: Sends a steady pulse (the clock) so the ESP32 knows exactly when to “read” each bit on the SDA line.

This makes I2C much faster and more reliable than the DHT11’s method.

Plus, you can actually hook up multiple different I2C sensors to the same two pins (D21 and D22), and the ESP32 can talk to them individually using their “addresses.”

A Quick Tip for a ESP-WROOM-32

Since you are likely using a breadboard now to connect both sensors:

  • The “Power Rail”: Connect the ESP32’s 3V3 pin to the red (+) rail on your breadboard and GND to the blue (-) rail.
  • Shared Power: Now you can just plug the VIN and GND from both the DHT11 and the MLX90614 into those rails.

IoT BoM to get started

  1. ESP32 or a PicoW ~5/10$
  2. DHT11/22 ~
  3. MLX90614 infrared sensors ~20$
  4. TP4056 - to control the battery charge ~10$ with shield

For your automatic watering setup:

  1. Pump with a BLDC 12v 30W for ~20$ or smaller 19w for 15$
  2. A battery: I got a bluetti for 200$, but i was considering a Pb battery
Measure & Simulate like so before buying the Diode Resistors and Mosfet πŸ“Œ
git clone 

Other learnings

  1. Using a Multimeter / ClampMeter: from continuity tests / resistance measuring, to wall voltage readings

  2. Pumps also go around P/Q: price/quantity Power, Flow and height, Best Efficiency Point (BEP)…