HI, I have my own made door/window sensor board using an ESP12 module, I have my own code that sends an ESP-Now message when triggered by the door opening or closing.
After transmitting the door status it pwers itself down until triggeed again consuming around 4 - 5uA.
Some people on my github page have asked if it can be used with ESPHome but I don’t really know ESPHome, I use HA but not yet with ESPHome.
Is there a way to configure it to use ESPHome so that when it powers up it reads GPIO13 (reed switch input) and sends the state to HA then switch GIPIO 16 low to power off the device.
link to github page GitHub - gadjet/Window-Door-sensor-Version-5: Version 5 of the Window/Door sensor project this time with ultra low current consumption
Very nice project!
An ESPHome implementation on the device seems doable to me. Pretty standard configuration for the input button and reed switch would be binary sensors, adc input for battery, and gpio switch for the GPIO16 that defaults to ON. on_boot: trigger would be used to wait until the HA api connects, delay for the sensors to update, then switch off the power latch. Static IP address would cut down on wifi traffic/power a little bit but still not as efficient as ESP-NOW.
Alternative could be a mains powered ESP-NOW to HA bridge device using two esp modules. One would listen for the ESP-NOW messages, send the updates to the other ESP over serial connection. That ESP would have ESPHome connection to HA for all the potential sensors.
Thanks, I’m currently using another ESP12 as a receiver plugged into a Pi4 and feeding NodeRed.
I do plan to move it all over to another Pi4 running HA with the NodeRed addon so I only power one Pi for everything.
I also designed a PCB to hold two Adafruit ESP QT PYs to make a standalone gateway but I’ve just not got around to finishing it off.
It’s just that I keep getting asked about running the module with ESPHome.
Hi there,
meanwhile I received a couple of gadjet’s pcb’s and soldered the reed switch and the ESP-12E to the pcb.
Next step would be flashing it with the appropriate ESPhome code.
Frankly speaking I would appreciate very much to get some support in doing that. @mulcmu, can you please share your ESPhome code?
My post above was just speculation. I don’t have any of these boards to test, anyway here was my crack at the ESPHome implementation from above post…
esphome:
name: test
on_boot:
- wait_until:
condition:
api.connected:
- delay: 5s
- switch.turn_off: power_latch
esp8266:
board: esp12e
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
password: !secret esp_home_ota_pw
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Optional manual IP
manual_ip:
static_ip: 192.168.100.100
gateway: 192.168.100.1
subnet: 255.255.255.0
sensor:
- platform: adc
pin: A0
name: "Battery"
update_interval: 50ms
#add filter and scale here
switch:
- platform: gpio
pin: GPIO16
id: power_latch
name: "Power Latch"
internal: true
icon: "mdi:power"
restore_mode: ALWAYS_ON
binary_sensor:
- platform: gpio
pin: GPIO13
name: "Reed Switch"
- platform: gpio
pin: GPIO12
name: "Aux Input"
Great, I will test your code and report later. Thank you!
@mulcmu, I flashed your code to a ESP12, next step I will solder the ESP to gadjet’s pcb. Then test your code.
The sensor is working!
This is how I tested the node:
Window is closed and will be opened (node is offline, magnet fixed to the reed switch): When I remove the magnet from the reed switch, the node goes online after 12 s. And goes offline after 35 secondes more.
Same when I close the window (node is offline, magnet removed from the reed switch): When I fix the magnet to the reed switch, the node goes online after 12 seconds and goes offline again after 35 seconds more.
@mulcmu, do you think there is a possibility to make the sensor faster? What about the delay in the on_boot procedure?
If you remove the 5s delay then that will leave the 7 seconds it takes for the ESP to negotiate a connection with your router, I don’t believe this time can be reduced, it may be 5 seconds it may be 7 seconds, if you have a static IP address fixed inyour router that that’s the fastest it will be.
That’s te reason I use ESP_Now it doesn’t use the router and therefore it connects to the gateway ESP in milliseconds and therefore is virtually instant and uses a lot, lot less battery power.