├── .github └── FUNDING.yml ├── docs ├── images │ ├── banner.png │ ├── Tasmota Home.png │ ├── ESPHome Setup.png │ ├── Tasmota FW Upgrade.png │ ├── Tasmota FW Upgrade Successful.png │ └── ESPHome Configuration Created Dialog.png ├── CHANGELOG-ja.md └── README-ja.md ├── CHANGELOG.md ├── switchbot-plug-mini-w2001401-ja.yaml ├── switchbot-plug-mini-w2001401-homekit-enabled-ja.yaml ├── switchbot-plug-mini-w2001401.yaml ├── switchbot-plug-mini-w2001401-homekit-enabled.yaml ├── README.md └── LICENSE /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | buy_me_a_coffee: i_am_taikun 2 | -------------------------------------------------------------------------------- /docs/images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/banner.png -------------------------------------------------------------------------------- /docs/images/Tasmota Home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/Tasmota Home.png -------------------------------------------------------------------------------- /docs/images/ESPHome Setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/ESPHome Setup.png -------------------------------------------------------------------------------- /docs/images/Tasmota FW Upgrade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/Tasmota FW Upgrade.png -------------------------------------------------------------------------------- /docs/images/Tasmota FW Upgrade Successful.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/Tasmota FW Upgrade Successful.png -------------------------------------------------------------------------------- /docs/images/ESPHome Configuration Created Dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/HEAD/docs/images/ESPHome Configuration Created Dialog.png -------------------------------------------------------------------------------- /docs/CHANGELOG-ja.md: -------------------------------------------------------------------------------- 1 | # SwitchBot プラグミニ for ESPHome 変更ログ 2 | [English](/CHANGELOG.md) | **日本語** 3 | 4 | ## 1.2.0 5 | - `LED Brightness`(LEDの明るさ)の`オフ`(または`Off`)オプション名を`LEDオフ`(または`LED Off`)に変更 6 | - **これは破壊的変更です。**\ 7 | `オフ`(または`Off`)を検出したり、切り替えたりするオートメーションを使用している場合、ファームウェアの更新に合わせてオートメーションも`LEDオフ`(または`LED Off`)に変更する必要があります。 8 | - この変更によって、初回インストール後にESPHomeで完全な制御を得た時、バリデーションが通らない問題([**#4**](https://github.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/issues/4))が修正される可能性があります。 9 | 10 | ## 1.1.1 11 | - HomeKitファームウェアからESP32のフレームワークバージョンとプラットフォームバージョンの指定を削除 12 | 13 | このバージョンは機能に変更はなく、最新バージョンのESPHome(2025.10.2)でビルドできることを確認するためのメンテナンスビルドです。\ 14 | すでにESPHomeでSwitchBot プラグミニをお使いの方は更新する必要はありません。 15 | 16 | ## 1.1.0 17 | - `Total Monthly Energy`(一ヵ月の累計消費電力量)センサーを追加 18 | - このセンサーは、毎月1日の午前0時にリセットされます。 19 | 20 | ## 1.0.1 21 | - `Power`(電力)センサーの`accuracy_decimals`(小数点以下の数)を`1`に減少 22 | - 電力モニタリングセンサーの`update_interval`を`5s`に増加 23 | - これにより、`Power`(電力)センサーの精度が向上します。 24 | - `Apparent Power`(皮相電力)センサーの`update_interval`を`20s`に増加 25 | - `Power Factor`(力率)センサーの`update_interval`を`20s`に増加 26 | 27 | ## 1.0.0 28 | - 最初のリリース 29 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # SwitchBot Plug Mini for ESPHome Changelog 2 | **English** | [日本語](docs/CHANGELOG-ja.md) 3 | 4 | ## 1.2.0 5 | - Change the `Off` (or `オフ`) option name for `LED Brightness` to `LED Off` (or `LEDオフ`) 6 | - **This is a breaking change.**\ 7 | If you have automations detecting or toggling `Off` (or `オフ`), you will need to update them to `LED Off` (or `LEDオフ`) when updating the firmware. 8 | - This change may resolve an issue ([**#4**](https://github.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/issues/4)) where validation failed when taking control in ESPHome after initial installation. 9 | 10 | ## 1.1.1 11 | - Removes specification of ESP32 framework version and platform version from HomeKit firmware 12 | 13 | This version contains no functional changes and is a maintenance build to confirm compatibility with the latest ESPHome version (2025.10.2).\ 14 | Users already using SwitchBot Plug Mini with ESPHome do not need to update. 15 | 16 | ## 1.1.0 17 | - Add `Total Monthly Energy` sensor 18 | - This sensor resets at 0 am on the first day of every month. 19 | 20 | ## 1.0.1 21 | - Reduced `accuracy_decimals` (Number of decimal points) for `Power` sensor to `1` 22 | - Increased `update_interval` for power monitoring sensor to `5s` 23 | - This improves the accuracy for `Power` sensor. 24 | - Increased `update_interval` for `Apparent Power` sensor to `20s` 25 | - Increased `update_interval` for `Power Factor` sensor to `20s` 26 | 27 | ## 1.0.0 28 | - First release 29 | -------------------------------------------------------------------------------- /switchbot-plug-mini-w2001401-ja.yaml: -------------------------------------------------------------------------------- 1 | # SwitchBot プラグミニ (JP) for ESPHome by taikun114 2 | 3 | substitutions: 4 | device_name: switchbot-plug-mini 5 | friendly_name: SwitchBot Plug Mini 6 | fw_version: 1.2.0 7 | 8 | # モデル番号 9 | model: "W2001401" 10 | 11 | # キャリブレーションデータ 12 | voltage_divider: "660.7973855893309" 13 | current_resistor: "0.0024013086148925913" 14 | current_multiply: "1.783420806116323" 15 | # キャリブレーションを行う際、電力メーターに表示される値からプラグミニ自体の消費電力(リレーをオンにした状態で約0.8W / 0.019A)を 16 | # 引いた値を使ってキャリブレーションを行ってください。 17 | # 18 | # キャリブレーションの方法については、以下のドキュメントをご覧ください。 19 | # https://esphome.io/components/sensor/hlw8012#calibration 20 | 21 | # ESPHomeに関する設定 22 | esphome: 23 | name: ${device_name} 24 | comment: 電力モニタリングスマートフラグ(${model}) 25 | friendly_name: ${friendly_name} 26 | name_add_mac_suffix: true 27 | platformio_options: 28 | board_build.flash_mode: dio 29 | project: 30 | name: SwitchBot (Customized by taikun114).Plug Mini JP (${model}) 31 | version: ${fw_version} 32 | 33 | # ESP32に関する設定 34 | esp32: 35 | board: esp32-c3-devkitm-1 36 | variant: ESP32C3 37 | framework: 38 | type: esp-idf 39 | 40 | # この設定ファイルをローカルに読み込むための設定 41 | dashboard_import: 42 | package_import_url: github://taikun114/SwitchBot-Plug-Mini-for-ESPHome/switchbot-plug-mini-w2001401-ja.yaml@v1.2.0 43 | import_full_config: true 44 | 45 | # ログを表示するための設定 46 | logger: 47 | 48 | # APIに関する設定 49 | api: 50 | 51 | # OTA(Over-The-Air)アップデートに関する設定 52 | ota: 53 | - platform: esphome 54 | 55 | # Wi-Fiネットワークに関する設定 56 | wifi: 57 | # プラグミニが接続するWi-Fiネットワークの設定 58 | # ssid: !secret wifi_ssid 59 | # password: !secret wifi_password 60 | 61 | # 一定の期間(デフォルトでは1分)Wi-Fiネットワークに接続できなかった場合に 62 | # 有効になるフォールバックホットスポット(アクセスポイントモード)の設定 63 | ap: 64 | # password: !secret ap_password # コメントを外して、パスワードを設定することをおすすめします。 65 | 66 | # Wi-Fiネットワークから切断されている時に、青色LEDを点滅させる 67 | on_connect: # Wi-Fiネットワークに接続された時 68 | - light.turn_off: blue_led 69 | on_disconnect: # Wi-Fiネットワークから切断された時 70 | - while: 71 | condition: 72 | not: 73 | wifi.connected: 74 | then: 75 | - light.turn_on: 76 | id: blue_led 77 | brightness: 100% 78 | - delay: 500ms 79 | - light.turn_off: blue_led 80 | - delay: 500ms 81 | 82 | # フォールバックホットスポットに接続したときに、プラグミニのWi-Fi設定の変更や 83 | # ファームウェアの更新を行えるようにするキャプティブポータルの設定 84 | captive_portal: 85 | 86 | # Bluetooth LEを使ってWi-Fiをセットアップできるようにする設定 87 | # 注意: このコンポーネントを使用していると内部温度が上昇するため、 88 | # このコンポーネントを無効化(コメントアウト)し、フォールバックホットスポットからWi-Fiを設定することをおすすめします。 89 | esp32_improv: 90 | authorizer: none 91 | 92 | # 時間に関する設定 93 | time: 94 | # API接続を通して、Home Assistantと時間を同期する 95 | - platform: homeassistant 96 | id: homeassistant_time 97 | 98 | on_time: # 特定の時間になった時 99 | # 毎月1日午前0時に、一ヵ月の累計消費電力量センサーをリセットする 100 | - seconds: 0 101 | minutes: 0 102 | hours: 0 103 | days_of_month: 1 104 | then: 105 | - sensor.integration.reset: total_monthly_energy 106 | 107 | # ボタンに関する設定 108 | button: 109 | # プラグミニを再起動する 110 | - platform: restart 111 | name: Reboot 112 | id: reboot 113 | 114 | # バイナリセンサーに関する設定 115 | binary_sensor: 116 | # プラグミニ本体のボタンが押されたことを検知 117 | - platform: gpio 118 | id: power_button 119 | pin: 120 | number: GPIO02 121 | inverted: true 122 | internal: true 123 | 124 | on_click: # ボタンを押したとき 125 | # ボタンを押してすぐ離した時にリレースイッチを切り替える 126 | - min_length: 50ms 127 | max_length: 500ms 128 | then: 129 | - switch.toggle: relay 130 | 131 | # ボタンを3秒以上10秒以下の範囲で長押しした時にプラグミニを再起動する 132 | - min_length: 3s 133 | max_length: 10s 134 | then: 135 | - button.press: reboot 136 | 137 | # センサーに関する設定 138 | sensor: 139 | # Wi-Fiアクセスポイントへの接続強度 140 | - platform: wifi_signal 141 | name: Wi-Fi Signal 142 | update_interval: 30s 143 | 144 | # 最後に電源を入れた時刻 145 | - platform: uptime 146 | type: timestamp 147 | name: Uptime 148 | 149 | # プラグミニの内部温度 150 | - platform: internal_temperature 151 | name: Internal Temperature 152 | update_interval: 30s 153 | 154 | # 電力モニタリングセンサー 155 | - platform: hlw8012 156 | sel_pin: 157 | number: GPIO20 158 | inverted: true 159 | cf_pin: GPIO18 160 | cf1_pin: GPIO19 161 | current_resistor: ${current_resistor} 162 | voltage_divider: ${voltage_divider} 163 | power: # 電力 164 | name: Power 165 | unit_of_measurement: W 166 | id: wattage 167 | accuracy_decimals: 1 # 小数点以下の数 168 | current: # 電流 169 | name: Current 170 | unit_of_measurement: A 171 | id: current 172 | filters: 173 | - multiply: ${current_multiply} 174 | voltage: # 電圧 175 | name: Voltage 176 | unit_of_measurement: V 177 | id: voltage 178 | accuracy_decimals: 2 # 小数点以下の数 179 | initial_mode: VOLTAGE # 初期の測定モード。電圧(VOLTAGE)または電流(CURRENT) 180 | change_mode_every: 1 # 電流と電圧の測定モードを切り替えるまでの測定回数(切り替え後、初回の値は破棄されるため、設定値 + 1回測定されます) 181 | update_interval: 5s # センサーの更新間隔 182 | # センサーの更新間隔について 183 | # 184 | # 電力センサーの更新間隔は update_interval で設定した間隔で更新されます。 185 | # 電流センサーと電圧センサーの更新間隔は change_mode_every の設定値によって異なります。 186 | # 187 | # change_mode_every: 1 以上の場合: 188 | # (change_mode_everyの設定値 + 1) * 2 * update_intervalの設定値(秒換算) ごとに更新 189 | # 例えば change_mode_every: 1 で update_interval: 1s の場合、(1 + 1) * 2 * 1s = 4秒ごとに更新されることになります。 190 | # 191 | # change_mode_every: "never" の場合: 192 | # initial_mode で設定した測定モードのセンサーが update_intervalの設定値 ごとに更新 193 | # 指定されていないセンサーは更新されません。例えば initial_mode: VOLTAGE の場合、電流センサーは更新されません。 194 | 195 | # 皮相電力 196 | # 注意: 電流と電圧の測定タイミングが異なることから精度が非常に低いため、このセンサーはデフォルトで無効化されています。 197 | - platform: template 198 | name: Apparent Power 199 | lambda: return id(voltage).state * id(current).state; 200 | device_class: apparent_power 201 | unit_of_measurement: VA 202 | state_class: "measurement" 203 | accuracy_decimals: 2 # 小数点以下の数 204 | update_interval: 20s # 電流センサーと電圧センサーの更新間隔に合わせてください 205 | disabled_by_default: true 206 | 207 | # 力率 208 | # 注意: 電流と電圧の測定タイミングが異なることから精度が非常に低いため、このセンサーはデフォルトで無効化されています。 209 | - platform: template 210 | name: Power Factor 211 | lambda: !lambda |- 212 | if ((id(wattage).state / (id(voltage).state * id(current).state)) > 1) { 213 | return 1; // 1を超えた時は1を返す 214 | } else { 215 | return id(wattage).state / (id(voltage).state * id(current).state); // 1より少ない時はそのままの計算値を返す 216 | } 217 | device_class: power_factor 218 | state_class: "measurement" 219 | accuracy_decimals: 2 # 小数点以下の数 220 | update_interval: 20s # 電流センサーと電圧センサーの更新間隔に合わせてください 221 | disabled_by_default: true 222 | 223 | # 一日の累計消費電力量(毎日午前0時にリセットされます) 224 | - platform: total_daily_energy 225 | name: Total Daily Energy 226 | power_id: wattage 227 | accuracy_decimals: 3 # 小数点以下の数 228 | filters: 229 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 230 | unit_of_measurement: kWh 231 | 232 | # 一ヵ月の累計消費電力量(毎月1日午前0時にリセットされます) 233 | - platform: integration 234 | name: Total Monthly Energy 235 | id: total_monthly_energy 236 | sensor: wattage 237 | time_unit: h 238 | restore: true 239 | state_class: total_increasing 240 | device_class: energy 241 | accuracy_decimals: 3 # 小数点以下の数 242 | filters: 243 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 244 | unit_of_measurement: kWh 245 | 246 | # プラグミニを初めてESPHomeで設定してからの累計消費電力量 247 | - platform: integration 248 | name: Total Energy 249 | sensor: wattage 250 | time_unit: h 251 | restore: true 252 | state_class: total_increasing 253 | device_class: energy 254 | accuracy_decimals: 3 # 小数点以下の数 255 | filters: 256 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 257 | unit_of_measurement: kWh 258 | 259 | # スイッチに関する設定 260 | switch: 261 | # リレースイッチ 262 | - platform: gpio 263 | name: Plug 264 | pin: GPIO06 265 | id: relay 266 | device_class: outlet 267 | restore_mode: RESTORE_DEFAULT_OFF # プラグミニ起動時のリレースイッチ状態 268 | # 可能な設定: 269 | # 270 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 271 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 272 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 273 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 274 | # ALWAYS_OFF: 常にオフにする 275 | # ALWAYS_ON: 常にオンにする 276 | 277 | on_turn_on: # リレースイッチをオンにした時 278 | - light.turn_on: 279 | id: white_led 280 | brightness: !lambda |- 281 | if (id(led_brightness).state == "明るい") { 282 | return 1; // LEDライトの明るさ設定が「明るい」に設定されているときは、白色LEDを100%の明るさで点灯させる 283 | } else if (id(led_brightness).state == "暗い") { 284 | return 0.5; // LEDライトの明るさ設定が「暗い」に設定されているときは、白色LEDを50%の明るさで点灯させる 285 | } else { 286 | return 0; // LEDライトの明るさ設定が上記以外(LEDオフ)に設定されているときは、白色LEDを0%の明るさで点灯させる(消灯させる) 287 | } 288 | 289 | on_turn_off: # リレースイッチをオフにした時 290 | - light.turn_off: white_led 291 | 292 | # 選択に関する設定 293 | select: 294 | # プラグミニ内蔵LEDライトの明るさ設定 295 | - platform: template 296 | name: LED Brightness 297 | id: led_brightness 298 | icon: mdi:brightness-6 299 | optimistic: true 300 | options: 301 | - 明るい 302 | - 暗い 303 | - LEDオフ 304 | initial_option: 明るい 305 | restore_value: true 306 | entity_category: config 307 | on_value: # 状態が設定された時 308 | then: 309 | - lambda: |- 310 | if ( x == "LEDオフ") { 311 | id(white_led).turn_off().perform(); // 白色LEDを消灯させる 312 | } else if ( x == "暗い") { 313 | if (id(relay).state) { 314 | id(white_led).turn_on().set_brightness(0.5).perform(); // リレースイッチがオンの時のみ、白色LEDを50%の明るさで点灯させる 315 | } 316 | } else if ( x == "明るい") { 317 | if (id(relay).state) { 318 | id(white_led).turn_on().set_brightness(1.0).perform(); // リレースイッチがオンの時のみ、白色LEDを100%の明るさで点灯させる 319 | } 320 | } 321 | 322 | # 出力に関する設定 323 | output: 324 | # 白色LED出力 325 | - platform: ledc 326 | id: white_output 327 | pin: GPIO07 328 | inverted: true 329 | frequency: 19531Hz 330 | 331 | # 青色LED出力 332 | - platform: ledc 333 | id: blue_output 334 | pin: GPIO08 335 | inverted: true 336 | frequency: 19531Hz 337 | 338 | # ライトに関する設定 339 | light: 340 | # 白色LEDライト 341 | - platform: monochromatic 342 | output: white_output 343 | name: White LED 344 | id: white_led 345 | icon: mdi:led-off 346 | entity_category: config 347 | default_transition_length: 250ms 348 | restore_mode: RESTORE_DEFAULT_OFF # プラグミニ起動時の白色LEDライト状態 349 | # 可能な設定: 350 | # 351 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 352 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 353 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 354 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 355 | # ALWAYS_OFF: 常にオフにする 356 | # ALWAYS_ON: 常にオンにする 357 | 358 | # 青色LEDライト 359 | - platform: monochromatic 360 | output: blue_output 361 | name: Blue LED 362 | id: blue_led 363 | icon: mdi:led-off 364 | entity_category: config 365 | default_transition_length: 250ms 366 | restore_mode: ALWAYS_OFF # プラグミニ起動時の青色LEDライト状態 367 | # 可能な設定: 368 | # 369 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 370 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 371 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 372 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 373 | # ALWAYS_OFF: 常にオフにする 374 | # ALWAYS_ON: 常にオンにする 375 | -------------------------------------------------------------------------------- /switchbot-plug-mini-w2001401-homekit-enabled-ja.yaml: -------------------------------------------------------------------------------- 1 | # SwitchBot プラグミニ (JP) HomeKit for ESPHome by taikun114 2 | 3 | substitutions: 4 | device_name: switchbot-plug-mini 5 | friendly_name: SwitchBot Plug Mini 6 | fw_version: 1.2.0 7 | 8 | # モデル番号 9 | model: "W2001401" 10 | 11 | # キャリブレーションデータ 12 | voltage_divider: "660.7973855893309" 13 | current_resistor: "0.0024013086148925913" 14 | current_multiply: "1.783420806116323" 15 | # キャリブレーションを行う際、電力メーターに表示される値からプラグミニ自体の消費電力(リレーをオンにした状態で約0.8W / 0.019A)を 16 | # 引いた値を使ってキャリブレーションを行ってください。 17 | # 18 | # キャリブレーションの方法については、以下のドキュメントをご覧ください。 19 | # https://esphome.io/components/sensor/hlw8012#calibration 20 | 21 | # ESPHomeに関する設定 22 | esphome: 23 | name: ${device_name} 24 | comment: 電力モニタリングスマートフラグ(${model}) 25 | friendly_name: ${friendly_name} 26 | name_add_mac_suffix: true 27 | platformio_options: 28 | board_build.flash_mode: dio 29 | project: 30 | name: SwitchBot (Customized by taikun114).Plug Mini JP HomeKit (${model}) 31 | version: ${fw_version} 32 | 33 | # ESP32に関する設定 34 | esp32: 35 | board: esp32-c3-devkitm-1 36 | variant: ESP32C3 37 | framework: 38 | type: esp-idf 39 | sdkconfig_options: 40 | CONFIG_COMPILER_OPTIMIZATION_SIZE: y 41 | CONFIG_LWIP_MAX_SOCKETS: "16" 42 | CONFIG_MBEDTLS_HKDF_C: y 43 | 44 | # 外部コンポーネントに関する設定 45 | external_components: 46 | source: github://rednblkx/HAP-ESPHome@main 47 | refresh: 0s 48 | 49 | # この設定ファイルをローカルに読み込むための設定 50 | dashboard_import: 51 | package_import_url: github://taikun114/SwitchBot-Plug-Mini-for-ESPHome/switchbot-plug-mini-w2001401-homekit-enabled-ja.yaml@v1.2.0 52 | import_full_config: true 53 | 54 | # ログを表示するための設定 55 | logger: 56 | 57 | # APIに関する設定 58 | api: 59 | 60 | # OTA(Over-The-Air)アップデートに関する設定 61 | ota: 62 | - platform: esphome 63 | 64 | # Wi-Fiネットワークに関する設定 65 | wifi: 66 | # プラグミニが接続するWi-Fiネットワークの設定 67 | # ssid: !secret wifi_ssid 68 | # password: !secret wifi_password 69 | 70 | # 一定の期間(デフォルトでは1分)Wi-Fiネットワークに接続できなかった場合に 71 | # 有効になるフォールバックホットスポット(アクセスポイントモード)の設定 72 | ap: 73 | # password: !secret ap_password # コメントを外して、パスワードを設定することをおすすめします。 74 | 75 | # Wi-Fiネットワークから切断されている時に、青色LEDを点滅させる 76 | on_connect: # Wi-Fiネットワークに接続された時 77 | - light.turn_off: blue_led 78 | on_disconnect: # Wi-Fiネットワークから切断された時 79 | - while: 80 | condition: 81 | not: 82 | wifi.connected: 83 | then: 84 | - light.turn_on: 85 | id: blue_led 86 | brightness: 100% 87 | - delay: 500ms 88 | - light.turn_off: blue_led 89 | - delay: 500ms 90 | 91 | # フォールバックホットスポットに接続したときに、プラグミニのWi-Fi設定の変更や 92 | # ファームウェアの更新を行えるようにするキャプティブポータルの設定 93 | captive_portal: 94 | 95 | # Bluetooth LEを使ってWi-Fiをセットアップできるようにする設定 96 | # 注意: このコンポーネントを使用していると内部温度が上昇するため、 97 | # このコンポーネントを無効化(コメントアウト)し、フォールバックホットスポットからWi-Fiを設定することをおすすめします。 98 | esp32_improv: 99 | authorizer: none 100 | 101 | # HomeKitブリッジに関する設定 102 | homekit_base: 103 | meta: 104 | name: プラグミニのブリッジ 105 | manufacturer: SwitchBot 106 | model: ${model} 107 | fw_rev: ${fw_version} 108 | setup_code: 159-35-728 109 | 110 | # HomeKitに関する設定 111 | homekit: 112 | # HomeKitに追加するスイッチ 113 | switch: 114 | # リレースイッチ 115 | - id: relay 116 | meta: 117 | name: プラグ 118 | manufacturer: SwitchBot 119 | model: ${model} 120 | fw_rev: ${fw_version} 121 | 122 | # HomeKitに関する詳しい設定は以下をご覧ください。 123 | # https://github.com/rednblkx/HAP-ESPHome#readme-ov-file 124 | 125 | # 時間に関する設定 126 | time: 127 | # API接続を通して、Home Assistantと時間を同期する 128 | - platform: homeassistant 129 | id: homeassistant_time 130 | 131 | on_time: # 特定の時間になった時 132 | # 毎月1日午前0時に、一ヵ月の累計消費電力量センサーをリセットする 133 | - seconds: 0 134 | minutes: 0 135 | hours: 0 136 | days_of_month: 1 137 | then: 138 | - sensor.integration.reset: total_monthly_energy 139 | 140 | # ボタンに関する設定 141 | button: 142 | # プラグミニを再起動する 143 | - platform: restart 144 | name: Reboot 145 | id: reboot 146 | 147 | # HomeKitのペアリングをリセットする 148 | - platform: homekit_base 149 | factory_reset: 150 | id: reset_homekit_pairings 151 | internal: true 152 | 153 | # バイナリセンサーに関する設定 154 | binary_sensor: 155 | # プラグミニ本体のボタンが押されたことを検知 156 | - platform: gpio 157 | id: power_button 158 | pin: 159 | number: GPIO02 160 | inverted: true 161 | internal: true 162 | 163 | on_click: # ボタンを押したとき 164 | # ボタンを押してすぐ離した時にリレースイッチを切り替える 165 | - min_length: 50ms 166 | max_length: 500ms 167 | then: 168 | - switch.toggle: relay 169 | 170 | # ボタンを3秒以上10秒以下の範囲で長押しした時にプラグミニを再起動する 171 | - min_length: 3s 172 | max_length: 10s 173 | then: 174 | - button.press: reboot 175 | 176 | on_multi_click: # ボタンを特定のタイミングで複数回押した時 177 | # ボタンを1秒以上長押ししてから離し、その後、最低2秒間空けてから 178 | # 再びボタンを1秒以上長押しするという同様の手順を3回繰り返して、HomeKitのペアリングをリセットする 179 | - timing: 180 | - ON for at least 1s 181 | - OFF for at least 2s 182 | - ON for at least 1s 183 | - OFF for at least 2s 184 | - ON for at least 1s 185 | - OFF for at least 2s 186 | then: 187 | - button.press: reset_homekit_pairings 188 | 189 | # センサーに関する設定 190 | sensor: 191 | # Wi-Fiアクセスポイントへの接続強度 192 | - platform: wifi_signal 193 | name: Wi-Fi Signal 194 | update_interval: 30s 195 | 196 | # 最後に電源を入れた時刻 197 | - platform: uptime 198 | type: timestamp 199 | name: Uptime 200 | 201 | # プラグミニの内部温度 202 | - platform: internal_temperature 203 | name: Internal Temperature 204 | update_interval: 30s 205 | 206 | # 電力モニタリングセンサー 207 | - platform: hlw8012 208 | sel_pin: 209 | number: GPIO20 210 | inverted: true 211 | cf_pin: GPIO18 212 | cf1_pin: GPIO19 213 | current_resistor: ${current_resistor} 214 | voltage_divider: ${voltage_divider} 215 | power: # 電力 216 | name: Power 217 | unit_of_measurement: W 218 | id: wattage 219 | accuracy_decimals: 1 # 小数点以下の数 220 | current: # 電流 221 | name: Current 222 | unit_of_measurement: A 223 | id: current 224 | filters: 225 | - multiply: ${current_multiply} 226 | voltage: # 電圧 227 | name: Voltage 228 | unit_of_measurement: V 229 | id: voltage 230 | accuracy_decimals: 2 # 小数点以下の数 231 | initial_mode: VOLTAGE # 初期の測定モード。電圧(VOLTAGE)または電流(CURRENT) 232 | change_mode_every: 1 # 電流と電圧の測定モードを切り替えるまでの測定回数(切り替え後、初回の値は破棄されるため、設定値 + 1回測定されます) 233 | update_interval: 5s # センサーの更新間隔 234 | # センサーの更新間隔について 235 | # 236 | # 電力センサーの更新間隔は update_interval で設定した間隔で更新されます。 237 | # 電流センサーと電圧センサーの更新間隔は change_mode_every の設定値によって異なります。 238 | # 239 | # change_mode_every: 1 以上の場合: 240 | # (change_mode_everyの設定値 + 1) * 2 * update_intervalの設定値(秒換算) ごとに更新 241 | # 例えば change_mode_every: 1 で update_interval: 1s の場合、(1 + 1) * 2 * 1s = 4秒ごとに更新されることになります。 242 | # 243 | # change_mode_every: "never" の場合: 244 | # initial_mode で設定した測定モードのセンサーが update_intervalの設定値 ごとに更新 245 | # 指定されていないセンサーは更新されません。例えば initial_mode: VOLTAGE の場合、電流センサーは更新されません。 246 | 247 | # 皮相電力 248 | # 注意: 電流と電圧の測定タイミングが異なることから精度が非常に低いため、このセンサーはデフォルトで無効化されています。 249 | - platform: template 250 | name: Apparent Power 251 | lambda: return id(voltage).state * id(current).state; 252 | device_class: apparent_power 253 | unit_of_measurement: VA 254 | state_class: "measurement" 255 | accuracy_decimals: 2 # 小数点以下の数 256 | update_interval: 20s # 電流センサーと電圧センサーの更新間隔に合わせてください 257 | disabled_by_default: true 258 | 259 | # 力率 260 | # 注意: 電流と電圧の測定タイミングが異なることから精度が非常に低いため、このセンサーはデフォルトで無効化されています。 261 | - platform: template 262 | name: Power Factor 263 | lambda: !lambda |- 264 | if ((id(wattage).state / (id(voltage).state * id(current).state)) > 1) { 265 | return 1; // 1を超えた時は1を返す 266 | } else { 267 | return id(wattage).state / (id(voltage).state * id(current).state); // 1より少ない時はそのままの計算値を返す 268 | } 269 | device_class: power_factor 270 | state_class: "measurement" 271 | accuracy_decimals: 2 # 小数点以下の数 272 | update_interval: 20s # 電流センサーと電圧センサーの更新間隔に合わせてください 273 | disabled_by_default: true 274 | 275 | # 一日の累計消費電力量(毎日午前0時にリセットされます) 276 | - platform: total_daily_energy 277 | name: Total Daily Energy 278 | power_id: wattage 279 | accuracy_decimals: 3 # 小数点以下の数 280 | filters: 281 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 282 | unit_of_measurement: kWh 283 | 284 | # 一ヵ月の累計消費電力量(毎月1日午前0時にリセットされます) 285 | - platform: integration 286 | name: Total Monthly Energy 287 | id: total_monthly_energy 288 | sensor: wattage 289 | time_unit: h 290 | restore: true 291 | state_class: total_increasing 292 | device_class: energy 293 | accuracy_decimals: 3 # 小数点以下の数 294 | filters: 295 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 296 | unit_of_measurement: kWh 297 | 298 | # プラグミニを初めてESPHomeで設定してからの累計消費電力量 299 | - platform: integration 300 | name: Total Energy 301 | sensor: wattage 302 | time_unit: h 303 | restore: true 304 | state_class: total_increasing 305 | device_class: energy 306 | accuracy_decimals: 3 # 小数点以下の数 307 | filters: 308 | - multiply: 0.001 # 測定単位を Wh から kWh に変換 309 | unit_of_measurement: kWh 310 | 311 | # スイッチに関する設定 312 | switch: 313 | # リレースイッチ 314 | - platform: gpio 315 | name: Plug 316 | pin: GPIO06 317 | id: relay 318 | device_class: outlet 319 | restore_mode: RESTORE_DEFAULT_OFF # プラグミニ起動時のリレースイッチ状態 320 | # 可能な設定: 321 | # 322 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 323 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 324 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 325 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 326 | # ALWAYS_OFF: 常にオフにする 327 | # ALWAYS_ON: 常にオンにする 328 | 329 | on_turn_on: # リレースイッチをオンにした時 330 | - light.turn_on: 331 | id: white_led 332 | brightness: !lambda |- 333 | if (id(led_brightness).state == "明るい") { 334 | return 1; // LEDライトの明るさ設定が「明るい」に設定されているときは、白色LEDを100%の明るさで点灯させる 335 | } else if (id(led_brightness).state == "暗い") { 336 | return 0.5; // LEDライトの明るさ設定が「暗い」に設定されているときは、白色LEDを50%の明るさで点灯させる 337 | } else { 338 | return 0; // LEDライトの明るさ設定が上記以外(LEDオフ)に設定されているときは、白色LEDを0%の明るさで点灯させる(消灯させる) 339 | } 340 | 341 | on_turn_off: # リレースイッチをオフにした時 342 | - light.turn_off: white_led 343 | 344 | # 選択に関する設定 345 | select: 346 | # プラグミニ内蔵LEDライトの明るさ設定 347 | - platform: template 348 | name: LED Brightness 349 | id: led_brightness 350 | icon: mdi:brightness-6 351 | optimistic: true 352 | options: 353 | - 明るい 354 | - 暗い 355 | - LEDオフ 356 | initial_option: 明るい 357 | restore_value: true 358 | entity_category: config 359 | on_value: # 状態が設定された時 360 | then: 361 | - lambda: |- 362 | if ( x == "LEDオフ") { 363 | id(white_led).turn_off().perform(); // 白色LEDを消灯させる 364 | } else if ( x == "暗い") { 365 | if (id(relay).state) { 366 | id(white_led).turn_on().set_brightness(0.5).perform(); // リレースイッチがオンの時のみ、白色LEDを50%の明るさで点灯させる 367 | } 368 | } else if ( x == "明るい") { 369 | if (id(relay).state) { 370 | id(white_led).turn_on().set_brightness(1.0).perform(); // リレースイッチがオンの時のみ、白色LEDを100%の明るさで点灯させる 371 | } 372 | } 373 | 374 | # 出力に関する設定 375 | output: 376 | # 白色LED出力 377 | - platform: ledc 378 | id: white_output 379 | pin: GPIO07 380 | inverted: true 381 | frequency: 19531Hz 382 | 383 | # 青色LED出力 384 | - platform: ledc 385 | id: blue_output 386 | pin: GPIO08 387 | inverted: true 388 | frequency: 19531Hz 389 | 390 | # ライトに関する設定 391 | light: 392 | # 白色LEDライト 393 | - platform: monochromatic 394 | output: white_output 395 | name: White LED 396 | id: white_led 397 | icon: mdi:led-off 398 | entity_category: config 399 | default_transition_length: 250ms 400 | restore_mode: RESTORE_DEFAULT_OFF # プラグミニ起動時の白色LEDライト状態 401 | # 可能な設定: 402 | # 403 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 404 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 405 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 406 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 407 | # ALWAYS_OFF: 常にオフにする 408 | # ALWAYS_ON: 常にオンにする 409 | 410 | # 青色LEDライト 411 | - platform: monochromatic 412 | output: blue_output 413 | name: Blue LED 414 | id: blue_led 415 | icon: mdi:led-off 416 | entity_category: config 417 | default_transition_length: 250ms 418 | restore_mode: ALWAYS_OFF # プラグミニ起動時の青色LEDライト状態 419 | # 可能な設定: 420 | # 421 | # RESTORE_DEFAULT_OFF: 可能な場合は状態を復元し、不可能な場合はオフにする 422 | # RESTORE_DEFAULT_ON: 可能な場合は状態を復元し、不可能な場合はオンにする 423 | # RESTORE_INVERTED_DEFAULT_OFF: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオフにする 424 | # RESTORE_INVERTED_DEFAULT_ON: 可能な場合は以前の状態とは反転して復元し、不可能な場合はオンにする 425 | # ALWAYS_OFF: 常にオフにする 426 | # ALWAYS_ON: 常にオンにする 427 | -------------------------------------------------------------------------------- /switchbot-plug-mini-w2001401.yaml: -------------------------------------------------------------------------------- 1 | # SwitchBot Plug Mini (JP) for ESPHome by taikun114 2 | 3 | substitutions: 4 | device_name: switchbot-plug-mini 5 | friendly_name: SwitchBot Plug Mini 6 | fw_version: 1.2.0 7 | 8 | # Model number 9 | model: "W2001401" 10 | 11 | # Calibration data 12 | voltage_divider: "660.7973855893309" 13 | current_resistor: "0.0024013086148925913" 14 | current_multiply: "1.783420806116323" 15 | # When calibrating, use the value shown on the power meter minus the power consumption of the 16 | # Plug Mini itself (about 0.8W / 0.019A with the relay turned on) to calibrate. 17 | # 18 | # See the document below for calibration instructions. 19 | # https://esphome.io/components/sensor/hlw8012#calibration 20 | 21 | # Configuration for ESPHome 22 | esphome: 23 | name: ${device_name} 24 | comment: Energy Monitoring Smart Plug (${model}) 25 | friendly_name: ${friendly_name} 26 | name_add_mac_suffix: true 27 | platformio_options: 28 | board_build.flash_mode: dio 29 | project: 30 | name: SwitchBot (Customized by taikun114).Plug Mini JP (${model}) 31 | version: ${fw_version} 32 | 33 | # Configuration for ESP32 34 | esp32: 35 | board: esp32-c3-devkitm-1 36 | variant: ESP32C3 37 | framework: 38 | type: esp-idf 39 | 40 | # Configuration to read this configuration file locally 41 | dashboard_import: 42 | package_import_url: github://taikun114/SwitchBot-Plug-Mini-for-ESPHome/switchbot-plug-mini-w2001401.yaml@v1.2.0 43 | import_full_config: true 44 | 45 | # Configuration for showing logs 46 | logger: 47 | 48 | # Configuration for API 49 | api: 50 | 51 | # Configuration for OTA (Over-The-Air) updates 52 | ota: 53 | - platform: esphome 54 | 55 | # Configuration for Wi-Fi network 56 | wifi: 57 | # Configure the Wi-Fi network the Plug Mini will connect to 58 | # ssid: !secret wifi_ssid 59 | # password: !secret wifi_password 60 | 61 | # Configure the fallback hotspot (access point mode), which is activated when 62 | # Wi-Fi network is unable to connect for a certain period of time (1 minute by default) 63 | ap: 64 | # password: !secret ap_password # Remove comment and set a password is recommended. 65 | 66 | # Blinking Blue LED when disconnected from Wi-Fi network 67 | on_connect: # When connected to Wi-Fi network 68 | - light.turn_off: blue_led 69 | on_disconnect: # When disconnected from Wi-Fi network 70 | - while: 71 | condition: 72 | not: 73 | wifi.connected: 74 | then: 75 | - light.turn_on: 76 | id: blue_led 77 | brightness: 100% 78 | - delay: 500ms 79 | - light.turn_off: blue_led 80 | - delay: 500ms 81 | 82 | # Configure a captive portal that allows users to change Wi-Fi settings 83 | # and update firmware on the Plug Mini when connected to a fallback hotspot 84 | captive_portal: 85 | 86 | # Configuration to allow Wi-Fi setup using Bluetooth LE 87 | # Note: Since using this component increases internal temperature, 88 | # it is recommended to disable (comment out) this component and configure Wi-Fi from the fallback hotspot. 89 | esp32_improv: 90 | authorizer: none 91 | 92 | # Configuration for time 93 | time: 94 | # Synchronize time with Home Assistant through API connection 95 | - platform: homeassistant 96 | id: homeassistant_time 97 | 98 | on_time: # When a specific time came 99 | # Reset the total monthly energy sensor at 0 am on the first day of every month 100 | - seconds: 0 101 | minutes: 0 102 | hours: 0 103 | days_of_month: 1 104 | then: 105 | - sensor.integration.reset: total_monthly_energy 106 | 107 | # Configuration for buttons 108 | button: 109 | # Reboot the Plug Mini 110 | - platform: restart 111 | name: Reboot 112 | id: reboot 113 | 114 | # Configuration for binary sensors 115 | binary_sensor: 116 | # Detects that a button on the Plug Mini unit has been pressed 117 | - platform: gpio 118 | id: power_button 119 | pin: 120 | number: GPIO02 121 | inverted: true 122 | internal: true 123 | 124 | on_click: # When the button is pressed 125 | # Toggle the relay switch when the button is pressed and immediately released. 126 | - min_length: 50ms 127 | max_length: 500ms 128 | then: 129 | - switch.toggle: relay 130 | 131 | # Reboot the Plug Mini when the button is held between 3 and 10 seconds. 132 | - min_length: 3s 133 | max_length: 10s 134 | then: 135 | - button.press: reboot 136 | 137 | # Configuration for sensors 138 | sensor: 139 | # Connection strength to Wi-Fi access point 140 | - platform: wifi_signal 141 | name: Wi-Fi Signal 142 | update_interval: 30s 143 | 144 | # Time of last power on 145 | - platform: uptime 146 | type: timestamp 147 | name: Uptime 148 | 149 | # Internal temperature of Plug Mini 150 | - platform: internal_temperature 151 | name: Internal Temperature 152 | update_interval: 30s 153 | 154 | # Power monitoring sensors 155 | - platform: hlw8012 156 | sel_pin: 157 | number: GPIO20 158 | inverted: true 159 | cf_pin: GPIO18 160 | cf1_pin: GPIO19 161 | current_resistor: ${current_resistor} 162 | voltage_divider: ${voltage_divider} 163 | power: 164 | name: Power 165 | unit_of_measurement: W 166 | id: wattage 167 | accuracy_decimals: 1 # Number of decimal points 168 | current: 169 | name: Current 170 | unit_of_measurement: A 171 | id: current 172 | filters: 173 | - multiply: ${current_multiply} 174 | voltage: 175 | name: Voltage 176 | unit_of_measurement: V 177 | id: voltage 178 | accuracy_decimals: 2 # Number of decimal points 179 | initial_mode: VOLTAGE # Initial measurement mode. VOLTAGE or CURRENT 180 | change_mode_every: 1 181 | # Number of measurements before switching between current and voltage measurement modes 182 | # (after switching, the initial value is discarded, so the set value + 1 measurement is taken) 183 | 184 | update_interval: 5s 185 | # About sensor update intervals 186 | # 187 | # The power sensor is updated at the interval set by update_interval. 188 | # The current sensor and voltage sensor update intervals depend on the value set in change_mode_every. 189 | # 190 | # If change_mode_every: 1 or more: 191 | # Update every: (value set in change_mode_every + 1) * 2 * value set in update_interval (in seconds) 192 | # For example, if change_mode_every: 1 and update_interval: 1s, then (1 + 1) * 2 * 1s = update every 4 seconds. 193 | # 194 | # If change_mode_every: “never”: 195 | # The sensor in the measurement mode set in initial_mode is updated every update_interval value. 196 | # Unspecified sensors will not be updated. For example, if initial_mode: VOLTAGE, the current sensor will not be updated. 197 | 198 | # Apparent power 199 | # Note: This sensor is disabled by default because the accuracy is very low due to the different timing of current and voltage measurements. 200 | - platform: template 201 | name: Apparent Power 202 | lambda: return id(voltage).state * id(current).state; 203 | device_class: apparent_power 204 | unit_of_measurement: VA 205 | state_class: "measurement" 206 | accuracy_decimals: 2 # Number of decimal points 207 | update_interval: 20s # Please match the update intervals of the current and voltage sensors 208 | disabled_by_default: true 209 | 210 | # Power factor 211 | # Note: This sensor is disabled by default because the accuracy is very low due to the different timing of current and voltage measurements. 212 | - platform: template 213 | name: Power Factor 214 | lambda: !lambda |- 215 | if ((id(wattage).state / (id(voltage).state * id(current).state)) > 1) { 216 | return 1; // Return 1 if it is over 1 217 | } else { 218 | return id(wattage).state / (id(voltage).state * id(current).state); // Return the calculated value as is if it is less than 1 219 | } 220 | device_class: power_factor 221 | state_class: "measurement" 222 | accuracy_decimals: 2 # Number of decimal points 223 | update_interval: 20s # Please match the update intervals of the current and voltage sensors 224 | disabled_by_default: true 225 | 226 | # Total daily energy consumption (reset daily at 0 am) 227 | - platform: total_daily_energy 228 | name: Total Daily Energy 229 | power_id: wattage 230 | accuracy_decimals: 3 # Number of decimal points 231 | filters: 232 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 233 | unit_of_measurement: kWh 234 | 235 | # Total monthly energy consumption (reset monthly at 0 am on the first day of every month) 236 | - platform: integration 237 | name: Total Monthly Energy 238 | id: total_monthly_energy 239 | sensor: wattage 240 | time_unit: h 241 | restore: true 242 | state_class: total_increasing 243 | device_class: energy 244 | accuracy_decimals: 3 # Number of decimal points 245 | filters: 246 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 247 | unit_of_measurement: kWh 248 | 249 | # Total energy consumption since the Plug Mini was first set up with ESPHome 250 | - platform: integration 251 | name: Total Energy 252 | sensor: wattage 253 | time_unit: h 254 | restore: true 255 | state_class: total_increasing 256 | device_class: energy 257 | accuracy_decimals: 3 # Number of decimal points 258 | filters: 259 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 260 | unit_of_measurement: kWh 261 | 262 | # Configuration for switches 263 | switch: 264 | # Relay switch 265 | - platform: gpio 266 | name: Plug 267 | pin: GPIO06 268 | id: relay 269 | device_class: outlet 270 | restore_mode: RESTORE_DEFAULT_OFF # Relay switch state at startup of Plug Mini 271 | # Available configuration: 272 | # 273 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 274 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 275 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 276 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 277 | # ALWAYS_OFF: Always turn off 278 | # ALWAYS_ON: Always turn on 279 | 280 | on_turn_on: # When the relay switch is turned on 281 | - light.turn_on: 282 | id: white_led 283 | brightness: !lambda |- 284 | if (id(led_brightness).state == "Bright") { 285 | return 1; // When the brightness setting of the LED light is set to “Bright”, the White LED is turned on at 100% brightness 286 | } else if (id(led_brightness).state == "Dim") { 287 | return 0.5; // When the brightness setting of the LED light is set to “Dim”, the White LED is turned on at 50% brightness. 288 | } else { 289 | return 0; // When the brightness setting of the LED light is set to other than the above (LED Off), the White LED is turned on at 0% brightness (turned off) 290 | } 291 | 292 | on_turn_off: # When the relay switch is turned off 293 | - light.turn_off: white_led 294 | 295 | # Configuration for select 296 | select: 297 | # Brightness setting for built-in Plug Mini LED light 298 | - platform: template 299 | name: LED Brightness 300 | id: led_brightness 301 | icon: mdi:brightness-6 302 | optimistic: true 303 | options: 304 | - Bright 305 | - Dim 306 | - LED Off 307 | initial_option: Bright 308 | restore_value: true 309 | entity_category: config 310 | on_value: # When the state is set 311 | then: 312 | - lambda: |- 313 | if ( x == "LED Off") { 314 | id(white_led).turn_off().perform(); // Turn off the White LED 315 | } else if ( x == "Dim") { 316 | if (id(relay).state) { 317 | id(white_led).turn_on().set_brightness(0.5).perform(); // Turn on the White LED at 50% brightness only when the relay switch is on. 318 | } 319 | } else if ( x == "Bright") { 320 | if (id(relay).state) { 321 | id(white_led).turn_on().set_brightness(1.0).perform(); // Turn on the White LED at 100% brightness only when the relay switch is on. 322 | } 323 | } 324 | 325 | # Configuration of output 326 | output: 327 | # White LED output 328 | - platform: ledc 329 | id: white_output 330 | pin: GPIO07 331 | inverted: true 332 | frequency: 19531Hz 333 | 334 | # Blue LED output 335 | - platform: ledc 336 | id: blue_output 337 | pin: GPIO08 338 | inverted: true 339 | frequency: 19531Hz 340 | 341 | # Configuration for lights 342 | light: 343 | # White LED light 344 | - platform: monochromatic 345 | output: white_output 346 | name: White LED 347 | id: white_led 348 | icon: mdi:led-off 349 | entity_category: config 350 | default_transition_length: 250ms 351 | restore_mode: RESTORE_DEFAULT_OFF # White LED light state at startup of Plug Mini 352 | # Available configuration: 353 | # 354 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 355 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 356 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 357 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 358 | # ALWAYS_OFF: Always turn off 359 | # ALWAYS_ON: Always turn on 360 | 361 | # Blue LED light 362 | - platform: monochromatic 363 | output: blue_output 364 | name: Blue LED 365 | id: blue_led 366 | icon: mdi:led-off 367 | entity_category: config 368 | default_transition_length: 250ms 369 | restore_mode: ALWAYS_OFF # Blue LED light state at startup of Plug Mini 370 | # Available configuration: 371 | # 372 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 373 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 374 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 375 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 376 | # ALWAYS_OFF: Always turn off 377 | # ALWAYS_ON: Always turn on 378 | -------------------------------------------------------------------------------- /docs/README-ja.md: -------------------------------------------------------------------------------- 1 | # SwitchBot プラグミニ for ESPHome 2 | [English](/README.md) | **日本語** 3 | 4 | ![banner](images/banner.png) 5 | 6 | このリポジトリには、SwitchBotが発売している電力モニタリング機能付きスマートプラグ「プラグミニ」を[**ESPHome**](https://esphome.io/)(と[**Home Assistant**](https://www.home-assistant.io/))で使用するための手順や設定ファイルが含まれています。 7 | 8 | > [!CAUTION] 9 | > 作業は全て**自己責任で**行うようにしてください。 10 | > 11 | > SwitchBot プラグミニをESPHomeで使う事は**SwitchBot公式の使い方ではありません**ので、**SwitchBotからのいかなるサポートも受けられなくなります。** 12 | > 13 | > また、ここで紹介している手順ではファームウェアを書き換える作業があり、**手順を誤ったり失敗したりしてしまうと製品を破損させてしまう可能性**があります。 14 | > 15 | > どのような状況になったとしてもご自身で対処できる場合に限り作業を行われることをおすすめします。 16 | 17 | 18 | ## 目次 19 | - [対応機種](#対応機種) 20 | - [動作することを確認している機種](#動作することを確認している機種) 21 | - [動作する可能性が高い機種](#動作する可能性が高い機種) 22 | - [SwitchBot プラグミニをESPHomeで使えるようにする](#SwitchBot-プラグミニをESPHomeで使えるようにする) 23 | - [事前準備: ESPHome用のファームウェアをダウンロードする](#事前準備-ESPHome用のファームウェアをダウンロードする) 24 | - [ファームウェアの種類](#ファームウェアの種類) 25 | - [手順1. SwitchbOTAを使ってTasmotaファームウェアをインストールする](#手順1-SwitchbOTAを使ってTasmotaファームウェアをインストールする) 26 | - [手順2. ESPHomeファームウェアをインストールする](#手順2-ESPHomeファームウェアをインストールする) 27 | - [手順3. Wi-Fiネットワークの設定を行う](#手順3-Wi-Fiネットワークの設定を行う) 28 | - [フォールバックホットスポットからWi-Fiネットワークを設定する](#フォールバックホットスポットからWi-Fiネットワークを設定する) 29 | - [Improv via BLEを使ってWi-Fiネットワークを設定する](#Improv-via-BLEを使ってWi-Fiネットワークを設定する) 30 | - [手順4. ESPHomeの設定を行う](#手順4-ESPHomeの設定を行う) 31 | - [ESPHome Device Builderをインストールする](#ESPHome-Device-Builderをインストールする) 32 | - [デバイスの完全な制御を得る](#デバイスの完全な制御を得る) 33 | - [手順5. 最初に変更しておくべき設定](#手順5-最初に変更しておくべき設定) 34 | - [Wi-Fiネットワークに関する設定](#Wi-Fiネットワークに関する設定) 35 | - [Improv via BLEに関する設定](#Improv-via-BLEに関する設定) 36 | - [設定変更が終わったらファームウェアをインストールする](#設定変更が終わったらファームウェアをインストールする) 37 | - [手順6. 電力モニタリングセンサーのキャリブレーションを行う(オプション)](#手順6-電力モニタリングセンサーのキャリブレーションを行うオプション) 38 | - [手順7. HomeKitを設定する(HomeKitファームウェアのみ)](#手順7-HomeKitを設定するHomeKitファームウェアのみ) 39 | - [デフォルトの機能について](#デフォルトの機能について) 40 | - [LEDライトの表示について](#LEDライトの表示について) 41 | - [白色LEDライト](#白色LEDライト) 42 | - [青色LEDライト](#青色LEDライト) 43 | - [本体のボタンについて](#本体のボタンについて) 44 | - [ボタンを押してすぐ離したとき](#ボタンを押してすぐ離したとき) 45 | - [ボタンを長押ししたとき](#ボタンを長押ししたとき) 46 | - [特定のタイミングで複数回押したとき(HomeKitファームウェアのみ)](#特定のタイミングで複数回押したときHomeKitファームウェアのみ) 47 | - [Home Assistantに表示されるエンティティ名について](#Home-Assistantに表示されるエンティティ名について) 48 | - [クレジット](#クレジット) 49 | 50 | 51 | ## 対応機種 52 | 53 | ### 動作することを確認している機種 54 | - **W2001401**: [**プラグミニ(JP) HomeKit対応**](https://www.switchbot.jp/products/switchbot-plugmini-homekit) 55 | 56 | 57 | ### 動作する可能性が高い機種 58 | - **W1901400**: [**プラグミニ(US)**](https://www.switch-bot.com/products/switchbot-plug-mini) 59 | - **W1901401**: [**プラグミニ(US) HomeKit対応**](https://www.switch-bot.com/products/switchbot-plug-mini-homekit-enabled) 60 | - **W2001400**: [**プラグミニ(JP)**](https://www.switchbot.jp/products/switchbot-plug-mini) 61 | 62 | すべてのモデルが全く同じハードウェア構成かどうかがわからないため、これらのモデルで使用するためには設定ファイルを変更しなければならない可能性があります。 63 | 64 | 65 | > [!IMPORTANT] 66 | > ここで紹介している手順を行うと、HomeKit対応モデルでは**HomeKitの機能は失われます。** 67 | > 68 | > これを補完するために、「[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)」を使ってHomeKitの機能を追加したファームウェアも用意していますが、**工場出荷時に設定されていたHomeKitの情報が失われているため、認定されていないハードウェアとして認識されるようになります**のでご注意ください。 69 | 70 | 71 | ## SwitchBot プラグミニをESPHomeで使えるようにする 72 | 73 | ### 事前準備: ESPHome用のファームウェアをダウンロードする 74 | [**リリースページ**](https://github.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/releases)からファームウェアをダウンロードすることができます。 75 | 76 | 77 | #### ファームウェアの種類 78 | 機能や言語に応じて、複数のファームウェアを用意しています。 79 | 80 | - W2001401用 81 | - 英語 82 | - **switchbot-plug-mini-w2001401-vX.X.X.bin** 83 | - 基本的なファームウェアファイルです。 84 | - **switchbot-plug-mini-w2001401-homekit-enabled-vX.X.X.bin** 85 | - 基本的な機能に加え、「[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)」を使ってHomeKitの機能を追加したファームウェアファイルです。 86 | - 日本語 87 | - **switchbot-plug-mini-w2001401-vX.X.X-ja.bin** 88 | - 基本的なファームウェアファイルです。 89 | - **switchbot-plug-mini-w2001401-homekit-enabled-vX.X.X-ja.bin** 90 | - 基本的な機能に加え、「[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)」を使ってHomeKitの機能を追加したファームウェアファイルです。 91 | 92 | 変更ログは[**こちら**](CHANGELOG-ja.md)をご覧ください。 93 | 94 | 95 | > [!NOTE] 96 | > [**USモデルのW1901400とW1901401ではソフトウェア面以外での違いはほとんどないとの報告**](https://github.com/kendallgoto/switchbota/issues/19)がありますので、JPモデルのW2001400とW2001401も同様の可能性が高く、W2001400とW2001401は同じファームウェア / 設定ファイルが使用できる可能性があります。 97 | 98 | 99 | ### 手順1. SwitchbOTAを使ってTasmotaファームウェアをインストールする 100 | プラグミニを分解することなく、OTA(Over The Air)でファームウェアを書き換えることができるオープンソースのツール「[**SwitchbOTA**](https://github.com/kendallgoto/switchbota)」を使用して、最初にTasmotaのファームウェアに書き換える必要があります。 101 | 102 | ファームウェア書き換えの手順については、[**SwitchbOTAのREADME**](https://github.com/kendallgoto/switchbota#readme-ov-file)をご覧ください。 103 | 104 | Tasmotaファームウェアのインストールが完了してWi-Fiの設定が終わったら、次のステップに進みます。 105 | 106 | > [!WARNING] 107 | > Tasmotaをv12またはそれ以降のバージョンに**アップグレードしようとしないで**ください。Tasmota v12で導入された新しいパーティションレイアウトではESPHomeと互換性がないため、ESPHomeファームウェアをインストールすることができなくなってしまいます。 108 | > 109 | > また、Tasmota v11またはそれ以前に戻すには、本体を分解してシリアルフラッシュを行う必要がありますので、SwitchbOTAによってインストールされたTasmotaのバージョンは変更しないことを強くおすすめします。 110 | 111 | 112 | ### 手順2. ESPHomeファームウェアをインストールする 113 | ![Tasmota Home](images/Tasmota%20Home.png) 114 | 115 | TasmotaファームウェアをインストールしたプラグミニのIPアドレスにアクセスすると、Tasmotaのページが表示されるので、「**Firmware Upgrade**」をクリックします。 116 | 117 | ![Tasmota FW Upgrade](images/Tasmota%20FW%20Upgrade.png) 118 | 119 | ファームウェアアップグレードに関する画面が表示されるので、「**Upgrade by file upload**」のところにある「ファイルを選択」をクリックして、ダウンロードしておいたESPHome用のファームウェアを選択し、**ファイル選択の下にある「Start upgrade」をクリック**するとファームウェアアップグレードが始まります。 120 | 121 | ![Tasmota FW Upgrade Successful](images/Tasmota%20FW%20Upgrade%20Successful.png) 122 | 123 | このように、「Upload Successful」と表示されていれば問題なくアップグレードに成功しています。これで、ESPHome用のファームウェアをインストールすることができました。 124 | 125 | > [!TIP] 126 | > うまくファームウェアをインストールすることができない場合は、Tasmotaのコンソールで`SetOption78 1`コマンド(OTA互換性チェックを無効化するコマンド)を実行してからファームウェアのアップデートを行う必要があるかもしれません。 127 | 128 | 129 | ### 手順3. Wi-Fiネットワークの設定を行う 130 | ファームウェアのインストールが終わってプラグミニが再起動した後、自動的にWi-Fiネットワークに接続されない場合は、プラグミニの**フォールバックホットスポットに接続してWi-Fiネットワークを設定**するか、**Improv via BLEを使ってWi-Fiネットワークを設定**します。 131 | 132 | 133 | #### フォールバックホットスポットからWi-Fiネットワークを設定する 134 | プラグミニのフォールバックホットスポットのSSIDは、次のようになっているはずです:`switchbot-plug-mini-xxxxxx` 135 | 136 | フォールバックホットスポットに接続すると、自動的に設定画面が開くはずですので、そこからプラグミニを接続したいWi-Fiネットワークを設定します。 137 | 138 | > [!TIP] 139 | > 設定画面が自動的に表示されない場合は、ブラウザから手動で [http://192.168.4.1](http://192.168.4.1) にアクセスします。 140 | 141 | 142 | #### Improv via BLEを使ってWi-Fiネットワークを設定する 143 | 144 | [**Improv Wi-Fi**](https://www.improv-wifi.com/)のサイトにアクセスしてBLE経由でWi-Fiネットワークを設定します。 145 | 146 | Home Assistantをお使いでBluetooth統合を設定している場合、**自動的にImprov via BLEが検出される**ため、そこからWi-Fiネットワークを設定することもできます。 147 | 148 | 149 | ### 手順4. ESPHomeの設定を行う 150 | ESPHome Device Builderを使って、プラグミニの設定を変更できるように設定を行います。まだESPHome Device Builderがインストールされていない場合は、インストールしておく必要があります。 151 | 152 | 153 | #### ESPHome Device Builderをインストールする 154 | [**ESPHomeの公式ドキュメント**](https://esphome.io/guides/installing_esphome)にインストール方法が記載されているため、そちらをご覧ください。 155 | 156 | ESPHome Device BuilderはHome Assistantのアドオンとしても用意されているため、Home Assistant OSまたはHome Assistant Supervisedをお使いの方は、以下のボタンをクリックしてアドオンをインストールすることもできます。 157 | 158 | [![Open your Home Assistant instance and show the dashboard of an add-on.](https://my.home-assistant.io/badges/supervisor_addon.svg)](https://my.home-assistant.io/redirect/supervisor_addon/?addon=5c53de3b_esphome) 159 | 160 | 161 | #### デバイスの完全な制御を得る 162 | ![ESPHome Setup](images/ESPHome%20Setup.png) 163 | 164 | ESPHomeのダッシュボードを開くと、先ほどWi-Fiネットワークに接続したプラグミニが検出されるので、「**TAKE CONTROL**」をクリックすると、ESPHomeを使ってプラグミニを**完全に制御することができるように**なります。 165 | 166 | ![ESPHome Configuration Created Dialog](images/ESPHome%20Configuration%20Created%20Dialog.png) 167 | 168 | 途中で「Configuration created」と表示されたら、「**SKIP**」をクリックします。 169 | 170 | これで、ローカルにコピーされたプラグミニの設定ファイルを編集して、完全に制御できるようになりました。 171 | 172 | 173 | ### 手順5. 最初に変更しておくべき設定 174 | 完全に制御できるようになった後、狙い通りに使えるように、設定ファイルを少し変更しておくことをおすすめします。 175 | 176 | 177 | #### Wi-Fiネットワークに関する設定 178 | 初期状態の設定ファイルでは、Wi-Fiネットワークに関する設定は以下のようになっています。 179 | ```yaml 180 | # ... 181 | 182 | # Wi-Fiネットワークに関する設定 183 | wifi: 184 | # プラグミニが接続するWi-Fiネットワークの設定 185 | # ssid: !secret wifi_ssid 186 | # password: !secret wifi_password 187 | 188 | # プラグミニ起動後、一定の期間(デフォルトでは1分)Wi-Fiネットワークに 189 | # 接続できなかった場合に有効になるフォールバックホットスポット(アクセスポイントモード)の設定 190 | ap: 191 | # password: !secret ap_password # コメントを外して、パスワードを設定することをおすすめします。 192 | 193 | # ... 194 | ``` 195 | 196 | Wi-Fiネットワークに関する一部の設定はコメントアウトされているため、**このままインストールするとプラグミニがWi-Fiネットワークに正しく接続できない可能性**があります。そのため、SSIDとパスワード部分のコメントを外しておくことをおすすめします。 197 | 198 | また、デフォルトではフォールバックホットスポットのパスワードが設定されていないため、セキュリティ向上のためにパスワードを設定しておくことをおすすめします。 199 | 200 | 変更後の設定ファイルは以下のようになるはずです。 201 | ```yaml 202 | # ... 203 | 204 | # Wi-Fiネットワークに関する設定 205 | wifi: 206 | # プラグミニが接続するWi-Fiネットワークの設定 207 | ssid: !secret wifi_ssid 208 | password: !secret wifi_password 209 | 210 | # プラグミニ起動後、一定の期間(デフォルトでは1分)Wi-Fiネットワークに 211 | # 接続できなかった場合に有効になるフォールバックホットスポット(アクセスポイントモード)の設定 212 | ap: 213 | password: !secret ap_password # コメントを外して、パスワードを設定することをおすすめします。 214 | 215 | # ... 216 | ``` 217 | 218 | この設定では、Wi-Fiネットワークの設定が、`secrets.yaml`内で指定されたものを使用するようになっています。そのため、このファームウェアをインストールする前に、`secrets.yaml`が正しく設定されていることをご確認ください。 219 | 220 | まだ設定されていなければ、`secrets.yaml`を以下のように設定します。 221 | ```yaml 222 | # secrets.yaml内 223 | 224 | # ESPデバイスが接続するWi-FiのSSIDとパスワード 225 | wifi_ssid: "SSIDをここに入力します" 226 | wifi_password: "ネットワークパスワードをここに入力します" 227 | 228 | # ESPデバイスがフォールバックホットスポットモードで動作しているときに接続するためのパスワード 229 | ap_password: "フォールバックホットスポットに接続するためのパスワードをここに入力します" 230 | ``` 231 | 232 | 233 | #### Improv via BLEに関する設定 234 | 初期状態の設定ファイルでは、Improv via BLEに関する設定は以下のようになっています。 235 | ```yaml 236 | # ... 237 | 238 | # Bluetooth LEを使ってWi-Fiをセットアップできるようにする設定 239 | # 注意: このコンポーネントを使用していると内部温度が上昇するため、 240 | # このコンポーネントを無効化(コメントアウト)し、フォールバックホットスポットからWi-Fiを設定することをおすすめします。 241 | esp32_improv: 242 | authorizer: none 243 | 244 | # ... 245 | ``` 246 | 247 | 設定ファイル内のコメントにも書かれている通り、Improv via BLEコンポーネントを有効化していると**内部温度が上昇する現象を確認**しています。 248 | 249 | **デバイス温度の上昇は製品寿命に影響してきます**ので、Improv via BLEを使う予定がない場合は、以下のようにコメントアウトして無効化しておくことをおすすめします(もちろん削除しても問題ありません)。 250 | ```yaml 251 | # ... 252 | 253 | # Bluetooth LEを使ってWi-Fiをセットアップできるようにする設定 254 | # 注意: このコンポーネントを使用していると内部温度が上昇するため、 255 | # このコンポーネントを無効化(コメントアウト)し、フォールバックホットスポットからWi-Fiを設定することをおすすめします。 256 | #esp32_improv: 257 | # authorizer: none 258 | 259 | # ... 260 | ``` 261 | 262 | 263 | #### 設定変更が終わったらファームウェアをインストールする 264 | これらの設定変更が終わったら、ESPHomeのダッシュボードから目的のデバイスの右下にある「...」をクリックしてメニューを開いたら、「**Install**」をクリックします。 265 | 266 | > [!TIP] 267 | > 初めてESPHomeを使用する場合、編集した設定ファイルが正しいか不安になるかもしれません。 268 | > 269 | > その場合は、メニュー内の「**Validate**」をクリックすると、**設定ファイルが正しい状態になっていることをチェック**してくれます。 270 | > 271 | > **「INFO Configuration is valid!」と表示されれば設定ファイルは問題ありません**ので、インストールに進んで問題ありません。 272 | 273 | その後、インストール方法を聞かれるので「**Wirelessly**」をクリックすると、設定ファイルをもとにファームウェアのコンパイルが行われ、プラグミニにファームウェアがインストールされます。 274 | 275 | 問題なくインストールすることができたら、**ESPHomeでプラグミニを完全に制御することができるようになりました!** 276 | 277 | このままHome Assistantに追加して使ったりしても良いですし、設定ファイルを更新して機能を追加したりしても問題ありません。SwitchBotのクラウドからは完全に切り離されており、**プラグミニは真の意味で「あなたのもの」になったのです!** 278 | 279 | 280 | ### 手順6. 電力モニタリングセンサーのキャリブレーションを行う(オプション) 281 | 282 | ESPHomeで使えるようになったプラグミニはそのまま使うこともできますが、工場出荷時に行われたキャリブレーションデータは消えてしまっているので、正しい値を取得できるようにするためには**センサーのキャリブレーションを行う必要**があります。 283 | 284 | 電力モニタリングセンサーのキャリブレーションを行う方法については、[**ESPHomeの公式ドキュメント**](https://esphome.io/components/sensor/hlw8012#calibration)をご覧ください。 285 | 286 | キャリブレーションデータは、設定ファイル内の上部に、以下のように記載されています(初期状態では、私のプラグミニのキャリブレーションデータが設定されています)。 287 | ```yaml 288 | # ... 289 | 290 | # キャリブレーションデータ 291 | voltage_divider: "660.7973855893309" 292 | current_resistor: "0.0024013086148925913" 293 | current_multiply: "1.783420806116323" 294 | # キャリブレーションを行う際、電力メーターに表示される値からプラグミニ自体の消費電力(リレーをオンにした状態で約0.8W / 0.019A)を 295 | # 引いた値を使ってキャリブレーションを行ってください。 296 | # 297 | # キャリブレーションの方法については、以下の記事をご覧ください。 298 | # https://esphome.io/components/sensor/hlw8012#calibration 299 | 300 | # ... 301 | ``` 302 | 303 | キャリブレーションされた電力メーターの測定値に合わせるためのキャリブレーションデータ計算機が[**ESPHomeの公式ドキュメント**](https://esphome.io/components/sensor/hlw8012#calibration)にありますので、そちらをご利用ください。 304 | 305 | 306 | ### 手順7. HomeKitを設定する(HomeKitファームウェアのみ) 307 | 308 | HomeKit機能付きのファームウェアをインストールした場合、プラグミニを**Appleの「ホーム」に追加して制御する**ことができます。 309 | 310 | 追加で必要な設定は特になく、「ホーム」アプリのアクセサリ追加画面を開くとプラグミニ(`プラグミニのブリッジ`または`Plug Mini Bridge`)が表示されるはずです。セットアップコードは[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)のデフォルトコードである`159-35-728`を使用します(設定ファイルから変更できます)。 311 | 312 | スイッチの名前はデフォルトで`プラグ`または`Plug`になっていますが、「ホーム」アプリからお好みの名前に変更してください。 313 | 314 | > [!TIP] 315 | > 名前を変更した後にファームウェアを更新しても、「ホーム」アプリに表示される名前は変わりませんのでご安心ください。 316 | 317 | これらの設定が終わったら、必要なセットアップは全て完了です。お疲れ様でした! 318 | 319 | 320 | ## デフォルトの機能について 321 | ### LEDライトの表示について 322 | プラグミニには、白色と青色の2つのLEDライトが搭載されています。 323 | 324 | デフォルトのLEDライトの動作は、以下の通りです。 325 | 326 | 327 | #### 白色LEDライト 328 | リレースイッチの状態を表しています。 329 | 330 | LED消灯: リレースイッチが**オフ** 331 | 332 | LED点灯: リレースイッチが**オン** 333 | 334 | > [!NOTE] 335 | > `LED Brightness`が`LEDオフ`または`LED Off`に設定されている場合、リレースイッチの状態にかかわらずLEDは消灯状態となります。 336 | 337 | 338 | #### 青色LEDライト 339 | Wi-Fiネットワークの接続状況を表しています。 340 | 341 | LED消灯: Wi-Fiネットワークに**接続されている** 342 | 343 | LED点滅: Wi-Fiネットワークから**切断されている** 344 | 345 | > [!NOTE] 346 | > 青色LEDライトは、Wi-Fiネットワークの状態を常に確認できるように、`LED Brightness`設定の影響を受けません。 347 | > 348 | > つまり、`LED Brightness`が`明るい`または`Bright`以外に設定されていたとしても、Wi-Fiネットワークから切断されている間は100%の明るさで点滅します。 349 | 350 | 351 | ### 本体のボタンについて 352 | プラグミニには、ボタンが1つ搭載されています。 353 | 354 | デフォルトのボタンの動作は以下の通りです。 355 | 356 | 357 | #### ボタンを押してすぐ離したとき 358 | **50ミリ秒(0.05秒)以上500ミリ秒(0.5秒)以下の長さ**の間ボタンを押すと、**リレースイッチを切り替え**ます。 359 | 360 | 361 | #### ボタンを長押ししたとき 362 | **3秒以上10秒以下の長さ**の間ボタンを長押しすると、**プラグミニを再起動**します。 363 | 364 | 365 | #### 特定のタイミングで複数回押したとき(HomeKitファームウェアのみ) 366 | 以下の通りにボタンを操作すると、HomeKitのペアリングをリセットします。 367 | 368 | 1. 1秒以上ボタンを長押しする 369 | 2. 2秒以上ボタンを離したままにする 370 | 3. 上記手順をあと2回繰り返す 371 | 372 | 373 | ## Home Assistantに表示されるエンティティ名について 374 | デフォルトでは、**インストールしたファームウェアの言語にかかわらず、Home Assistantに表示されるエンティティ名は英語**になっています。 375 | 376 | これは、正しいエンティティIDが割り振られるように意図しているためです。 377 | 378 | Home AssistantのデフォルトエンティティIDは、ESPHomeの`friendly_name`および`name`プロパティからエンティティIDを決定しますが、**アルファベットと数字以外の文字が含まれていると、その部分は空として認識される**(例: `Wi-Fiシグナル` → `wi_fi`のように、日本語部分だけがなくなる)ため、目的のエンティティを探しづらくなってしまいます。 379 | 380 | 後からHome Assistant側でエンティティIDを変更することもできますが、すべてのエンティティIDを変更するのは非常に手間ですので、最初から英語のエンティティ名になるように設定しています。 381 | 382 | そのため、日本語のエンティティ名が良いのであれば、**Home Assistantから手動でエンティティの名前を変更してください。** 383 | 384 | 名前の日本語訳は以下の通りです(Home Assistantのデバイス設定画面に表示される順番に並んでいます)。 385 | 386 | | 英語名 | 日本語名 | 387 | |----------------------|--------------------| 388 | | Plug | プラグ | 389 | | Apparent Power | 皮相電力 | 390 | | Current | 電流 | 391 | | Power | 電力 | 392 | | Power Factor | 力率 | 393 | | Total Daily Energy | 一日の累計消費電力量 | 394 | | Total Energy | 累計消費電力量 | 395 | | Total Monthly Energy | 一ヵ月の累計消費電力量 | 396 | | Voltage | 電圧 | 397 | | Blue LED | 青色LED | 398 | | LED Brightness | LEDの明るさ | 399 | | Reboot | 再起動 | 400 | | White LED | 白色LED | 401 | | Internal Temperature | 内部温度 | 402 | | Uptime | アップタイム | 403 | | Wi-Fi Signal | Wi-Fiシグナル | 404 | 405 | もちろん、これらの翻訳はあくまで一例ですので、お好きなようにカスタマイズしていただいて構いません。 406 | 407 | 408 | ## クレジット 409 | - [**SwitchbOTA**](https://github.com/kendallgoto/switchbota) 410 | - OTAでプラグミニのファームウェア書き換え 411 | - [**ESPHome**](https://github.com/esphome/esphome) 412 | - [ESPHomeプラットフォーム・ドキュメント](https://esphome.io/) 413 | - [**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome) 414 | - ESPHome上でのHomeKit 415 | - [**@halomakes**](https://gist.github.com/halomakes) 416 | - プラグミニ用設定ファイル作成の元となった、プラグミニ用のESPHome設定ファイル: [switchbot-plug-mini-esphome.yml](https://gist.github.com/halomakes/8be3976a034ad32e37e9c3b315d25b64) 417 | - [**Home Assistant**](https://github.com/home-assistant/) 418 | - [Home Assistantプラットフォーム・ドキュメント](https://www.home-assistant.io/) 419 | -------------------------------------------------------------------------------- /switchbot-plug-mini-w2001401-homekit-enabled.yaml: -------------------------------------------------------------------------------- 1 | # SwitchBot Plug Mini (JP) HomeKit for ESPHome by taikun114 2 | 3 | substitutions: 4 | device_name: switchbot-plug-mini 5 | friendly_name: SwitchBot Plug Mini 6 | fw_version: 1.2.0 7 | 8 | # Model number 9 | model: "W2001401" 10 | 11 | # Calibration data 12 | voltage_divider: "660.7973855893309" 13 | current_resistor: "0.0024013086148925913" 14 | current_multiply: "1.783420806116323" 15 | # When calibrating, use the value shown on the power meter minus the power consumption of the 16 | # Plug Mini itself (about 0.8W / 0.019A with the relay turned on) to calibrate. 17 | # 18 | # See the document below for calibration instructions. 19 | # https://esphome.io/components/sensor/hlw8012#calibration 20 | 21 | # Configuration for ESPHome 22 | esphome: 23 | name: ${device_name} 24 | comment: Energy Monitoring Smart Plug (${model}) 25 | friendly_name: ${friendly_name} 26 | name_add_mac_suffix: true 27 | platformio_options: 28 | board_build.flash_mode: dio 29 | project: 30 | name: SwitchBot (Customized by taikun114).Plug Mini JP HomeKit (${model}) 31 | version: ${fw_version} 32 | 33 | # Configuration for ESP32 34 | esp32: 35 | board: esp32-c3-devkitm-1 36 | variant: ESP32C3 37 | framework: 38 | type: esp-idf 39 | sdkconfig_options: 40 | CONFIG_COMPILER_OPTIMIZATION_SIZE: y 41 | CONFIG_LWIP_MAX_SOCKETS: "16" 42 | CONFIG_MBEDTLS_HKDF_C: y 43 | 44 | # Configuration for external components 45 | external_components: 46 | source: github://rednblkx/HAP-ESPHome@main 47 | refresh: 0s 48 | 49 | # Configuration to read this configuration file locally 50 | dashboard_import: 51 | package_import_url: github://taikun114/SwitchBot-Plug-Mini-for-ESPHome/switchbot-plug-mini-w2001401-homekit-enabled.yaml@v1.2.0 52 | import_full_config: true 53 | 54 | # Configuration for showing logs 55 | logger: 56 | 57 | # Configuration for API 58 | api: 59 | 60 | # Configuration for OTA (Over-The-Air) updates 61 | ota: 62 | - platform: esphome 63 | 64 | # Configuration for Wi-Fi network 65 | wifi: 66 | # Configure the Wi-Fi network the Plug Mini will connect to 67 | # ssid: !secret wifi_ssid 68 | # password: !secret wifi_password 69 | 70 | # Configure the fallback hotspot (access point mode), which is activated when 71 | # Wi-Fi network is unable to connect for a certain period of time (1 minute by default) 72 | ap: 73 | # password: !secret ap_password # Remove comment and set a password is recommended. 74 | 75 | # Blinking Blue LED when disconnected from Wi-Fi network 76 | on_connect: # When connected to Wi-Fi network 77 | - light.turn_off: blue_led 78 | on_disconnect: # When disconnected from Wi-Fi network 79 | - while: 80 | condition: 81 | not: 82 | wifi.connected: 83 | then: 84 | - light.turn_on: 85 | id: blue_led 86 | brightness: 100% 87 | - delay: 500ms 88 | - light.turn_off: blue_led 89 | - delay: 500ms 90 | 91 | # Configure a captive portal that allows users to change Wi-Fi settings 92 | # and update firmware on the Plug Mini when connected to a fallback hotspot 93 | captive_portal: 94 | 95 | # Configuration to allow Wi-Fi setup using Bluetooth LE 96 | # Note: Since using this component increases internal temperature, 97 | # it is recommended to disable (comment out) this component and configure Wi-Fi from the fallback hotspot. 98 | esp32_improv: 99 | authorizer: none 100 | 101 | # Configuration for HomeKit Bridge 102 | homekit_base: 103 | meta: 104 | name: Plug Mini Bridge 105 | manufacturer: SwitchBot 106 | model: ${model} 107 | fw_rev: ${fw_version} 108 | setup_code: 159-35-728 109 | 110 | # Configuration for HomeKit 111 | homekit: 112 | # Switches to add to HomeKit 113 | switch: 114 | # Relay switch 115 | - id: relay 116 | meta: 117 | name: Plug 118 | manufacturer: SwitchBot 119 | model: ${model} 120 | fw_rev: ${fw_version} 121 | 122 | # See below for more information on HomeKit configurations. 123 | # https://github.com/rednblkx/HAP-ESPHome#readme-ov-file 124 | 125 | # Configuration for time 126 | time: 127 | # Synchronize time with Home Assistant through API connection 128 | - platform: homeassistant 129 | id: homeassistant_time 130 | 131 | on_time: # When a specific time came 132 | # Reset the total monthly energy sensor at 0 am on the first day of every month 133 | - seconds: 0 134 | minutes: 0 135 | hours: 0 136 | days_of_month: 1 137 | then: 138 | - sensor.integration.reset: total_monthly_energy 139 | 140 | # Configuration for buttons 141 | button: 142 | # Reboot the Plug Mini 143 | - platform: restart 144 | name: Reboot 145 | id: reboot 146 | 147 | # Reset HomeKit pairings 148 | - platform: homekit_base 149 | factory_reset: 150 | id: reset_homekit_pairings 151 | internal: true 152 | 153 | # Configuration for binary sensors 154 | binary_sensor: 155 | # Detects that a button on the Plug Mini unit has been pressed 156 | - platform: gpio 157 | id: power_button 158 | pin: 159 | number: GPIO02 160 | inverted: true 161 | internal: true 162 | 163 | on_click: # When the button is pressed 164 | # Toggle the relay switch when the button is pressed and immediately released. 165 | - min_length: 50ms 166 | max_length: 500ms 167 | then: 168 | - switch.toggle: relay 169 | 170 | # Reboot the Plug Mini when the button is held between 3 and 10 seconds. 171 | - min_length: 3s 172 | max_length: 10s 173 | then: 174 | - button.press: reboot 175 | 176 | on_multi_click: # When a button is pressed multiple times at specific times 177 | # Reset HomeKit pairings by pressing and holding the button for at least 1 second and releasing it, 178 | # and waiting at least 2 seconds before pressing and holding the button again for at least 1 second, 179 | # and repeating the same procedure 3 times. 180 | - timing: 181 | - ON for at least 1s 182 | - OFF for at least 2s 183 | - ON for at least 1s 184 | - OFF for at least 2s 185 | - ON for at least 1s 186 | - OFF for at least 2s 187 | then: 188 | - button.press: reset_homekit_pairings 189 | 190 | # Configuration for sensors 191 | sensor: 192 | # Connection strength to Wi-Fi access point 193 | - platform: wifi_signal 194 | name: Wi-Fi Signal 195 | update_interval: 30s 196 | 197 | # Time of last power on 198 | - platform: uptime 199 | type: timestamp 200 | name: Uptime 201 | 202 | # Internal temperature of Plug Mini 203 | - platform: internal_temperature 204 | name: Internal Temperature 205 | update_interval: 30s 206 | 207 | # Power monitoring sensors 208 | - platform: hlw8012 209 | sel_pin: 210 | number: GPIO20 211 | inverted: true 212 | cf_pin: GPIO18 213 | cf1_pin: GPIO19 214 | current_resistor: ${current_resistor} 215 | voltage_divider: ${voltage_divider} 216 | power: 217 | name: Power 218 | unit_of_measurement: W 219 | id: wattage 220 | accuracy_decimals: 1 # Number of decimal points 221 | current: 222 | name: Current 223 | unit_of_measurement: A 224 | id: current 225 | filters: 226 | - multiply: ${current_multiply} 227 | voltage: 228 | name: Voltage 229 | unit_of_measurement: V 230 | id: voltage 231 | accuracy_decimals: 2 # Number of decimal points 232 | initial_mode: VOLTAGE # Initial measurement mode. VOLTAGE or CURRENT 233 | change_mode_every: 1 234 | # Number of measurements before switching between current and voltage measurement modes 235 | # (after switching, the initial value is discarded, so the set value + 1 measurement is taken) 236 | 237 | update_interval: 5s 238 | # About sensor update intervals 239 | # 240 | # The power sensor is updated at the interval set by update_interval. 241 | # The current sensor and voltage sensor update intervals depend on the value set in change_mode_every. 242 | # 243 | # If change_mode_every: 1 or more: 244 | # Update every: (value set in change_mode_every + 1) * 2 * value set in update_interval (in seconds) 245 | # For example, if change_mode_every: 1 and update_interval: 1s, then (1 + 1) * 2 * 1s = update every 4 seconds. 246 | # 247 | # If change_mode_every: “never”: 248 | # The sensor in the measurement mode set in initial_mode is updated every update_interval value. 249 | # Unspecified sensors will not be updated. For example, if initial_mode: VOLTAGE, the current sensor will not be updated. 250 | 251 | # Apparent power 252 | # Note: This sensor is disabled by default because the accuracy is very low due to the different timing of current and voltage measurements. 253 | - platform: template 254 | name: Apparent Power 255 | lambda: return id(voltage).state * id(current).state; 256 | device_class: apparent_power 257 | unit_of_measurement: VA 258 | state_class: "measurement" 259 | accuracy_decimals: 2 # Number of decimal points 260 | update_interval: 20s # Please match the update intervals of the current and voltage sensors 261 | disabled_by_default: true 262 | 263 | # Power factor 264 | # Note: This sensor is disabled by default because the accuracy is very low due to the different timing of current and voltage measurements. 265 | - platform: template 266 | name: Power Factor 267 | lambda: !lambda |- 268 | if ((id(wattage).state / (id(voltage).state * id(current).state)) > 1) { 269 | return 1; // Return 1 if it is over 1 270 | } else { 271 | return id(wattage).state / (id(voltage).state * id(current).state); // Return the calculated value as is if it is less than 1 272 | } 273 | device_class: power_factor 274 | state_class: "measurement" 275 | accuracy_decimals: 2 # Number of decimal points 276 | update_interval: 20s # Please match the update intervals of the current and voltage sensors 277 | disabled_by_default: true 278 | 279 | # Total daily energy consumption (reset daily at 0 am) 280 | - platform: total_daily_energy 281 | name: Total Daily Energy 282 | power_id: wattage 283 | accuracy_decimals: 3 # Number of decimal points 284 | filters: 285 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 286 | unit_of_measurement: kWh 287 | 288 | # Total monthly energy consumption (reset monthly at 0 am on the first day of every month) 289 | - platform: integration 290 | name: Total Monthly Energy 291 | id: total_monthly_energy 292 | sensor: wattage 293 | time_unit: h 294 | restore: true 295 | state_class: total_increasing 296 | device_class: energy 297 | accuracy_decimals: 3 # Number of decimal points 298 | filters: 299 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 300 | unit_of_measurement: kWh 301 | 302 | # Total energy consumption since the Plug Mini was first set up with ESPHome 303 | - platform: integration 304 | name: Total Energy 305 | sensor: wattage 306 | time_unit: h 307 | restore: true 308 | state_class: total_increasing 309 | device_class: energy 310 | accuracy_decimals: 3 # Number of decimal points 311 | filters: 312 | - multiply: 0.001 # Convert unit of measurement from Wh to kWh 313 | unit_of_measurement: kWh 314 | 315 | # Configuration for switches 316 | switch: 317 | # Relay switch 318 | - platform: gpio 319 | name: Plug 320 | pin: GPIO06 321 | id: relay 322 | device_class: outlet 323 | restore_mode: RESTORE_DEFAULT_OFF # Relay switch state at startup of Plug Mini 324 | # Available configuration: 325 | # 326 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 327 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 328 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 329 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 330 | # ALWAYS_OFF: Always turn off 331 | # ALWAYS_ON: Always turn on 332 | 333 | on_turn_on: # When the relay switch is turned on 334 | - light.turn_on: 335 | id: white_led 336 | brightness: !lambda |- 337 | if (id(led_brightness).state == "Bright") { 338 | return 1; // When the brightness setting of the LED light is set to “Bright”, the White LED is turned on at 100% brightness 339 | } else if (id(led_brightness).state == "Dim") { 340 | return 0.5; // When the brightness setting of the LED light is set to “Dim”, the White LED is turned on at 50% brightness. 341 | } else { 342 | return 0; // When the brightness setting of the LED light is set to other than the above (LED Off), the White LED is turned on at 0% brightness (turned off) 343 | } 344 | 345 | on_turn_off: # When the relay switch is turned off 346 | - light.turn_off: white_led 347 | 348 | # Configuration for select 349 | select: 350 | # Brightness setting for built-in Plug Mini LED light 351 | - platform: template 352 | name: LED Brightness 353 | id: led_brightness 354 | icon: mdi:brightness-6 355 | optimistic: true 356 | options: 357 | - Bright 358 | - Dim 359 | - LED Off 360 | initial_option: Bright 361 | restore_value: true 362 | entity_category: config 363 | on_value: # When the state is set 364 | then: 365 | - lambda: |- 366 | if ( x == "LED Off") { 367 | id(white_led).turn_off().perform(); // Turn off the White LED 368 | } else if ( x == "Dim") { 369 | if (id(relay).state) { 370 | id(white_led).turn_on().set_brightness(0.5).perform(); // Turn on the White LED at 50% brightness only when the relay switch is on. 371 | } 372 | } else if ( x == "Bright") { 373 | if (id(relay).state) { 374 | id(white_led).turn_on().set_brightness(1.0).perform(); // Turn on the White LED at 100% brightness only when the relay switch is on. 375 | } 376 | } 377 | 378 | # Configuration of output 379 | output: 380 | # White LED output 381 | - platform: ledc 382 | id: white_output 383 | pin: GPIO07 384 | inverted: true 385 | frequency: 19531Hz 386 | 387 | # Blue LED output 388 | - platform: ledc 389 | id: blue_output 390 | pin: GPIO08 391 | inverted: true 392 | frequency: 19531Hz 393 | 394 | # Configuration for lights 395 | light: 396 | # White LED light 397 | - platform: monochromatic 398 | output: white_output 399 | name: White LED 400 | id: white_led 401 | icon: mdi:led-off 402 | entity_category: config 403 | default_transition_length: 250ms 404 | restore_mode: RESTORE_DEFAULT_OFF # White LED light state at startup of Plug Mini 405 | # Available configuration: 406 | # 407 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 408 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 409 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 410 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 411 | # ALWAYS_OFF: Always turn off 412 | # ALWAYS_ON: Always turn on 413 | 414 | # Blue LED light 415 | - platform: monochromatic 416 | output: blue_output 417 | name: Blue LED 418 | id: blue_led 419 | icon: mdi:led-off 420 | entity_category: config 421 | default_transition_length: 250ms 422 | restore_mode: ALWAYS_OFF # Blue LED light state at startup of Plug Mini 423 | # Available configuration: 424 | # 425 | # RESTORE_DEFAULT_OFF: Restore state if possible, turn off if not possible 426 | # RESTORE_DEFAULT_ON: Restore state if possible, turn on if not possible 427 | # RESTORE_INVERTED_DEFAULT_OFF: Restore inverted from previous state if possible, turn off if not possible 428 | # RESTORE_INVERTED_DEFAULT_ON: Restore inverted from previous state if possible, turn on if not possible 429 | # ALWAYS_OFF: Always turn off 430 | # ALWAYS_ON: Always turn on 431 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwitchBot Plug Mini for ESPHome 2 | **English** | [日本語](docs/README-ja.md) 3 | 4 | ![banner](docs/images/banner.png) 5 | 6 | This repository contains instructions and configuration files for using the Plug Mini, the power monitoring smart plug from SwitchBot, with [**ESPHome**](https://esphome.io/) (and [**Home Assistant**](https://www.home-assistant.io/)). 7 | 8 | > [!CAUTION] 9 | > All work should be done **at your own risk**. 10 | > 11 | > Using the SwitchBot Plug Mini with the ESPHome is **not an official use of the SwitchBot** and **you will not be able to receive any support from SwitchBot.** 12 | > 13 | > Also, the procedure described here includes rewriting the firmware, **which can damage the product if the procedure is done incorrectly or unsuccessfully**. 14 | > 15 | > It is recommended that you perform the work only if you are able to handle the any situation on your own. 16 | 17 | 18 | ## Table of Contents 19 | - [Supported models](#supported-models) 20 | - [Models that have been confirmed to work](#models-that-have-been-confirmed-to-work) 21 | - [Models that are highly likely to work](#models-that-are-highly-likely-to-work) 22 | - [To use SwitchBot Plug Mini with ESPHome](#to-use-switchbot-plug-mini-with-esphome) 23 | - [Preparation: Download firmware for ESPHome](#preparation-download-firmware-for-esphome) 24 | - [Firmware Variants](#firmware-variants) 25 | - [Step 1. Install Tasmota firmware using SwitchbOTA](#step-1-install-tasmota-firmware-using-switchbota) 26 | - [Step 2. Install ESPHome firmware](#step-2-install-esphome-firmware) 27 | - [Step 3. Configure the Wi-Fi network](#step-3-configure-the-wi-fi-network) 28 | - [Configuring the Wi-Fi network from a fallback hotspot](#configuring-the-wi-fi-network-from-a-fallback-hotspot) 29 | - [Configuring the Wi-Fi network using Improv via BLE](#configuring-the-wi-fi-network-using-improv-via-ble) 30 | - [Step 4. Configure the ESPHome](#step-4-configure-the-esphome) 31 | - [Install ESPHome Device Builder](#install-esphome-device-builder) 32 | - [Take full control of your device](#take-full-control-of-your-device) 33 | - [Step 5. Configuration that should be changed first](#step-5-configuration-that-should-be-changed-first) 34 | - [Configuration for Wi-Fi network](#configuration-for-wi-fi-network) 35 | - [Configuration for Improv via BLE](#configuration-for-improv-via-ble) 36 | - [Install the firmware after changing the configurations](#install-the-firmware-after-changing-the-configurations) 37 | - [Step 6. Calibrate the power monitoring sensor (Optional)](#step-6-calibrate-the-power-monitoring-sensor-optional) 38 | - [Step 7. Configure HomeKit (HomeKit firmware only)](#step-7-configure-homekit-homekit-firmware-only) 39 | - [About default functionality](#about-default-functionality) 40 | - [About LED lights indications](#about-led-lights-indications) 41 | - [White LED light](#white-led-light) 42 | - [Blue LED light](#blue-led-light) 43 | - [About the button on the unit](#about-the-button-on-the-unit) 44 | - [When the button is pressed and released immediately](#when-the-button-is-pressed-and-released-immediately) 45 | - [When the button is long-pressed](#when-the-button-is-long-pressed) 46 | - [When pressed multiple times at specific timings (HomeKit firmware only)](#when-pressed-multiple-times-at-specific-timings-homekit-firmware-only) 47 | - [About entity names that appear in the Home Assistant](#about-entity-names-that-appear-in-the-home-assistant) 48 | - [Credits](#credits) 49 | 50 | 51 | ## Supported models 52 | 53 | ### Models that have been confirmed to work 54 | - **W2001401**: [**Plug Mini (JP) HomeKit Enabled**](https://www.switchbot.jp/products/switchbot-plugmini-homekit) 55 | 56 | 57 | ### Models that are highly likely to work 58 | - **W1901400**: [**Plug Mini (US)**](https://www.switch-bot.com/products/switchbot-plug-mini) 59 | - **W1901401**: [**Plug Mini (US) HomeKit Enabled**](https://www.switch-bot.com/products/switchbot-plug-mini-homekit-enabled) 60 | - **W2001400**: [**Plug Mini (JP)**](https://www.switchbot.jp/products/switchbot-plug-mini) 61 | 62 | It might be necessary to change the configuration file for use with these models, since it is unknown if all models have exactly the same hardware configuration. 63 | 64 | > [!IMPORTANT] 65 | > **HomeKit functionality will be lost** on HomeKit-enabled models if you perform the procedures described here. 66 | > 67 | > To complement this, there is also firmware that adds HomeKit functionality using “[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)”, but **please note that the factory configured HomeKit information was lost, so the hardware will be recognized as non-certified hardware**. 68 | 69 | 70 | ## To use SwitchBot Plug Mini with ESPHome 71 | 72 | ### Preparation: Download firmware for ESPHome 73 | You can download the firmware from the [**Releases page**](https://github.com/taikun114/SwitchBot-Plug-Mini-for-ESPHome/releases). 74 | 75 | 76 | #### Firmware Variants 77 | Depending on the functions and languages, several firmware versions are available. 78 | 79 | - For W2001401 80 | - English 81 | - **switchbot-plug-mini-w2001401-vX.X.X.bin** 82 | - Basic firmware file. 83 | - **switchbot-plug-mini-w2001401-homekit-enabled-vX.X.X.bin** 84 | - In addition to the basic functions, this firmware file adds HomeKit functions using “[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)". 85 | - Japanese 86 | - **switchbot-plug-mini-w2001401-vX.X.X-ja.bin** 87 | - Basic firmware file. 88 | - **switchbot-plug-mini-w2001401-homekit-enabled-vX.X.X-ja.bin** 89 | - In addition to the basic functions, this firmware file adds HomeKit functions using “[**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome)". 90 | 91 | Change logs can be found [**here**](CHANGELOG.md). 92 | 93 | 94 | > [!NOTE] 95 | > [**There is a report that there is almost no difference between US models W1901400 and W1901401 except in software**](https://github.com/kendallgoto/switchbota/issues/19), so it is highly likely that the JP models W2001400 and W2001401 are also similar and it is likely that the same firmware / configuration files may can be used for the W2001400 and W2001401. 96 | 97 | 98 | ### Step 1. Install Tasmota firmware using SwitchbOTA 99 | You will need to first replace the firmware with Tasmota firmware using "[**SwitchbOTA**](https://github.com/kendallgoto/switchbota)", an open source tool that allows replacing firmware OTA (Over The Air) without disassembling the Plug Mini. 100 | 101 | Please refer to [**README in SwitchbOTA**](https://github.com/kendallgoto/switchbota#readme-ov-file) for the firmware replacement procedure. 102 | 103 | Once the Tasmota firmware installation is complete and Wi-Fi is configured, proceed to the next step. 104 | 105 | > [!WARNING] 106 | > **Please do not try to upgrade** Tasmota to v12 or any later version. The new partition layout introduced in Tasmota v12 is not compatible with ESPHome and you will not be able to install the ESPHome firmware. 107 | > 108 | > Also, to revert to Tasmota v11 or earlier, you will need to disassemble the unit and perform a serial flash, so it is strongly recommended that you do not change the version of Tasmota installed by SwitchbOTA. 109 | 110 | 111 | ### Step 2. Install ESPHome firmware 112 | ![Tasmota Home](docs/images/Tasmota%20Home.png) 113 | 114 | Access the IP address of the Plug Mini that installed the Tasmota firmware and you will see the Tasmota page, click “**Firmware Upgrade**”. 115 | 116 | ![Tasmota FW Upgrade](docs/images/Tasmota%20FW%20Upgrade.png) 117 | 118 | You will see firmware upgrade screen. Click “Choose file” under “**Upgrade by file upload**”, select the firmware for ESPHome that you already downloaded, and then **click “Start upgrade" under the file selection** to start the firmware upgrade. 119 | 120 | ![Tasmota FW Upgrade Successful](docs/images/Tasmota%20FW%20Upgrade%20Successful.png) 121 | 122 | If you see “Upload Successful” as shown here, the upgrade was successful without any problems. Now, you have installed the firmware for ESPHome. 123 | 124 | > [!TIP] 125 | > If you are unsuccessful in installing the firmware, you may need to run the `SetOption78 1` command (to disable the OTA compatibility check) in the Tasmota console before updating the firmware. 126 | 127 | 128 | ### Step 3. Configure the Wi-Fi network 129 | After the firmware is installed and the Plug Mini has rebooted, if it does not automatically connect to the Wi-Fi network, **connect to the fallback hotspot on the Plug Mini to configure the Wi-Fi network**, or **use Improv via BLE to configure the Wi-Fi network**. 130 | 131 | #### Configuring the Wi-Fi network from a fallback hotspot 132 | The SSID of the fallback hotspot on the Plug Mini should be: `switchbot-plug-mini-xxxxxx` 133 | 134 | Once you connect to the fallback hotspot, the configuration screen should open automatically, and from there you can configure the Wi-Fi network to which you want to connect the Plug Mini. 135 | 136 | > [!TIP] 137 | > If the configuration screen does not open automatically, access [http://192.168.4.1](http://192.168.4.1) manually from the browser. 138 | 139 | 140 | #### Configuring the Wi-Fi network using Improv via BLE 141 | 142 | Visit the [**Improv Wi-Fi**](https://www.improv-wifi.com/) website to configure your Wi-Fi network via BLE. 143 | 144 | If you are using Home Assistant and have set up Bluetooth integration, **it will automatically discover Improv via BLE**, and you can also configure your Wi-Fi network from there. 145 | 146 | 147 | ### Step 4. Configure the ESPHome 148 | Use ESPHome Device Builder to configure the Plug Mini so that you can change its configuration. If ESPHome Device Builder is not already installed, you will need to install it. 149 | 150 | 151 | #### Install ESPHome Device Builder 152 | See the [**official ESPHome documentation**](https://esphome.io/guides/installing_esphome) for installation instructions. 153 | 154 | ESPHome Device Builder is also available as an add-on for Home Assistant, so if you are using Home Assistant OS or Home Assistant Supervised, you can also install the add-on by clicking the button below. 155 | 156 | [![Open your Home Assistant instance and show the dashboard of an add-on.](https://my.home-assistant.io/badges/supervisor_addon.svg)](https://my.home-assistant.io/redirect/supervisor_addon/?addon=5c53de3b_esphome) 157 | 158 | 159 | #### Take full control of your device 160 | ![ESPHome Setup](docs/images/ESPHome%20Setup.png) 161 | 162 | When you open the ESPHome dashboard, it will detect the Plug Mini that you just connected to your Wi-Fi network, and when you click “**TAKE CONTROL**” **you will be able to take full control** of your Plug Mini using ESPHome. 163 | 164 | ![ESPHome Configuration Created Dialog](docs/images/ESPHome%20Configuration%20Created%20Dialog.png) 165 | 166 | When you see “Configuration created” during the process, click “**SKIP**”. 167 | 168 | You now have full control to edit the locally copied Plug Mini configuration file. 169 | 170 | 171 | ### Step 5. Configuration that should be changed first 172 | After you get full control, it is recommended that you make a few changes to the configuration file so that you can use it as you want it to be used. 173 | 174 | 175 | #### Configuration for Wi-Fi network 176 | In the default configuration file, the configuration for the Wi-Fi network is as below. 177 | ```yaml 178 | # ... 179 | 180 | # Configuration for Wi-Fi network 181 | wifi: 182 | # Configure the Wi-Fi network the Plug Mini will connect to 183 | # ssid: !secret wifi_ssid 184 | # password: !secret wifi_password 185 | 186 | # Configure the fallback hotspot (access point mode), which is activated when 187 | # Wi-Fi network is unable to connect for a certain period of time (1 minute by default) 188 | ap: 189 | # password: !secret ap_password # Remove comment and set a password is recommended. 190 | 191 | # ... 192 | ``` 193 | 194 | Some configurations for Wi-Fi networks are commented out, so **if installed unchanged, the Plug Mini may not be able to properly connect to a Wi-Fi network**. For this reason, uncommenting the SSID and password sections is recommended. 195 | 196 | Also, there is no password set for the fallback hotspot by default, so it is recommended that a password be set for improved security. 197 | 198 | The changed configuration file should look like below. 199 | ```yaml 200 | # ... 201 | 202 | # Configuration for Wi-Fi network 203 | wifi: 204 | # Configure the Wi-Fi network the Plug Mini will connect to 205 | ssid: !secret wifi_ssid 206 | password: !secret wifi_password 207 | 208 | # Configure the fallback hotspot (access point mode), which is activated when 209 | # Wi-Fi network is unable to connect for a certain period of time (1 minute by default) 210 | ap: 211 | password: !secret ap_password # Remove comment and set a password is recommended. 212 | 213 | # ... 214 | ``` 215 | 216 | This configuration uses the Wi-Fi network settings specified in the `secrets.yaml`. So, before installing this firmware, please make sure that your `secrets.yaml` is correctly configured. 217 | 218 | If not, configure the `secrets.yaml` as below. 219 | ```yaml 220 | # In the secrets.yaml 221 | 222 | # Wi-Fi SSID and password that ESP devices will connect to 223 | wifi_ssid: "Enter your SSID here" 224 | wifi_password: "Enter your network password here" 225 | 226 | # Password to connect when ESP devices is running in fallback hotspot mode 227 | ap_password: "Enter the password to connect to the fallback hotspot here" 228 | ``` 229 | 230 | 231 | #### Configuration for Improv via BLE 232 | In the default configuration file, the configuration for Improv via BLE is as below. 233 | ```yaml 234 | # ... 235 | 236 | # Configuration to allow Wi-Fi setup using Bluetooth LE 237 | # Note: Since using this component increases internal temperature, 238 | # it is recommended to disable (comment out) this component and configure Wi-Fi from the fallback hotspot. 239 | esp32_improv: 240 | authorizer: none 241 | 242 | # ... 243 | ``` 244 | 245 | As noted in the comments in the configuration file, **I have noticed an increase in internal temperature** when the Improv via BLE component is enabled. 246 | 247 | Since the **increase in device temperature will affect product lifetime**, if you do not plan to use Improv via BLE, it is recommended to comment out and disable it as shown below (of course, removing it is no problem). 248 | ```yaml 249 | # ... 250 | 251 | # Configuration to allow Wi-Fi setup using Bluetooth LE 252 | # Note: Since using this component increases internal temperature, 253 | # it is recommended to disable (comment out) this component and configure Wi-Fi from the fallback hotspot. 254 | #esp32_improv: 255 | # authorizer: none 256 | 257 | # ... 258 | ``` 259 | 260 | 261 | #### Install the firmware after changing the configurations 262 | Once you have made these changes, open the menu from the ESPHome dashboard by clicking on the “...” button in the lower right corner of the target device and click “**Install**”. 263 | 264 | > [!TIP] 265 | > If you are using ESPHome for the first time, you may be concerned that the configuration file you have edited is correct. 266 | > 267 | > If so, click “**Validate**” in the menu and **it will check that the configuration file is in the correct state**. 268 | > 269 | > **If you see “INFO Configuration is valid!”, the configuration file is valid** and you can proceed with the installation. 270 | 271 | Then, it will ask how to install the firmware, and clicking “**Wirelessly**” will compile the firmware based on the configuration file, and the firmware will be installed to the Plug Mini. 272 | 273 | Once installed without problems, **you now have full control of the Plug Mini in ESPHome!** 274 | 275 | You can use it as is by adding it to the Home Assistant, or you can update the configuration file to add additional functionality. It is completely disconnected from the SwitchBot cloud, and the **Plug Mini is now truly “yours”!** 276 | 277 | 278 | ### Step 6. Calibrate the power monitoring sensor (Optional) 279 | The Plug Mini that is now ready for use with ESPHome can be used as is, but the calibration data done at the factory was lost, so the **sensor needs to be calibrated** in order to get the correct values. 280 | 281 | See the [**official ESPHome documentation**](https://esphome.io/components/sensor/hlw8012#calibration) for instructions on how to calibrate the power monitoring sensor. 282 | 283 | The calibration data is found at the top in the configuration file as below (by default, the calibration data for my Plug Mini is configured). 284 | ```yaml 285 | # ... 286 | 287 | # Calibration data 288 | voltage_divider: "660.7973855893309" 289 | current_resistor: "0.0024013086148925913" 290 | current_multiply: "1.783420806116323" 291 | # When calibrating, use the value shown on the power meter minus the power consumption of the 292 | # Plug Mini itself (about 0.8W / 0.019A with the relay turned on) to calibrate. 293 | # 294 | # See the document below for calibration instructions. 295 | # https://esphome.io/components/sensor/hlw8012#calibration 296 | 297 | # ... 298 | ``` 299 | 300 | The calibration data calculator is available in the [**official ESPHome documentation**](https://esphome.io/components/sensor/hlw8012#calibration) to help you match the measurements of a calibrated power meter. 301 | 302 | 303 | ### Step 7. Configure HomeKit (HomeKit firmware only) 304 | 305 | If firmware with HomeKit functionality is installed, you can add the Plug Mini to **Apple “Home” for control**. 306 | 307 | There is no additional setup required, and the Plug Mini (`Plug Mini Bridge` or `プラグミニのブリッジ`) should appear when you open the “Home” app's Add Accessory screen. The setup code is `159-35-728`, which is the default code for [**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome) (can be changed from the configuration file). 308 | 309 | The name of the switch is `Plug` or `プラグ` by default, but you can change it to your preferred name from the “Home” app. 310 | 311 | > [!TIP] 312 | > Do not worry, if you update the firmware after changing the name, the name displayed in the “Home” app will not change. 313 | 314 | Once these are done, all necessary setups are complete. Well done! 315 | 316 | 317 | ## About default functionality 318 | ### About LED lights indications 319 | The Plug Mini has two LED lights, one white and one blue. 320 | 321 | The default LED lights behave as below. 322 | 323 | 324 | #### White LED light 325 | Indicates the state of the relay switch. 326 | 327 | LED off: Relay switch is **off**. 328 | 329 | LED on: Relay switch is **on**. 330 | 331 | > [!NOTE] 332 | > If `LED Brightness` is set to `LED Off` or `LEDオフ`, the LED will be off regardless of the state of the relay switch. 333 | 334 | 335 | #### Blue LED light 336 | Indicates the connection status of the Wi-Fi network. 337 | 338 | LED off: **Connected** to Wi-Fi network 339 | 340 | LED blinking: **Disconnected** from Wi-Fi network 341 | 342 | > [!NOTE] 343 | > The blue LED light is not affected by the `LED Brightness` setting to ensure that the Wi-Fi network status is always visible. 344 | > 345 | > This means that even if the `LED Brightness` is set to anything other than `Bright` or `明るい`, it will still blink at 100% brightness while disconnected from the Wi-Fi network. 346 | 347 | 348 | ### About the button on the unit 349 | The Plug Mini has a single button. 350 | 351 | The default button behave as below. 352 | 353 | 354 | #### When the button is pressed and released immediately 355 | Pressing the button for **a length of time between 50 milliseconds (0.05 seconds) and 500 milliseconds (0.5 seconds)** will **toggle the relay switch**. 356 | 357 | 358 | #### When the button is long-pressed 359 | Press and hold the button for **a length of time between 3 and 10 seconds** will **reboot the Plug Mini**. 360 | 361 | 362 | #### When pressed multiple times at specific timings (HomeKit firmware only) 363 | Press the button as below to reset HomeKit pairings. 364 | 365 | 1. Press and hold the button for at least 1 second 366 | 2. Keep the button released for at least 2 seconds 367 | 3. Repeat the above steps two more times 368 | 369 | 370 | ## About entity names that appear in the Home Assistant 371 | By default, **entity names appearing in the Home Assistant are in English, regardless of the language of the firmware installed**. 372 | 373 | 374 | This is because it is intended that the correct entity ID be assigned. 375 | 376 | The default entity ID of Home Assistant determines the entity ID from the `friendly_name` and `name` properties from ESPHome, but if any characters other than alphabetic and numeric are included, the part is recognized as empty (e.g., `Wi-Fiシグナル` → `wi_fi`, only the Japanese part will be lost), making it difficult to find the desired entity. 377 | 378 | You can change the entity ID later on the Home Assistant side, but it is very time-consuming to change all the entity IDs, so it is configured to be an English entity name from the beginning. 379 | 380 | Therefore, if you prefer Japanese entity names, **please rename the entities manually from the Home Assistant.** 381 | 382 | Japanese translations of the names are as below (listed in the order in which they appear on the device configuration screen of the Home Assistant). 383 | 384 | | English names | Japanese names | 385 | |----------------------|--------------------| 386 | | Plug | プラグ | 387 | | Apparent Power | 皮相電力 | 388 | | Current | 電流 | 389 | | Power | 電力 | 390 | | Power Factor | 力率 | 391 | | Total Daily Energy | 一日の累計消費電力量 | 392 | | Total Energy | 累計消費電力量 | 393 | | Total Monthly Energy | 一ヵ月の累計消費電力量 | 394 | | Voltage | 電圧 | 395 | | Blue LED | 青色LED | 396 | | LED Brightness | LEDの明るさ | 397 | | Reboot | 再起動 | 398 | | White LED | 白色LED | 399 | | Internal Temperature | 内部温度 | 400 | | Uptime | アップタイム | 401 | | Wi-Fi Signal | Wi-Fiシグナル | 402 | 403 | Of course, these translations are just examples and can be customized as you like. 404 | 405 | 406 | ## Credits 407 | - [**SwitchbOTA**](https://github.com/kendallgoto/switchbota) 408 | - Plug Mini firmware replacement with OTA 409 | - [**ESPHome**](https://github.com/esphome/esphome) 410 | - [ESPHome Platform and Documentation](https://esphome.io/) 411 | - [**HAP-ESPHome**](https://github.com/rednblkx/HAP-ESPHome) 412 | - HomeKit on ESPHome 413 | - [**@halomakes**](https://gist.github.com/halomakes) 414 | - Original ESPHome configuration file for Plug Mini that was used to create the configuration file for Plug Mini: [switchbot-plug-mini-esphome.yml](https://gist.github.com/halomakes/8be3976a034ad32e37e9c3b315d25b64) 415 | - [**Home Assistant**](https://github.com/home-assistant/) 416 | - [Home Assistant Platform and Documentation](https://www.home-assistant.io/) 417 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------