ページへ戻る

− Links

 印刷 

ミンティア[MINTIA] で WiFi 6ボタンスイッチを作った のソース :: XOOPS マニア

UsersWiki:nao-pon/blog/2021-06-15のソース

  
#navi
RIGHT:&rsslink(../);
#boxdate

* ミンティア[MINTIA] で WiFi 6ボタンスイッチを作った :-D [#i7d337be]
RIGHT:&tag(WiFi,ESP-32,DIY,HomeAssistant,Hass.io,ESPHome);

Google Home や Alexa と HomeAssistant を統合しているので、声で大体のことはできる・・・けど。
声を発声して、アシスタントに認識させるのが、面倒くさいと感じる。なんてわがままな! :lol: 
だって、正しく認識してくれないと、もう一度言い直したり、見当違いのスイッチを ON/OFF されたり・・・

そこで、やっぱり物理ボタンですよ!

ちょうど手元にミンティアとESP-32が転がっていて・・・。ん?これ入るんじゃね?って思ったところ。

おぉー!やっぱりピッタリじゃないですか!厚みが若干きついけど。

で、結果こうなりました。やっぱりボタンで操作できるのは快適です。USB電源はいるけどね。

&ref(site://modules/xelfinder/index.php/view/10/DSC_3857.JPG,left,mw:180,mh:180);&ref(site://modules/xelfinder/index.php/view/8/DSC_3856.JPG,left,mh:180);

#clear
ボタンの穴あけを少し失敗したけど、今度作るときはもう少しきちんと作ろう!

ボタンを押すと青いLEDが光ります。

** いるもの ((価格は購入時のもの)) [#ibd9ea71]
- [[ESP-32 モジュール:https://ja.aliexpress.com/item/32823593448.html]] 474円 ((Aliexpress で買ったけど、技適マークはついていました。))
- [[タクトスイッチ:https://www.marutsu.co.jp/pc/i/599871/]] 10円 × 6
- ミンティアの空き容器
- 適当なユニバーサル基板
- 2mmポリウレタン銅線 適宜

** ESPHome の設定 [#j6fe7996]

esp32_ble_tracker は、手元に Qmote-S があったので、うまく使えないかな?と思って試してみたけど、検知範囲が狭くてほぼ使えなかった。残念。

#code(yaml){{
substitutions:
  devicename: switch_box_11

esphome:
  name: $devicename
  platform: ESP32
  board: wemos_d1_mini32
  on_boot:
    - priority: 1000
      then:
        - while:
            condition:
              not:
                api.connected:
            then:
            - switch.turn_on: led
            - delay: 500ms 
            - switch.turn_off: led
            - delay: 500ms

wifi:
  networks: !include common/wifi.networks.yaml
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap: !include common/wifi.ap.yaml

  manual_ip:
    static_ip: 192.168.1.xx
    gateway: 192.168.1.1
    subnet: 255.255.255.0

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

esp32_ble_tracker:
  id: ble_tracker

  on_ble_manufacturer_data_advertise:
    - mac_address: 88:4A:XX:XX:DE:52
      manufacturer_id: 004C
      then:
        - lambda: |-
            if (id(qmote_de52_click).state == false) {
              id(qmote_de52_click).publish_state(true);
              id(qmote_de52_click).publish_state(false);
            }
    - mac_address: 88:4A:XX:XX:99:BB
      manufacturer_id: 004C
      then:
        - lambda: |-
            if (id(qmote_99bb_click).state == false) {
              id(qmote_99bb_click).publish_state(true);
              id(qmote_99bb_click).publish_state(false);
            }
    - mac_address: 88:4A:XX:XX:9F:03
      manufacturer_id: 004C
      then:
        - lambda: |-
            if (id(qmote_9f03_click).state == false) {
              id(qmote_9f03_click).publish_state(true);
              id(qmote_9f03_click).publish_state(false);
            }
  
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO23
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn1"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: gpio
    pin:
      number: GPIO19
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn2"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: gpio
    pin:
      number: GPIO18
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn3"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: gpio
    pin:
      number: GPIO33
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn4"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: gpio
    pin:
      number: GPIO05
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn5"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: gpio
    pin:
      number: GPIO26
      inverted: True
      mode: INPUT_PULLUP
    name: "$devicename btn6"
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: template
    id: qmote_de52_click
    name: "$devicename Qmote de52 Click"
    filters:
      delayed_off: 800ms
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: template
    id: qmote_99bb_click
    name: "$devicename Qmote 99bb Click"
    filters:
      delayed_off: 800ms
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led
  - platform: template
    id: qmote_9f03_click
    name: "$devicename Qmote 9f03 Click"
    filters:
      delayed_off: 800ms
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led

sensor:
  - platform: wifi_signal
    name: "$devicename WiFi"
    update_interval: 60s
    unit_of_measurement: "%"
    filters:
      - lambda: x = 2 * (x + 100); if (x < 0) {x = 0;} else if (x > 100) {x = 100;} return x;

switch:
  - platform: restart
    name: "$devicename Restart"
  - platform: gpio
    pin:
      number: GPIO2
    name: "$devicename LED"
    id: led
}}

RIGHT:&font(90%){&page_comments;};
#navi

  

  • nao-pon/blog/2021-06-15 のバックアップソース(No. All)