--- disqus: ahb0222 GA : G-VF9ZT413CG --- > [color=#40f1ef][name=LHB阿好伯, 2021/07/16][:earth_africa:](https://www.facebook.com/LHB0222/) [TOC] Sonoff S31是一款智能插座,可以通過刷入ESPHome固件來連接到Home Assistant 刷入ESPHome固件後,Sonoff S31可以通過Wi-Fi連接到你的家庭網絡 可以通過Home Assistant來控制插座的開關,並且監測插座的用電情況 ![](https://hackmd.io/_uploads/Hy1hXQzo3.jpg) ![](https://hackmd.io/_uploads/r1pFLQfin.png) ![](https://hackmd.io/_uploads/SJSq8Xzsn.png) # ESPHome設定 ## 拆解Sonoff S31 :::danger 警示:在進行任何拆解操作之前,請確保你已經斷開了所有電源,並且具有相應的專業知識和技能。 拆解電子設備可能會導致電擊、火災或其他傷害。 如果你不確定如何安全地拆解設備,請尋求專業人士的幫助。 同時,請注意拆解設備可能會使其保修失效,並且可能違反當地法律或規定。 在進行任何拆解操作之前,請仔細考慮風險並遵守相關法律和規定。 本文章只作為紀錄請勿輕易模仿 ::: ### 拆除頂板 ![](https://hackmd.io/_uploads/H1HcXmfon.jpg) ![](https://hackmd.io/_uploads/r1I9mXGoh.jpg) ### 解開螺絲 ![](https://hackmd.io/_uploads/ByUq77fin.jpg) #### 內部構造 ![](https://hackmd.io/_uploads/SJfc77zi2.jpg) ![](https://hackmd.io/_uploads/ry5nHmfj2.png) ### 燒錄 使用燒錄器或是焊接杜邦線進行燒錄 ![](https://hackmd.io/_uploads/SJk0X7fjn.jpg) :::success 按住GPIO0後再插入電腦進入燒錄模式 ::: ![](https://hackmd.io/_uploads/rkeUpLmMi3.png) ## HA新增裝置 在HA中新增裝置開啟ESPHome網頁 ![](https://hackmd.io/_uploads/Skl01Xzi3.png) 連接S31通訊埠 ![](https://hackmd.io/_uploads/HyIDvGGoh.png) ![](https://hackmd.io/_uploads/Skb9Dzzin.png) 進行燒錄 ![](https://hackmd.io/_uploads/HkUnwzGjh.png) ![](https://hackmd.io/_uploads/r1p6wMMs2.png) ![](https://hackmd.io/_uploads/BJCQ_fzs2.png) ### wifi無法設定 目前我個人遇到wifi設定問題 ![](https://hackmd.io/_uploads/SJpBdfGi2.png) 最後只好手動設定回到HA創建裝置 ![](https://hackmd.io/_uploads/Hk0dOMGsh.png) 設定名稱 ![](https://hackmd.io/_uploads/rkD5uMfj3.png) 設定裝置類型 這邊可以看到Pi pico W選項有空再來試試看 ![](https://hackmd.io/_uploads/HJ-jdfGi3.png) 這邊會生成一組API Key不用記之後都可以查 ![](https://hackmd.io/_uploads/r19aOffo3.png) 完成後就可以看到剛剛新增的裝置 ![](https://hackmd.io/_uploads/ryEyFMfjn.png) 這邊我們手動編輯其配置檔(yaml) ![](https://hackmd.io/_uploads/HkQzKGMs3.png) :::info 注意API key為自動填入勿修改 ::: ```yaml= substitutions: device_name: sonoff_s31f #測電流(備用) esphome: name: ${device_name} platform: ESP8266 board: esp01_1m api: encryption: key: "******************************" ##自動填入勿修改 ota: password: !secret wifi_pw web_server: port: 80 wifi: ssid: !secret wifi_ssid password: !secret wifi_pw ap: ssid: "${device_name}_Fallback" password: 12345678 #設定Wifi的密碼 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 ``` [yaml來源](https://forum.justplus.com.tw/forum.php?mod=viewthread&tid=113&_dsign=16441b6e) ## USB安裝 ![](https://hackmd.io/_uploads/B1JpcGfs2.png) ![](https://hackmd.io/_uploads/r1lCqfMon.png) 下載安裝檔 ![](https://hackmd.io/_uploads/H1I5oMMo3.png) ![](https://hackmd.io/_uploads/BJ16oMzih.png) ![](https://hackmd.io/_uploads/SklCoGfsh.png) ![](https://hackmd.io/_uploads/BkBuTGfo3.png) 通電 ![](https://hackmd.io/_uploads/HJKpmXfs2.jpg) 第一次使用須設定wifi 等待數秒鐘後用手機連接S31的Wifi ![](https://hackmd.io/_uploads/Bkq02mfsn.jpg) 進入1923.168.4.1設定Wifi ![](https://hackmd.io/_uploads/Hk7FRQMj3.png) 若是連接成功就可以看到HA上搜尋到S31 並可以查看S31相關訊息 ![](https://hackmd.io/_uploads/SyRu6Gfsn.png) ![](https://hackmd.io/_uploads/HyljK6fGon.png) ![](https://hackmd.io/_uploads/SJd2pMfj3.png) # 討論 ## daily energy更新問題 ![image](https://hackmd.io/_uploads/HkuOE2YzJl.png) 全文分享至 🌟全文可以至下方連結觀看或是補充 https://www.facebook.com/LHB0222/ https://www.instagram.com/ahb0222/ 有疑問想討論的都歡迎於下方留言 喜歡的幫我分享給所有的朋友 \o/ 有所錯誤歡迎指教 # [:page_with_curl: 全部文章列表](https://hackmd.io/@LHB-0222/AllWritings) ![](https://i.imgur.com/nHEcVmm.jpg)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up