Last active
June 19, 2025 03:27
-
-
Save lanefu/6a2bf8b3ed4ecd9650c2c0a94421a7f0 to your computer and use it in GitHub Desktop.
ESPHome multimode rotary encoder button
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: | |
name: magicbuttonboard | |
platform: ESP8266 | |
board: d1_mini | |
on_boot: | |
priority: -100 | |
then: | |
- lambda: id(magic_button_board_selection_mode).publish_state(false); | |
- lambda: id(magic_button_board_button_click).publish_state(false); | |
wifi: | |
ssid: "" | |
password: "" | |
# domain only needed if you prefer to use your own DNS instead of mdns with .local | |
# domain: ".internal.example.com" | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "Magicbuttonboard" | |
password: "cEcsAJKdHccP" | |
captive_portal: | |
# Enable logging | |
logger: | |
level: debug | |
# Enable Home Assistant API | |
api: | |
ota: | |
sensor: | |
- platform: rotary_encoder | |
name: "Rotary Encoder" | |
pin_a: D7 | |
pin_b: D2 | |
min_value: 0 | |
max_value: 100 | |
resolution: 2 | |
filters: | |
- delta: 4.0 | |
id: magic_button_board_dial | |
#- platform: dht | |
# pin: D4 | |
# model: DHT22 | |
# temperature: | |
# name: "Magic Button Board Temperature" | |
# humidity: | |
# name: "Board Button Board Humidity" | |
# update_interval: 30s | |
binary_sensor: | |
- platform: template | |
name: "Selection Mode Active" | |
id: magic_button_board_selection_mode | |
lambda: return {}; | |
- platform: template | |
name: "Button Click" | |
id: magic_button_board_button_click | |
lambda: return {}; | |
- platform: gpio | |
pin: | |
number: D5 | |
mode: INPUT_PULLUP | |
inverted: true | |
name: "Rotary Button" | |
id: magic_button_board_button | |
on_multi_click: | |
- timing: | |
- ON for at most 1s | |
- OFF for at most 1s | |
- ON for at most 1s | |
- OFF for at least 0.2s | |
then: | |
- logger.log: "Double Clicked" | |
- if: | |
condition: | |
binary_sensor.is_off: magic_button_board_selection_mode | |
then: | |
- lambda: id(magic_button_board_selection_mode).publish_state(true); | |
- light.turn_on: | |
id: magic_button_board_indicator | |
brightness: 30% | |
red: 100% | |
green: 0% | |
blue: 0% | |
else: | |
- lambda: id(magic_button_board_selection_mode).publish_state(false); | |
- light.turn_off: | |
id: magic_button_board_indicator | |
- timing: | |
- ON for at most 1s | |
- OFF for at least 0.5s | |
then: | |
- logger.log: "Single short Clicked" | |
- lambda: id(magic_button_board_button_click).publish_state(true); | |
- delay: 2s | |
- lambda: id(magic_button_board_button_click).publish_state(false); | |
light: | |
- platform: fastled_clockless | |
chipset: neopixel | |
pin: D1 | |
num_leds: 1 | |
name: "indicator" | |
id: magic_button_board_indicator |
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
- id: '1589733347689' | |
alias: living room lights dim | |
description: '' | |
trigger: | |
- entity_id: sensor.magic_button_board_dial | |
platform: state | |
condition: | |
- condition: state | |
entity_id: binary_sensor.selection_mode_active | |
state: 'on' | |
action: | |
- data_template: | |
brightness_pct: '{{states.sensor.magic_button_board_dial.state | int }}' | |
entity_id: group.living_room_overhead | |
service: light.turn_on | |
- id: '1589737175591' | |
alias: Toggle Lights Living Room Overhead | |
description: '' | |
trigger: | |
- device_id: ecbd2595fbd0410697b64518a1441e73 | |
domain: binary_sensor | |
entity_id: binary_sensor.button_click | |
platform: device | |
type: turned_on | |
condition: | |
- condition: state | |
entity_id: binary_sensor.selection_mode_active | |
state: 'on' | |
action: | |
- data: {} | |
entity_id: group.living_room_overhead | |
service: light.toggle | |
- id: '1589737175592' | |
alias: Toggle Lights Living Room Endtables | |
description: '' | |
trigger: | |
- device_id: ecbd2595fbd0410697b64518a1441e73 | |
domain: binary_sensor | |
entity_id: binary_sensor.button_click | |
platform: device | |
type: turned_on | |
condition: | |
- condition: state | |
entity_id: binary_sensor.selection_mode_active | |
state: 'off' | |
action: | |
- data: {} | |
entity_id: group.living_room_end_tables | |
service: switch.toggle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment