前言: sonoff s31是我很喜歡的測電量電流插座,只要會淘寶,取得的成本不用台幣200塊,幾個步驟簡單刷機,不用花五百八百去買人家刷好的
工具: usb轉ttl模塊(參考購買地址)、小鱷魚夾(參考購買地址)、ESPHome-Flasher-1.4.0-Windows-x64.exe
yaml範例:
substitutions:
device_name: sonoff_s31 #測電流(備用)
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
api:
ota:
password: !secret wifi_pw
web_server:
port: 80
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pw
ap:
ssid: "${device_name}_Fallback"
password: !secret wifi_pw
captive_portal:
logger:
baud_rate: 0 # (UART logging interferes with cse7766)
time:
- platform: homeassistant
id: homeassistant_time
uart:
rx_pin: RX
baud_rate: 4800
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: "${device_name} Button"
on_press:
- switch.toggle: relay
- platform: status
name: "${device_name} Status"
sensor:
- platform: wifi_signal
name: "${device_name} WiFi Signal"
update_interval: 60s
- platform: uptime
name: "${device_name} Uptime"
filters:
- lambda: return x / 3600;
unit_of_measurement: "hours"
accuracy_decimals: 1
- platform: cse7766
update_interval: 1s
current:
name: "${device_name} Current"
accuracy_decimals: 2
unit_of_measurement: A
filters:
- sliding_window_moving_average:
window_size: 3
send_every: 2
voltage:
name: "${device_name} Voltage"
unit_of_measurement: V
accuracy_decimals: 1
power:
name: "${device_name} Wattage"
unit_of_measurement: W
accuracy_decimals: 1
id: "wattage"
- platform: total_daily_energy
name: "${device_name} Total Daily Energy"
power_id: "wattage"
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
switch:
- platform: gpio
name: "${device_name} Relay"
icon: mdi:power-socket-us
pin: GPIO12
id: relay
restore_mode: always_on
- platform: restart
name: "${device_name} Restart"
output:
- platform: esp8266_pwm
id: blueLED
pin: GPIO13
inverted: True
light:
- platform: monochromatic
name: "${device_name}_blueLED"
output: blueLED
id: ${device_name}_blueLED
interval:
- interval: 60s
then:
if:
condition:
wifi.connected:
then:
- light.turn_on:
id: ${device_name}_blueLED
else:
- light.turn_on:
id: ${device_name}_blueLED
flash_length : 1s
影片: 由於手機錄影拍螢幕畫面很糊,所以最後看著燒錄程式跑過程的畫面就省略了。
https://www.youtube.com/watch?v=5ggUrlfPF64
就那麼簡單,另一個簡單到一直不好意思分享的東西,打完收工。