IMG_5188.JPG

之前有寫了一篇用Broadlink RF整合電燈吊扇進入Home assistant

另外還有吊扇燈,

這個一樣從學習RF碼開始,

不懂請看上方連結,

截圖 2021-08-22 下午7.17.44.png

或是進入yaml模式直接copy以下程式,

service: remote.learn_command
data:
  device: light
  command: 'on'
  command_type: rf
target:
  entity_id: remote.shu_fang_yao_kong_remote

 

執行服務就可以學到設備light的on訊號,

接下來到packages建立study_light.yaml,請先參考Home assistant介面介紹

程式碼連結:https://github.com/percy10442/study_light

 

這思路一樣是建立一個模擬的switch開關,

因為這個燈亮暗都是同一個按鍵,

判斷on/off就需要用一個虛擬的input_boolean,

假如啟動RF的on的服務,

input_boolean連動變成on,

虛擬開關的狀態就是on,

反之則是off,

不過這也表示你額外用原本的遙控器控制會讓on/off狀態錯亂。

 

switch:
  - platform: template
    switches:
      study_light:   #實體名稱
        value_template: "{{ states('input_boolean.study_light_state') }}"    #虛擬開關狀態用input_boolean.study_light_state模擬
        turn_on:    #書房燈亮執行的腳本
          service: script.study_light_on
        turn_off:    #書房燈暗執行的腳本
          service: script.study_light_off
            
input_boolean:
  study_light_state:
    name: Study Room Light State

script:
    study_light_on:
      alias: Study room Light On   #書房燈亮時執行的動作
      sequence:
        - service: input_boolean.turn_on  #讓虛擬開關狀態變on
          entity_id: input_boolean.study_light_state
        - service: remote.send_command    #發射RF讓燈亮的訊號
          data:
            device: light
            command: 'on'
          target:
            entity_id: remote.shu_fang_yao_kong_remote


    study_light_off:    #書房燈暗時執行的動作
      alias: Study room Light Off
      sequence:
        - service: input_boolean.turn_off   #讓虛擬開關狀態變off
          entity_id: input_boolean.study_light_state
        - service: remote.send_command   #發射RF讓燈暗的訊號
          data:
            device: light
            command: 'on'
          target:
            entity_id: remote.shu_fang_yao_kong_remote

 

接下來加入實體就好了

Home Assistant教學總目錄

 

如果我的文章對你有幫助,歡迎送我喝杯咖啡喔

Buy Me A Coffee 建立免費、漂亮的個人贊助頁面,接收 PayPal 小額付款


arrow
arrow
    全站熱搜

    派西 發表在 痞客邦 留言(0) 人氣()