2024/07/14

ESPHome: HTTP Request 컴포넌트



HA를 경유해 주방후드 제어하던걸 주방후드 플러그의 esphome에 web서버를 설치하고 주방 벽스위치로 HTTP Request 컴포넌트를 통해 직접 제어하는 걸로 변경.
이 경우 HA서버 없이 제어 가능하고 외부연결이 끊겨도 제어가능.
 

HA 구성요소를 통한 esphome에서 주방후드 제어:

esphome:
  name: zemi-kitchen
  area: Kitchen
esp8266:
  board: esp01_1m
binary_sensor:
  - platform: gpio
    id: button3
    name: "Kitchen Bottom"
    pin:
      number: GPIO16
      inverted: true
    on_multi_click:
    - timing:
        - ON for at most 0.5s
        - OFF for at least 0.01s
      then:
        - light.toggle: light3
    - timing:
        - ON for 0.6s to 3s
        - OFF for at least 0.1s
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.hood


HTTP Request 컴포넌트를 이용한 주방후드 제어:

esphome:
  name: zemi-kitchen
  area: Kitchen
  on_boot:
    priority: 600.0
    then:
      - switch.template.publish:
          id: hood
          state: ON
esp8266:
  board: esp01_1m
http_request:
  useragent: esphome/device
  verify_ssl: false
binary_sensor:
  - platform: gpio
    id: button3
    name: "Kitchen Bottom"
    pin:
      number: GPIO16
      inverted: true
    on_multi_click:
    - timing:
        - ON for at most 0.5s
        - OFF for at least 0.01s
      then:
        - light.toggle: light3
    - timing:
        - ON for 0.6s to 3s
        - OFF for at least 0.1s
      then:
        - switch.toggle: hood
switch:
  - platform: template
    name: "Hood Switch"
    id: hood
    turn_on_action:
      - http_request.post: "http://192.168.1.212/switch/neo12_relay/turn_on"
      - switch.template.publish:
          id: hood
          state: ON
    turn_off_action:
      - http_request.post: "http://192.168.1.212/switch/neo12_relay/turn_off"
      - switch.template.publish:
          id: hood
          state: OFF