Skip to content

Commit

Permalink
Update Linkind Switch, add esp32c3 and 1core BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
untergeek committed Nov 27, 2024
1 parent 9472790 commit cff96de
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 19 deletions.
29 changes: 29 additions & 0 deletions 1core-ble-tracker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
substitutions:
interval: 320ms
window: 30ms

# This special package is necessary for single-core ESP32s
# The multi-core ESP32s can divide and conquer, having one core do WiFi duty while
# another does BLE, etc. But the ESP32 C3 and others only have a single core.
# With only a single core, trying to poll BLE while trying to connect to WiFi
# causes issues. As a result, we hard code `continous: false` as a scan paramter,
# and add the API configuration to not start BLE scanning until the client is
# connected, and also to stop scanning BLE if the client disconnects.

esp32_ble_tracker:
id: 1core-tracker
scan_parameters:
interval: ${interval}
window: ${window}
continuous: false

api:
on_client_connected:
- esp32_ble_tracker.start_scan:
continuous: true
on_client_disconnected:
- esp32_ble_tracker.stop_scan:

bluetooth_proxy:
active: true
127 changes: 127 additions & 0 deletions template/esp32c3-sw02-03.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
# ESP32-C3 is a single-core ESP32 chip with BLE support
packages:
comm: !include ../common.yaml
togl: !include ../restart_switch.yaml
1ble: !include ../1core-ble-tracker.yaml

substitutions:
project_name: untergeek.esp32c3_sw02-03
project_version: 1.0.0
id1: relay1
id2: relay2
id3: relay3
name1: "Top Switch"
icon1: mdi:toggle-switch-variant
name2: "Middle Switch"
icon2: mdi:toggle-switch-variant
name3: "Bottom Switch"
icon3: mdi:toggle-switch-variant

esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
sdkconfig_options:
CONFIG_FREERTOS_UNICORE: y
CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10"

output:
- platform: gpio
id: output_led_1
pin: GPIO9
- platform: gpio
id: output_led_2
pin: GPIO4
- platform: gpio
id: output_led_3
pin: GPIO2
# Blue status LED behind the WiFi logo
- platform: gpio
id: blue_led
pin: GPIO21
# Red status LED behind the WiFi logo
- platform: gpio
id: red_led
pin: GPIO1

light:
- platform: status_led
name: "ESPHome Status LED"
internal: true
# Can use either "output: blue_led" or "output: red_led"
output: blue_led
# output: red_led
- platform: binary
id: status1
internal: true
output: output_led_1
- platform: binary
id: status2
internal: true
output: output_led_2
- platform: binary
id: status3
internal: true
output: output_led_3

switch:
- platform: gpio
id: ${id1}
pin: GPIO6
name: ${name1}
icon: ${icon1}
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_on: status1
on_turn_off:
- light.turn_off: status1
- platform: gpio
id: ${id2}
pin: GPIO7
name: ${name2}
icon: ${icon2}
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_on: status2
on_turn_off:
- light.turn_off: status2
- platform: gpio
id: ${id3}
pin: GPIO10
name: ${name3}
icon: ${icon3}
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_on: status3
on_turn_off:
- light.turn_off: status3

binary_sensor:
- platform: gpio
internal: true
name: "${friendly_name} Button 1"
pin:
number: GPIO5
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: ${id1}
- platform: gpio
internal: true
name: "${friendly_name} Button 2"
pin:
number: GPIO3
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: ${id2}
- platform: gpio
internal: true
name: "${friendly_name} Button 3"
pin:
number: GPIO20
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: ${id3}
22 changes: 3 additions & 19 deletions template/linkind-switch.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
# Special odditiy that runs a weird, single-core ESP32 chip but still has BLE
# Special oddity that runs a weird, single-core ESP32 chip but still has BLE
substitutions:
project_name: "untergeek.linkind_switch"
project_version: "1.0.2"
project_version: "1.0.3"

<<: !include ../common.yaml
<<: !include ../restart_switch.yaml
<<: !include ../1core-ble-tracker.yaml

esp32:
board: esp32dev
Expand Down Expand Up @@ -71,20 +72,3 @@ binary_sensor:
internal: False
on_click:
- switch.turn_off: relay

esp32_ble_tracker:
scan_parameters:
# Adjust timing if the defaults do not work in your environment
# interval: 1100ms
# window: 1100ms
continuous: false

api:
on_client_connected:
- esp32_ble_tracker.start_scan:
continuous: true
on_client_disconnected:
- esp32_ble_tracker.stop_scan:

bluetooth_proxy:
active: true

0 comments on commit cff96de

Please sign in to comment.