本帖最后由 ciasdmxhxjjpd@c 于 2022-6-26 22:58 编辑
已经解决了
button gpio 为 gpio0
缺少 interval:
还有部分问题:
1. ota更新提示失败,多试几次
esphome:
name: smart-plug
platformio_options:
platform_packages:
- framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
on_loop:
- lambda: |
vTaskDelay(10/portTICK_PERIOD_MS);
on_boot:
then:
- switch.turn_off: switch_plug
- delay: 3s
- switch.turn_on: switch_plug
esp32:
board: esp32dev
# Enable logging
logger:
# level: VERY_VERBOSE
web_server:
port: 80
auth:
username: admin
password: !secret web_password
api:
password: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.100
gateway: 192.168.1.1
subnet: 255.255.255.0
dns1: 192.168.1.1
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "SmartPlug Fallback Hotspot"
password: !secret wifi_password
captive_portal:
# add
globals: #示例,配合实现切换灯状态 可删除
# idle 1, wifi connected 2, reboot 3
- id: var_light_status
type: int
restore_value: no
initial_value: '0'
script: #示例,配合实现切换灯状态 可删除
- id: script_led_idle
mode: single
then:
- if:
condition:
lambda: "return (id(var_light_status) != 1) && (id(var_light_status) != 3);"
then:
- globals.set:
id: var_light_status
value: '1'
- light.turn_off:
id: light_blue
transition_length: 0s
- light.turn_on:
id: light_yellow
transition_length: 0s
- id: script_led_connected
mode: single
then:
- if:
condition:
lambda: "return (id(var_light_status) != 2) && (id(var_light_status) != 3);"
then:
- globals.set:
id: var_light_status
value: '2'
- light.turn_off:
id: light_yellow
transition_length: 0s
- light.turn_on:
id: light_blue
brightness: 50%
transition_length: 0s
- id: script_led_reboot
mode: single
then:
- globals.set:
id: var_light_status
value: '3'
- light.turn_off:
id: light_blue
transition_length: 0s
- light.turn_on:
id: light_yellow
effect: "fast flash"
light:
- platform: monochromatic
id: "light_blue"
name: "Light Blue"
output: output_blue
restore_mode: ALWAYS_OFF
- platform: monochromatic
id: "light_yellow"
output: output_yellow
restore_mode: ALWAYS_OFF
effects:
- pulse:
name: "fast flash"
transition_length: 0s
update_interval: 100ms
output: #黄、蓝指示灯引脚
- id: output_blue
platform: ledc
pin: GPIO18
inverted: True
- id: output_yellow
platform: ledc
pin: GPIO23
inverted: True
switch: #继电器引脚
- platform: gpio
name: "SmartPlug Switcher"
id: "switch_plug"
pin:
number: GPIO27
on_turn_on:
then:
- switch.toggle: switch_lock
on_turn_off:
then:
- switch.toggle: switch_lock
- platform: gpio
id: "switch_lock"
pin: GPIO26
sensor: #功率计引脚
- platform: hlw8012
current_resistor: 0.005
voltage_divider: 766 #影响220v电压测量结果,自行校准
sel_pin:
number: GPIO5
inverted: True
cf_pin: GPIO21
cf1_pin: GPIO22
current:
name: "HLW8012 Current"
unit_of_measurement: A
voltage:
name: "HLW8012 Voltage"
unit_of_measurement: V
power:
name: "HLW8012 Power"
unit_of_measurement: W
energy:
name: "HLW8012 Energy"
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 3
change_mode_every: 1
update_interval: 30s
- platform: template
lambda: return temperatureRead();
name: "HLW8012 Temperature"
unit_of_measurement: "°C"
update_interval: 300s
# xiaomi temperature meter with custom firmware,https://github.com/atc1441/ATC_MiThermometer
# in https://atc1441.github.io/TelinkFlasher.html
# after flush custom fireware, set Advertising Type: Mi Like
# and click 'Save current settings in flash' button
# replace BLE MAC address
- platform: xiaomi_lywsd03mmc
mac_address: "A4:C1:38:xx:xx:xx"
bindkey: "47CF9F14B8CE5C668DE3C6799B008D28"
temperature:
name: "Room LYWSD03MMC Temperature"
humidity:
name: "Room LYWSD03MMC Humidity"
battery_level:
name: "Room LYWSD03MMC Battery Level"
- platform: xiaomi_lywsd03mmc
mac_address: "A4:C1:38:xx:xx:xx"
bindkey: "47CF9F14B8CE5C668DE3C6799B008D28"
temperature:
name: "Outdoor LYWSD03MMC Temperature"
humidity:
name: "Outdoor LYWSD03MMC Humidity"
battery_level:
name: "Outdoor LYWSD03MMC Battery Level"
binary_sensor:
- platform: gpio #按钮相关引脚
pin:
number: GPIO0
mode: INPUT
name: "SmartPlug Button"
filters:
- invert:
- delayed_on_off: 100ms
on_click: #示例,单击开关继电器
min_length: 50ms
max_length: 350ms
then:
- switch.toggle: switch_plug
on_multi_click: #示例,长按3秒重启插座
- timing:
- ON for at least 3s
then:
- script.execute: script_led_reboot
- timing:
- ON for at least 3s
- OFF for at least 0.3s
then:
- lambda: |
App.reboot();
interval:
- interval: 3s #示例,根据wifi连接情况改变灯色,可删除
then:
- if:
condition:
wifi.connected
then:
- script.execute: script_led_connected
else:
- script.execute: script_led_idle
# BLE
esp32_ble_tracker:
|