Created
November 15, 2024 22:54
-
-
Save tkroo/f4f5d4a9fbe514d11455197934218b01 to your computer and use it in GitHub Desktop.
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
substitutions: | |
name: "mqttespbutton" | |
friendly_name: My Button 1 | |
esphome: | |
name: ${name} | |
friendly_name: ${friendly_name} | |
min_version: 2024.6.0 | |
name_add_mac_suffix: false | |
project: | |
name: esphome.web | |
version: dev | |
on_boot: | |
priority: -100 | |
then: | |
- logger.log: "Checking sleep" | |
- lambda: |- | |
if (id(my_button).state) { | |
ESP_LOGD("main", "Prevent sleep"); | |
id(deep_sleep_1).prevent_deep_sleep(); | |
id(defeat_sleep) = true; | |
} else { | |
ESP_LOGD("main", "Allow sleep"); | |
} | |
esp32: | |
board: esp32-c3-devkitm-1 | |
framework: | |
type: arduino | |
packages: | |
common: !include ../common/common.yaml | |
mqtt: | |
broker: homeassistant.local | |
port: 1883 | |
username: !secret mqtt_username | |
password: !secret mqtt_key | |
globals: | |
- id: defeat_sleep | |
type: bool | |
initial_value: "false" | |
switch: | |
- platform: template | |
restore_mode: RESTORE_DEFAULT_OFF | |
name: "Remote sleep defeat" | |
lambda: |- | |
return id(defeat_sleep); | |
turn_on_action: | |
- logger.log: "Press defeat" | |
- deep_sleep.prevent: deep_sleep_1 | |
- globals.set: | |
id: defeat_sleep | |
value: "true" | |
turn_off_action: | |
- logger.log: "Will be OK at next restart" | |
- globals.set: | |
id: defeat_sleep | |
value: "false" | |
deep_sleep: | |
run_duration: 30s | |
wakeup_pin: | |
number: 3 | |
inverted: true | |
mode: | |
input: true | |
pullup: true | |
allow_other_uses: true | |
id: deep_sleep_1 | |
button: | |
- platform: restart | |
name: "Remote restart" | |
- platform: template | |
name: "Button" | |
id: interface_button | |
on_press: | |
- mqtt.publish: | |
topic: "homeassistant/sensor/${name}/button" | |
payload: "1" | |
- platform: template | |
name: "Button2" | |
id: interface_button2 | |
on_press: | |
- mqtt.publish: | |
topic: "homeassistant/sensor/${name}/button" | |
payload: "2" | |
- platform: template | |
name: "ButtonDouble" | |
id: interface_button_double | |
on_press: | |
- mqtt.publish: | |
topic: "homeassistant/sensor/${name}/button" | |
payload: "1-double" | |
binary_sensor: | |
- platform: gpio | |
name: "My Button" | |
id: my_button | |
pin: | |
number: 3 | |
inverted: true | |
mode: | |
input: true | |
pullup: true | |
allow_other_uses: true | |
on_multi_click: | |
- timing: | |
- ON for at most 250ms | |
- OFF for at most 250ms | |
- ON for at most 250ms | |
- OFF for at least 100ms | |
then: | |
- button.press: interface_button_double | |
- timing: | |
- ON for 50ms to 1000ms | |
- OFF for at least 100ms | |
then: | |
- button.press: interface_button | |
- platform: gpio | |
name: "Button2" | |
id: my_button2 | |
pin: | |
number: 4 | |
inverted: true | |
mode: | |
input: true | |
pullup: true | |
on_click: | |
min_length: 50ms | |
max_length: 1s | |
then: | |
- button.press: interface_button2 | |
sensor: | |
- platform: template | |
name: "Wakeup Cause" | |
accuracy_decimals: 0 | |
lambda: return esp_sleep_get_wakeup_cause(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment