Created
July 26, 2024 16:25
-
-
Save fracarvic/f9fad50e08c6362296159224c9a63488 to your computer and use it in GitHub Desktop.
ESPHome package for DFRobot SEN0610 (12m) mmwave radar using UART
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
on_boot: | |
priority: 600 | |
then: | |
- delay: 3s | |
- uart.write: "setUartOutput 1 1" | |
external_components: | |
- source: | |
type: git | |
url: https://github.com/ssieb/custom_components | |
components: [serial] | |
uart: | |
id: uart_bus | |
tx_pin: ${uart_tx_pin} | |
rx_pin: ${uart_rx_pin} | |
baud_rate: 9600 | |
text_sensor: | |
- platform: serial | |
uart_id: uart_bus | |
name: UART Text | |
id: UART_Text | |
icon: "mdi:format-text" | |
internal: true | |
on_value: | |
lambda: |- | |
if (id(UART_Text).state.substr(0,6) == "$DFHPD") { | |
if (id(UART_Text).state.substr(7,1) == "1") { | |
if (id(uart_presence).state == false) { | |
id(uart_presence).publish_state(true); | |
} | |
} | |
if (id(UART_Text).state.substr(7,1) == "0") { | |
if (id(uart_presence).state == true) { | |
id(uart_presence).publish_state(false); | |
} | |
} | |
} | |
binary_sensor: | |
- platform: template | |
name: "Presence" | |
id: uart_presence | |
device_class: occupancy | |
switch: | |
- platform: template | |
name: mmWave sensor | |
id: mmwave_sensor | |
disabled_by_default: True | |
entity_category: config | |
optimistic: true | |
internal: true | |
restore_mode: RESTORE_DEFAULT_ON | |
turn_on_action: | |
- uart.write: "sensorStart" | |
- delay: 1s | |
turn_off_action: | |
- uart.write: "sensorStop" | |
- delay: 1s | |
number: | |
- platform: template | |
id: range_minimum | |
name: Range (Min) | |
icon: mdi:arrow-collapse-left | |
entity_category: config | |
min_value: 0.6 | |
max_value: 12 | |
initial_value: 0.6 | |
optimistic: true | |
step: 0.1 | |
restore_value: true | |
unit_of_measurement: m | |
mode: slider | |
- platform: template | |
id: range_maximum | |
name: Range (Max) | |
icon: mdi:arrow-collapse-right | |
entity_category: config | |
min_value: 0.6 | |
max_value: 12 | |
initial_value: 6 | |
optimistic: true | |
step: 0.1 | |
restore_value: true | |
unit_of_measurement: m | |
mode: slider | |
- platform: template | |
id: range_trigger | |
name: Range (Trigger) | |
icon: mdi:arrow-collapse-right | |
entity_category: config | |
min_value: 0 | |
max_value: 12 | |
initial_value: 6 | |
optimistic: true | |
step: 0.1 | |
restore_value: true | |
unit_of_measurement: m | |
mode: slider | |
- platform: template | |
name: Delay (Clearance) | |
icon: mdi:clock-end | |
entity_category: config | |
id: mmwave_off_latency | |
min_value: 0 | |
max_value: 60 | |
initial_value: 15 | |
optimistic: true | |
step: 5 | |
restore_value: true | |
unit_of_measurement: seconds | |
mode: slider | |
- platform: template | |
name: Delay (Detection) | |
icon: mdi:clock-start | |
id: mmwave_on_latency | |
entity_category: config | |
min_value: 0 | |
max_value: 2 | |
initial_value: 0.050 | |
optimistic: true | |
step: 0.05 | |
restore_value: true | |
unit_of_measurement: seconds | |
mode: slider | |
- platform: template | |
name: Sensitivity (Occupancy) | |
icon: mdi:target-variant | |
id: sensitivity_occupancy | |
entity_category: config | |
min_value: 0 | |
max_value: 9 | |
initial_value: 7 | |
optimistic: true | |
step: 1 | |
restore_value: true | |
- platform: template | |
name: Sensitivity (Movement) | |
icon: mdi:target-variant | |
id: sensitivity_movement | |
entity_category: config | |
min_value: 0 | |
max_value: 9 | |
initial_value: 5 | |
optimistic: true | |
step: 1 | |
restore_value: true | |
button: | |
- platform: template | |
name: "Apply config" | |
id: apply_config | |
entity_category: config | |
on_press: | |
- switch.turn_off: mmwave_sensor | |
- delay: 1s | |
- uart.write: !lambda |- | |
std::string mss = "setLatency " + to_string(id(mmwave_on_latency).state) + " " + to_string(id(mmwave_off_latency).state); | |
return std::vector<unsigned char>(mss.begin(), mss.end()); | |
- delay: 0.1s | |
- uart.write: !lambda |- | |
std::string ms = "setRange " + to_string(id(range_minimum).state) + " " + to_string(id(range_maximum).state); | |
return std::vector<unsigned char>(ms.begin(), ms.end()); | |
- delay: 0.1s | |
- uart.write: !lambda |- | |
std::string ms = "setTrigRange " + to_string(id(range_trigger).state); | |
return std::vector<unsigned char>(ms.begin(), ms.end()); | |
- delay: 0.1s | |
- uart.write: !lambda |- | |
std::string mss = "setSensitivity " + to_string(id(sensitivity_occupancy).state) + " " + to_string(id(sensitivity_movement).state); | |
return std::vector<unsigned char>(mss.begin(), mss.end()); | |
- delay: 0.1s | |
- uart.write: "saveConfig" | |
- delay: 1s | |
- switch.turn_on: mmwave_sensor | |
- platform: template | |
name: Restart mmWave Sensor | |
id: restart_mmwave | |
entity_category: config | |
internal: true | |
on_press: | |
- uart.write: "resetSystem" | |
- platform: template | |
name: Factory Reset mmWave | |
icon: mdi:cog-counterclockwise | |
id: factory_reset_mmwave | |
disabled_by_default: false | |
entity_category: diagnostic | |
on_press: | |
- switch.turn_off: mmwave_sensor | |
- delay: 1s | |
- uart.write: "resetCfg" | |
- delay: 3s | |
- switch.turn_on: mmwave_sensor | |
- platform: template | |
name: Query config | |
icon: mdi:cog | |
id: query_config | |
disabled_by_default: false | |
entity_category: diagnostic | |
on_press: | |
- uart.write: "getLatency" | |
- delay: 0.1s | |
- uart.write: "getRange" | |
- delay: 0.1s | |
- uart.write: "getTrigRange" | |
- delay: 0.1s | |
- uart.write: "getSensitivity" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment