闲来无事,
在B站看到有UP主说有个智能排插用的是ESP8266芯片做的
可以拆开,用ESPhome线刷成自己定义的固件,
电能功率计用的是BL0937,可以实时检测电流电压,但感觉不太准。
实物图如下
拆解刷机没有记录下来就不写了,直接上原代码
substitutions:
device_name: s3switch05
button_pin: GPIO13 #按钮
relay_pin: GPIO5 #继电器
led_r_pin: GPIO4 #白色led
led_w_pin: GPIO16 #------红色led
alarm_pin1: GPIO12 #零火检测 ###零线地线之间是否有电压
alarm_pin2: GPIO14 #缺地检测##地线和火线之间是否有电压
hlw8012_sel_pin: GPIO2
hlw8012_sf_pin: GPIO9
hlw8012_sf1_pin: GPIO10
esphome:
name: s3switch05
friendly_name: S3SWITCH05
on_boot:
then:
- delay: 3s
- switch.turn_on: "relay1"
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "FPoefBYLYls4gxpYtEuXVtbbcM8oGvZTU93WRwNBEX4="
reboot_timeout: 0s
ota:
password: "0c17bfc95c167e23cf6555a8a38d3863"
captive_portal:
wifi:
ssid: wushi-2.4
password: ++0123--
manual_ip:
static_ip: 192.168.1.117 ##固定此设备IP地址为192.168.1.100;
gateway: 192.168.1.1 ##路由器、网关地址;
subnet: 255.255.255.0 ##子网掩码;
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name}_Fallback Hotspot"
password: "Ioi78VkYZ5vh"
status_led:
pin:
number: $led_w_pin
inverted: true
globals:
- id: auto_gl
type: int
restore_value: yes
initial_value: "1"
- id: flag_closealarm
type: int
initial_value: "1"
restore_value: yes
output:
- id: light_output
platform: gpio
pin:
number: $led_r_pin
inverted: true
light:
- platform: binary
output: light_output
name: "${device_name}_r_led"
id: "r_led"
internal: true
binary_sensor:
- platform: gpio
pin:
number: $button_pin
inverted: true
mode:
input: true
pullup: true
name: "${device_name}_B1"
on_click:
- min_length: 50ms
max_length: 1000ms
then:
- if:
condition:
lambda: 'return id(Lock1).state ;'
then:
- switch.toggle: "relay1"
- min_length: 3000ms
max_length: 20000ms
then:
- switch.toggle: 'Lock1'
- platform: gpio
pin:
number: $alarm_pin2
inverted: false
mode:
input: true
name: "${device_name}_lostGnd"
id: lostGnd
filters:
- delayed_on: 100ms
- platform: gpio
pin:
number: $alarm_pin1
inverted: true
mode:
input: true
filters:
- delayed_on: 100ms
name: "${device_name}_LNInversion"
id: LNInversion
sensor:
- platform: wifi_signal
name: "${device_name}_RSSI"
update_interval: 60s
- platform: hlw8012
model: BL0937
sel_pin:
number: $hlw8012_sel_pin
inverted: true
cf_pin: $hlw8012_sf_pin
cf1_pin: $hlw8012_sf1_pin
current:
name: "${device_name}_Current"
voltage:
name: "${device_name}_Voltage"
power:
name: "${device_name}_Power"
energy:
name: "${device_name}_Energy"
initial_mode: CURRENT
update_interval: 30s
voltage_divider: 1651
current_resistor: 0.001
text_sensor:
- platform: wifi_info
ip_address:
name: '${device_name}_IP'
mac_address:
name: '${device_name}_MAC'
button:
- platform: factory_reset
name: "${device_name}_Reset"
- platform: restart
name: "${device_name}_Restart"
- platform: safe_mode
name: "${device_name}_SafeMode"
switch:
- platform: gpio #继电器
pin: $relay_pin
name: "${device_name}_relay"
id: "relay1"
- platform: template
name: "${device_name}_CloseAlarm"
id: "CloseAlarm"
turn_on_action:
then:
- lambda: |-
id(flag_closealarm)=1;
turn_off_action:
then:
- lambda: |-
id(flag_closealarm)=0;
lambda: |-
return id(flag_closealarm);
- platform: template
name: "${device_name}_Lock"
id: "Lock1"
turn_on_action:
then:
- lambda: |-
id(auto_gl)=1;
turn_off_action:
then:
- lambda: |-
id(auto_gl)=0;
lambda: |-
return id(auto_gl);
interval:
- interval: 1000ms
then:
lambda: |-
if ( (id(LNInversion).state or id(lostGnd).state) and id(flag_closealarm) ) {
auto call =id(r_led).toggle();
call.perform();
} else{
auto call =id(r_led).turn_off();
call.perform();
}
通电3秒继电器自动接通
按着开关50毫秒到1秒算短按,在没有锁止的状态下,可以切换继电器通断
按着开关3秒到20秒算长按,长按切换锁止状态