Skip to content

Instantly share code, notes, and snippets.

@fracarvic
Created July 26, 2024 16:25
Show Gist options
  • Select an option

  • Save fracarvic/f9fad50e08c6362296159224c9a63488 to your computer and use it in GitHub Desktop.

Select an option

Save fracarvic/f9fad50e08c6362296159224c9a63488 to your computer and use it in GitHub Desktop.
ESPHome package for DFRobot SEN0610 (12m) mmwave radar using UART
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"
@fracarvic
Copy link
Author

This yaml can be used as a esphome package, can be used in your own device yaml with:

packages:
  radar: !include
    file: packages/dfrobot-sen0610.yaml
    vars:
      uart_tx_pin: GPIO4
      uart_rx_pin: GPIO5

@tetrdd
Copy link

tetrdd commented Jul 6, 2025

The query config does not work for me. here are the logs:

[21:52:04][D][text_sensor:069]: 'UART Text': Sending state '$DFDMD,1,1,0.631,-0.210,2754, , *'
[21:52:04][D][button:010]: 'Query config' Pressed.
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'getLatency'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>$DFDMD,1,1,0.613,-0.179,75490, , *'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'getRange'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'Response 0.000 13.000'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'Done'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>$DFDMD,1,1,0.597,-0.152,43681, , *'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'getTrigRange'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>$DFDMD,1,1,0.583,-0.130,61200, , *'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state '$DFDMD,1,1,0.572,-0.111,100009, , *'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'getSensitivity'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>$DFDMD,1,1,0.562,-0.094,83620, , *'
[21:52:04][D][text_sensor:069]: 'UART Text': Sending state '$DFDMD,1,1,0.553,-0.080,253205, , *'

@tetrdd
Copy link

tetrdd commented Jul 6, 2025

The same happens with applying the config

[22:39:59][D][button:010]: 'Apply config' Pressed.
[22:39:59][D][switch:016]: 'mmWave sensor' Turning OFF.
[22:39:59][D][switch:055]: 'mmWave sensor': Sending state OFF
[22:39:59][D][text_sensor:069]: 'UART Text': Sending state 'sensorStop'
[22:39:59][D][text_sensor:069]: 'UART Text': Sending state 'sensor stopped already'
[22:39:59][D][text_sensor:069]: 'UART Text': Sending state 'Done'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>setLatency 2.000000 60.000000'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>setRange 0.600000 6.000000'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'Done'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>setTrigRange 6.000000'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>setSensitivity 7.000000 5.000000'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'Error'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>saveConfig'
[22:40:00][D][text_sensor:069]: 'UART Text': Sending state 'Done'
[22:40:01][D][switch:012]: 'mmWave sensor' Turning ON.
[22:40:01][D][switch:055]: 'mmWave sensor': Sending state ON
[22:40:01][D][text_sensor:069]: 'UART Text': Sending state 'DFRobot:/>sensorStart'
[22:40:01][D][text_sensor:069]: 'UART Text': Sending state 'sensor started already'
[22:40:01][D][text_sensor:069]: 'UART Text': Sending state 'Done'

@rachitdBeast
Copy link

Hi, the code is working in my case and output white led is also turning on when presence is detected, But same is not getting updated on homeassistant.
image

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