2025年2月17日 星期一

Home Assistant上MQTT電燈和開關測試

 畫面:


開關:


Add-ons:

安裝File editor和Mosquitto。


Devices&services:

安裝MQTT


/homeassistant/configuration.yaml:
# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

mqtt:
    - light:
        - name: Bed room light
          command_topic: "bed_room/light"
        - name: Live room light
          command_topic: "live_room/light"
    - switch:
        - name: Bed room switch
          command_topic: "bed_room/switch"
        - name: Live room switch
          command_topic: "live_room/switch"
    - binary_sensor:
        - name: Windows contact
          state_topic: "home-assistant/window/contact"
          value_template: "{%if is_state(entity_id,\"on\")-%}OFF{%-else-%}ON{%-endif%}"

  


/homeassistant/automations.yaml

- id: '1739746357824'
  alias: bed light turn on
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - switch.bed_room_switch
    from: 'off'
    to: 'on'
  conditions: []
  actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.bed_room_light
  mode: single
- id: '1739746513220'
  alias: bed light turn off
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - switch.bed_room_switch
    from: 'on'
    to: 'off'
  conditions: []
  actions:
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.bed_room_light
  mode: single

沒有留言:

張貼留言