Skip to content

Instantly share code, notes, and snippets.

@EverythingSmartHome
Created May 31, 2022 13:04
Show Gist options
  • Save EverythingSmartHome/4f8c9d8e94bffb44c7b7965f172b6470 to your computer and use it in GitHub Desktop.
Save EverythingSmartHome/4f8c9d8e94bffb44c7b7965f172b6470 to your computer and use it in GitHub Desktop.
ESPHome Config for DFRobot mmWave SEN0395 Sensor
esphome:
name: mmwave-occupancy
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "password"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "mmWave-Occupancy"
password: "password"
substitutions:
device_name: mmwave-sensor
captive_portal:
web_server:
port: 80
version: 2
include_internal: true
http_request:
useragent: esphome/$device_name
timeout: 2s
switch:
- platform: safe_mode
internal: true
name: use_safe_mode
binary_sensor:
- platform: gpio
name: mmwave_in_bedroom
pin:
number: GPIO16
mode: INPUT_PULLDOWN
uart:
id: uart_bus
tx_pin: GPIO4
rx_pin: GPIO5
baud_rate: 115200
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
number:
- platform: template
name: distance
id: distance
min_value: 0
max_value: 1350
initial_value: 315
optimistic: true
step: 15
restore_value: true
unit_of_measurement: cm
set_action:
- uart.write: "sensorStop"
- delay: 1s
- uart.write: !lambda
int cm = (int)ceil(x / 15.0);
std::string cms = "detRangeCfg -1 0 " + to_string(cm);
return std::vector<unsigned char>(cms.begin(), cms.end());
- delay: 1s
- uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
- delay: 1s
- uart.write: "sensorStart"
- platform: template
name: latency
id: latency
min_value: 0
max_value: 65000
initial_value: 12500
optimistic: true
step: 25
restore_value: true
unit_of_measurement: ms
set_action:
- uart.write: "sensorStop"
- delay: 1s
- uart.write: !lambda
int ms = (int)ceil(x / 25.0);
std::string mss = "outputLatency -1 0 " + to_string(ms);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
- delay: 1s
- uart.write: "sensorStart"
button:
- platform: restart
name: Restart $device_name
- platform: template
name: "factory_reset_sensor"
id: "factory_reset_sensor"
on_press:
- uart.write: "sensorStop"
- delay: 1s
- uart.write: "factoryReset 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
- delay: 3s
- uart.write: "sensorStart"
@mpch13
Copy link

mpch13 commented Feb 23, 2023

why you didnt define an uar.write sensorStart? could you post your yaml platform template configuration? i am getting errors with mine.
Edit:
so this si how it should be coded? it doesnt seem to work.

- platform: template
name: "turn off mmwave led"
id: "turn_off_led"
on_press:
- uart.write: "sensorStop"
- delay: 1s
- uart.write: "setLedMode 1 1"
- delay: 1s
- uart.write: "setUartOutput 1 0"
- delay: 1s
- uart.write: "setUartOutput 2 1 1 2"
- delay: 1s
- uart.write: "saveConfig"
- delay: 3s
- uart.write: "sensorStart"
- delay: 6s # the sum of mmwave_sensor delays

@Oinq
Copy link

Oinq commented Apr 24, 2023

Great work! Will you publish the V2, @EverythingSmartHome ?

Just came here searching and asking for this.
Will you publish the code for this V2?

Since I have the stuff home, I'll build one, if it works nicely you can expect a new client for a maybe 4 units.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment