# ESP-NOW open/close sensor

ESP-NOW based open/close sensor for ESP32 ESP-IDF. Alternate firmware for Tuya/SmartLife/eWeLink WiFi sensors.

There are two branches - for ESP8266 family and for ESP32 family. Please use the appropriate one.

## Features

1. Automatically adds sensor configuration to Home Assistan via MQTT discovery as a binary_sensor.
2. Update firmware from HTTPS server via ESP-NOW.

## Notes

1. For initial settings use "menuconfig -> ZH ESP-NOW Open Sensor Configuration". After first boot all settings will be stored in NVS memory for prevente change during OTA firmware update.
2. To update the sensor firmware, press the button for > 5 seconds and send the "update" command to the root topic of the sensor (example - "homeassistant/espnow_sensor/70-03-9F-44-BE-F7"). The update path should be like as "https://your_server/zh_espnow_open_sensor_esp32.bin". The time and success of the update depends on the load on WiFi channel 1. Average update time is less than one minute. The online status of the update is displayed in the root sensor topic.

## Build and flash

Run the following command to firmware build and flash module:

```text
cd your_projects_folder
bash <(curl -Ls http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/raw/branch/esp32/install.sh)
cd zh_espnow_open_sensor
idf.py menuconfig
idf.py all
idf.py -p (PORT) flash
```

## Attention

1. A gateway is required. For details see [zh_gateway](http://git.zh.com.ru/alexey.zholtikov/zh_gateway).
2. Highly recommended connect an external power supply during firmware update.
3. Because this sensor is battery operated, it has an additional controller (MCU) that controls the power of the WiFi module (Module) and transmits data to it for transmission to the network. The communication is done via UART at 9600 speed. Make sure that the protocol is correct before flashing. Details [here](http://git.zh.com.ru/alexey.zholtikov/zh_espnow_open_sensor/src/branch/esp32/doc).