esphome:
name: custom-switch
friendly_name: "插排"
name_add_mac_suffix: True
esp8266:
board: esp_wroom_02
restore_from_flash: True
logger:
level: INFO
baud_rate: 0
external_components:
- source: custom_compents
ota:
- platform: esphome
password: !secret ota_password
substitutions:
use_address: '192.168.31.97'
switch3_restore_mode: 'RESTORE_DEFAULT_OFF'
switch2_restore_mode: 'ALWAYS_ON'
switch1_restore_mode: 'ALWAYS_ON'
usb_restore_mode: 'ALWAYS_ON'
wifi:
use_address: '${use_address}'
# fast_connect: True
reboot_timeout: 0s
ap:
ssid: "switch"
captive_portal:
mqtt:
broker: !secret mqtt_broker
# client_id: 95f0853b212540f0ba1b3d4337bee7ec
username: !secret mqtt_user
password: !secret mqtt_password
discovery_unique_id_generator: mac
mdns:
disabled: True
button:
- platform: factory_reset
name: reset
id: "reset_factory_button"
- platform: restart
name: restart
id: "restart_chip"
switch:
- platform: gpio
id: "switch3"
pin:
number: GPIO13
name: "开关3"
restore_mode: '${switch3_restore_mode}'
- platform: gpio
id: "switch2"
pin:
number: GPIO12
name: "开关2"
restore_mode: '${switch2_restore_mode}'
- platform: gpio
id: "switch1"
pin:
number: GPIO14
name: "开关1"
restore_mode: '${switch1_restore_mode}'
- platform: gpio
id: "usb"
pin:
number: GPIO15
name: "USB Switch"
icon: "mdi:usb"
restore_mode: '${usb_restore_mode}'
- platform: template
id: "all_switch"
name: "总开关"
lambda: |
return (id(switch1).state && id(switch2).state && id(switch3).state && id(usb).state);
turn_on_action:
then:
- switch.turn_on: switch1
- switch.turn_on: switch2
- switch.turn_on: switch3
- switch.turn_on: usb
turn_off_action:
then:
- switch.turn_off: switch1
- switch.turn_off: switch2
- switch.turn_off: switch3
- switch.turn_off: usb
output:
- platform: esp8266_pwm
pin:
number: GPIO4
inverted: True
frequency: 500 Hz
id: led_blue
status_led:
pin:
number: GPIO16
inverted: True
light:
- platform: monochromatic
output: led_blue
internal: True
id: "light_led_blue"
effects:
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
min_brightness: 0%
max_brightness: 100%
sensor:
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
binary_sensor:
- platform: gpio
id: "input"
pin:
number: GPIO5
inverted: True
on_press:
then:
- light.turn_on:
id: light_led_blue
effect: "Fast Pulse"
on_release:
then:
- light.turn_off: light_led_blue
name: "按钮"
internal: True
# on_click:
# then:
# - switch.toggle: switch1
# on_double_click:
# then:
# - switch.toggle: switch2
on_multi_click:
- timing:
- ON for at least 20ms
- OFF for at least 500ms
then:
- switch.toggle: switch1
- timing:
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 500ms
then:
- switch.toggle: switch2
- timing:
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 500ms
then:
- switch.toggle: switch3
- timing:
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 50ms
- ON for 20ms to 200ms
- OFF for at least 500ms
then:
- switch.toggle: usb
- timing:
- ON for at least 1.5s
- OFF for at least 500ms
then:
- switch.toggle: all_switch
- timing:
- ON for at least 3s
- OFF for at least 500ms
then:
- button.press: restart_chip
- timing:
- ON for at least 5s
- OFF for at least 500ms
then:
- light.turn_on: light_led_blue
- button.press: reset_factory_button
text_sensor:
- platform: wifi_info
ip_address:
name: ESP IP Address
ssid:
name: ESP Connected SSID
bssid:
name: ESP Connected BSSID
mac_address:
name: ESP Mac Wifi Address
dns_address:
name: ESP DNS Address