Files
jdillenburg-esphome/trash/basement-stairs-mmwave-sensor.yaml
John Dillenburg d1578f36e0 yaml
2024-11-24 15:47:04 -06:00

199 lines
4.8 KiB
YAML

substitutions:
device_name: basement-stairs-mmwave-sensor
device_name_pretty: "basement stairs mmwave sensor"
esphome:
name: ${device_name}
friendly_name: ${device_name_pretty}
includes:
- leapmmw_sensor.h
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: DEBUG #You Can Use "INFO" Level
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "gNh+IsnVWnhDp3rXf2hMHB7ZpAx6ScnZo1TCQxYibQg="
ota:
password: "c56a9c1d07dc8f2eff30e19b961b405c"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Basement-Stairs-Mmwave-Sensor"
password: "zwj6vOqPQePO"
captive_portal:
uart:
id: SEN095_UART_BUS
rx_pin: GPIO16
tx_pin: GPIO17
baud_rate: 115200
data_bits: 8
stop_bits: 1
parity: NONE
# Example configuration entry
dfrobot_sen0395:
binary_sensor:
- platform: gpio
name: "${device_name_pretty}"
id: mmwave_presence_detection
device_class: motion
pin:
number: 27
mode: INPUT_PULLDOWN
# when motion is detected, the radar sensor is on so publish radar state to HA
on_press:
then:
lambda: !lambda |-
if (!id(mmwave_sensor).state) {
id(mmwave_sensor).publish_state(true);
}
sensor:
- platform: custom
lambda: |-
auto s = new leapmmw(id(SEN095_UART_BUS));
App.register_component(s);
return {};
sensors:
switch:
- platform: safe_mode
name: use_safe_mode
- platform: template
name: "${device_name_pretty} mmwave_sensor"
id: mmwave_sensor # do not change
entity_category: config
optimistic: true
turn_on_action:
- uart.write: "setUartOutput 1 0"
- delay: 1s
- uart.write: "saveConfig"
- delay: 4s
- uart.write: "sensorStart"
turn_off_action:
- uart.write: "sensorStop"
- delay: 2s
- platform: template
name: "${device_name_pretty} led"
id: led # do not change
entity_category: config
optimistic: true
turn_on_action:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: "setLedMode 1 0"
- delay: 3s
- lambda: |-
leapmmw(id(SEN095_UART_BUS)).getmmwConf("getLedMode 1");
- delay: 2s
- switch.turn_on: mmwave_sensor
turn_off_action:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: "setLedMode 1 1"
- delay: 3s
- lambda: |-
leapmmw(id(SEN095_UART_BUS)).getmmwConf("getLedMode 1");
- delay: 2s
- switch.turn_on: mmwave_sensor
number:
- platform: template
name: "${device_name_pretty} distance"
id: distance # do not change
entity_category: config
min_value: 0.15
max_value: 9.45
step: 0.15
unit_of_measurement: M
mode: box
lambda: |-
leapmmw(id(SEN095_UART_BUS)).getmmwConf("getRange");
return {};
set_action:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: !lambda
std::string range = "setRange 0 " + str_sprintf("%.2f", x);
return std::vector<unsigned char>(range.begin(), range.end());
- delay: 3s
- switch.turn_on: mmwave_sensor
- platform: template
name: "${device_name_pretty} latency"
id: latency # do not change
entity_category: config
min_value: 1
max_value: 600
lambda: |-
leapmmw(id(SEN095_UART_BUS)).getmmwConf("getLatency");
return {};
step: 1
unit_of_measurement: s
mode: box
set_action:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: !lambda
std::string setL = "setLatency 0.1 " + str_sprintf("%.0f", x);
return std::vector<unsigned char>(setL.begin(), setL.end());
- delay: 3s
- switch.turn_on: mmwave_sensor
- platform: template
name: "${device_name_pretty} sensitivity"
id: sensitivity # do not change
entity_category: config
min_value: 0
max_value: 9
lambda: |-
leapmmw(id(SEN095_UART_BUS)).getmmwConf("getSensitivity");
return {};
step: 1
set_action:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: !lambda
std::string mss = "setSensitivity " + to_string((int)x);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 3s
- switch.turn_on: mmwave_sensor
button:
- platform: restart
name: Restart_ESP_${device_name}
entity_category: diagnostic
on_press:
- uart.write:
id: SEN095_UART_BUS
data: "resetSystem 0"
- platform: template
name: factory_reset_mmwMCU_${device_name}
id: factory_reset_mmwMCU
entity_category: diagnostic
on_press:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: "resetCfg"
- delay: 3s