tags: ESPHOME

ESPHome 入門

安裝

  • 首先要先安裝 Home Assistant (HA),而且不能是 Container版本。
    比較理想是用樹莓派或是VM。
  • HA裡必須要有Supervisor的功能
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 附加元件商店 裡安裝 ESPHOME
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • ESPHOME 安裝後如下
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

初次使用

  • 開啟WEB UI
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 按下「+」新增一個設備 (下圖中我已經新增了兩個設備)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 輸入設備名稱,WIFI SSID 與 PASSWORD
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選板子 (目前我都是用8266)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 已經新增了一個設備(my-device-name),接著按下edit
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 這裡就是寫程式的地方了
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

第一次燒錄

  • 不急著編寫程式,先上傳一次看看
  • ESPHOME的玩法與Arduino差很多,ESPHOME會線上編譯好程式,接著透過OTA的方式,無線上傳到開發板
  • 不過第一次沒辦法OTA,必須在線上編譯後,下載bin檔案,然後使用esphome-flasher上傳。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 如果有上傳成功,WIFI SSID/PASSWORD 沒有打錯,連線成功會顯示 ONLINE
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 看到 ONLINE 就可以開始寫程式了!

編寫 YAML

  • 玩這套(ESPHOME)東西,其實不需要寫程式,只需要編寫設定檔
  • YAML 是類似 JSON/XML 的資料格式
  • 詳細編寫的方式請看官方網站,以下列幾個範例
  • 指令設備名稱與板子
esphome: name: my-device-name platform: ESP8266 board: nodemcuv2
  • 將 D0 當作一個 digital input
binary_sensor: - platform: gpio name: "my-digital-sensor" pin: D0
  • 將 D6 當作一個 digital output
switch: - platform: gpio name: "my-relay" pin: D6
  • 以上合起來的完整範例
esphome: name: my-device-name platform: ESP8266 board: nodemcuv2 binary_sensor: - platform: gpio name: "my-digital-sensor" pin: D0 switch: - platform: gpio name: "my-relay" pin: D6 # Enable logging logger: # Enable Home Assistant API api: ota: password: "fbfbc594a285001b93364f775cdbf7da" wifi: ssid: "WIFI-SSID" password: "123456789" # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "My-Device-Name Fallback Hotspot" password: "gQ8NLQDq872C" captive_portal:
  • 上傳後,HA 將會發現新設備,然後就可以主面板裡
    • 新增一個小面板,顯示 D0 是 ON/OFF
    • 新增一個按鈕,可用操作 D6,然後 D6 可以接上你需要的元件,例如 Relay

其他

  • 在mac環境esphome-flasher UI有點問題,好像必須要用指令
cd /applications/esphome-flasher.app/contents/macos chmod +x ESPHome-Flasher.app/Contents/MacOS/ESPHome-Flasher ./ESPHome-Flasher -p /dev/cu.usbserial-0001 ~/Desktop/light-433-8266.bin