Dreame L20 Ultra 在NodeRed中設定分區掃地+掃地模式+TTS+Line設定方式

最近入手了Dreame L20 Ultra
也透過群內朋友們的方式加入了HA
在摸索了一陣之後把分區以及設定模式弄到NR裡面並傳到HK去執行


並將掃地訊息傳到Line通知
image
並透過TTS廣播

前置作業

  1. 先到Dreame GitHub安裝Beta v2.0.0b9版本,下載完後解壓縮放到/homeassistant/custom_components底下


    然後重開HA到整合新增Dreame Vacuum ,Beta版本可以直接登入Dreame 的app帳號

    HACS Line Notify 安裝申請Line Token 請參考
    Line Notify Token + 攝影機截圖 Line訊息傳送 NR應用方法
    Edge安裝方式請參考
    Edge TTS Node-Red 亂數語音+亂數訊息分享

  2. 到助手新增按鈕,依照你的分區設定(N+1)*4個按鈕,以我的為例我分了4個區域所以我建了20個按鈕


    按鈕依照 區域+模式分類
    以我的來說是 全屋 房間1 房間2 房間3 房間4 每個房間4個模式 掃地 拖地 掃拖 先掃後拖分類
    ****************************
    這邊說一個小賤招 不熟json的的請不要照這方法去弄
    /config/.storage/input_button
    這邊存放的是助手新增的按鈕資料,懶得一個一個新增的可以直接將下面設定貼進去
    注意我下方圖片標示的游標位置 先將游標移到那邊再複製下方的設定再貼上去
    不然可能會因為[ ]位置不對而造成問題
    所以不熟的請不要這樣操作還是乖乖的一個一個手動新增
    貼上後存檔 重開HA然後再去助手那邊確認是否有出現20個按鈕
    ****************************

      },
      {
        "id": "all_room_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "All Room Sweeping"
      },
      {
        "id": "all_room_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "All Room Mopping"
      },
      {
        "id": "all_room_sweeping_and_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "All Room Sweeping And Mopping"
      },
      {
        "id": "all_room_mopping_after_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "All Room Mopping After Sweeping"
      },
      {
        "id": "room1_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 1 Sweeping"
      },
      {
        "id": "room1_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 1 Mopping"
      },
      {
        "id": "room1_sweeping_and_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 1 Sweeping And Mopping"
      },
      {
        "id": "room1_mopping_after_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 1 Mopping After Sweeping"
      },
      {
        "id": "room2_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 2 Sweeping"
      },
      {
        "id": "room2_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 2 Mopping"
      },
      {
        "id": "room2_sweeping_and_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 2 Sweeping And Mopping"
      },
      {
        "id": "room2_mopping_after_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 2 Mopping After Sweeping"
      },
      {
        "id": "room3_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 3 Sweeping"
      },
      {
        "id": "room3_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 3 Mopping"
      },
      {
        "id": "room3_sweeping_and_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 3 Sweeping And Mopping"
      },
      {
        "id": "room3_mopping_after_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 3 Mopping After Sweeping"
      },
      {
        "id": "room4_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 4 Sweeping"
      },
      {
        "id": "room4_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 4 Mopping"
      },
      {
        "id": "room4_sweeping_and_mopping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 4 Sweeping And Mopping"
      },
      {
        "id": "room4_mopping_after_sweeping",
        "icon": "mdi:robot-vacuum",
        "name": "Room 4 Mopping After Sweeping"

  1. 確認按鍵有新增後就將按鈕傳過去HK
    下面為homekit.yaml設定的內容 有用homekit.yaml的請直接複製貼上就好,
    設定好存檔重開HA掃碼進HK
    請注意Port有沒有跟你原本的重複有重複的請改掉Port
    另外使用HomeKit Bridge的就自己傳過去吧
-  
  port: 51811
  name: 掃地機
  filter:

    include_entities:
      - input_button.all_room_sweeping
      - input_button.all_room_mopping
      - input_button.all_room_sweeping_and_mopping
      - input_button.all_room_mopping_after_sweeping
      - input_button.room_1_sweeping
      - input_button.room_1_mopping
      - input_button.room_1_sweeping_and_mopping
      - input_button.room_1_mopping_after_sweeping
      - input_button.room_2_sweeping
      - input_button.room_2_mopping
      - input_button.room_2_sweeping_and_mopping
      - input_button.room_2_mopping_after_sweeping
      - input_button.room_3_sweeping
      - input_button.room_3_mopping
      - input_button.room_3_sweeping_and_mopping
      - input_button.room_3_mopping_after_sweeping
      - input_button.room_4_sweeping
      - input_button.room_4_mopping
      - input_button.room_4_sweeping_and_mopping
      - input_button.room_4_mopping_after_sweeping
 
  entity_config:
     input_button.all_room_sweeping:
      name: "全屋掃地"
     input_button.all_room_mopping:
      name: "全屋拖地"
     input_button.all_room_sweeping_and_mopping:
      name: "全屋掃拖"
     input_button.all_room_mopping_after_sweeping:
      name: "全屋先掃後拖"
     input_button.room_1_sweeping:
      name: "房間1掃地"
     input_button.room_1_mopping:
      name: "房間1拖地"
     input_button.room_1_sweeping_and_mopping:
      name: "房間1掃拖"
     input_button.room_1_mopping_after_sweeping:
      name: "房間1先掃後拖"
     input_button.room_2_sweeping:
      name: "房間2掃地"
     input_button.room_2_mopping:
      name: "房間2拖地"
     input_button.room_2_sweeping_and_mopping:
      name: "房間2掃拖"
     input_button.room_2_mopping_after_sweeping:
      name: "房間2先掃後拖"
     input_button.room_3_sweeping:
      name: "房間3掃地"
     input_button.room_3_mopping:
      name: "房間3拖地"
     input_button.room_3_sweeping_and_mopping:
      name: "房間3掃拖"
     input_button.room_3_mopping_after_sweeping:
      name: "房間3先掃後拖"
     input_button.room_4_sweeping:
      name: "房間4掃地"
     input_button.room_4_mopping:
      name: "房間4拖地"
     input_button.room_4_sweeping_and_mopping:
      name: "房間4掃拖"
     input_button.room_4_mopping_after_sweeping:
      name: "房間4先掃後拖"

中文名稱可以依照自己喜好去做修改

  1. Dreame Vacuum設定檢查
    這邊需要確認幾個設定是否正確
    Cleaning Sequence 還有 Customized Cleaning 都需要打開才可以
    如果沒有打開,設定模式的幾個會用到的實體會變成不可用 這點請注意

這邊是設定每個區域的清掃次數,請依照你的需求自己修改


這邊是設定拖地時用的拖布濕度,一樣依照你的需求自己修改

這邊是依照你的分區設定清掃順序設定後可以在地圖上面看到


這邊可以看到目前設定的清潔模式

以上這些在掃地機回到基站的時候都是可用狀態
如果掃地機開始清掃都會變成不可用為正常現象

  1. 到這邊前置作業都差不多了再來就是NR的設定方式

    這是我的NR設定
    下面的圖是我會分享給大家的完整流

Function內容如下

var roomMapping = new Map([
    ["input_button.all_room_sweeping", { roomid: 0, mode: "sweeping" }],
    ["input_button.all_room_mopping", { roomid: 0, mode: "mopping" }],
    ["input_button.all_room_sweeping_and_mopping", { roomid: 0, mode: "sweeping_and_mopping" }],
    ["input_button.all_room_mopping_after_sweeping", { roomid: 0, mode: "mopping_after_sweeping" }],
    ["input_button.room_1_sweeping", { roomid: 1, mode: "sweeping" }],
    ["input_button.room_1_mopping", { roomid: 1, mode: "mopping" }],
    ["input_button.room_1_sweeping_and_mopping", { roomid: 1, mode: "sweeping_and_mopping" }],
    ["input_button.room_1_mopping_after_sweeping", { roomid: 1, mode: "mopping_after_sweeping" }],
    ["input_button.room_2_sweeping", { roomid: 2, mode: "sweeping" }],
    ["input_button.room_2_mopping", { roomid: 2, mode: "mopping" }],
    ["input_button.room_2_sweeping_and_mopping", { roomid: 2, mode: "sweeping_and_mopping" }],
    ["input_button.room_2_mopping_after_sweeping", { roomid: 2, mode: "mopping_after_sweeping" }],
    ["input_button.room_3_sweeping", { roomid: 3, mode: "sweeping" }],
    ["input_button.room_3_mopping", { roomid: 3, mode: "mopping" }],
    ["input_button.room_3_sweeping_and_mopping", { roomid: 3, mode: "sweeping_and_mopping" }],
    ["input_button.room_3_mopping_after_sweeping", { roomid: 3, mode: "mopping_after_sweeping" }],
    ["input_button.room_4_sweeping", { roomid: 4, mode: "sweeping" }],
    ["input_button.room_4_mopping", { roomid: 4, mode: "mopping" }],
    ["input_button.room_4_sweeping_and_mopping", { roomid: 4, mode: "sweeping_and_mopping" }],
    ["input_button.room_4_mopping_after_sweeping", { roomid: 4, mode: "mopping_after_sweeping" }]
]);

var mappingResult = roomMapping.get(msg.topic) || { roomid: 0, mode: "sweeping_and_mopping" };

var entityIds = [];
var cleaningMode = mappingResult.mode;
var zhTWZone = "";
var zhTWMode = "";

if (mappingResult.roomid === 0) {
    entityIds = ["select.dreamebot_l20_ultra_room_1_cleaning_mode", "select.dreamebot_l20_ultra_room_2_cleaning_mode", "select.dreamebot_l20_ultra_room_3_cleaning_mode", "select.dreamebot_l20_ultra_room_4_cleaning_mode"];
    msg.payload_segments = {"segments": [1, 2, 3, 4]};
    zhTWZone = "全屋";
} else {
    entityIds = [`select.dreamebot_l20_ultra_room_${mappingResult.roomid}_cleaning_mode`];
    msg.payload_segments = {"segments": mappingResult.roomid};
    // Map roomid to corresponding zone
    var roomidToZoneMap = {
        1: "房間1",
        2: "房間2",
        3: "房間3",
        4: "房間4"
    };
    zhTWZone = roomidToZoneMap[mappingResult.roomid] || "未知區域";
}

// Map cleaningMode to corresponding mode in zh-TW
var modeToZhTWMap = {
    "sweeping": "掃地模式",
    "mopping": "拖地模式",
    "sweeping_and_mopping": "掃拖模式",
    "mopping_after_sweeping": "先掃後拖"
};

zhTWMode = modeToZhTWMap[cleaningMode] || "未知模式";

msg.payload_target = {
    "entity_id": entityIds
};

msg.payload_setroommode = {
    "entity_id": msg.payload_target.entity_id,
    "option": cleaningMode
};

msg.payload_tts = {
  "message": `掃地機開始掃地,清掃區域 ${zhTWZone},模式為 ${zhTWMode}`,
  "cache": true,
  "options": {
    "volume": "+100%",
    "voice": "zh-TW-HsiaoChenNeural", // or use randomVoice if needed
    "pitch": "+0Hz",
    "rate": "+0%"
  }
};
msg.payload_line = { "message": "掃地機開始掃地\n清掃區域為:" + zhTWZone + "\n模式為:" + zhTWMode};

return msg;

roomMapping 這邊對應的是input_button是哪個按鍵被按下
依照對應的按鍵取出 房間ID 以及 掃地模式
roomid=0 代表全屋, =1 代表房間1, 依此類推如果你的區域不是4個請自己增減相對應的

如果你的區域不是4個請修改這段裡面的
msg.payload_segments = {“segments”: [1, 2, 3, 4]};

if (mappingResult.roomid === 0) {
    entityIds = ["select.dreamebot_l20_ultra_room_1_cleaning_mode", "select.dreamebot_l20_ultra_room_2_cleaning_mode", "select.dreamebot_l20_ultra_room_3_cleaning_mode", "select.dreamebot_l20_ultra_room_4_cleaning_mode"];
    msg.payload_segments = {"segments": [1, 2, 3, 4]};
    zhTWZone = "全屋";

roomidToZoneMap 這邊修改成你要的房間名稱

    entityIds = [`select.dreamebot_l20_ultra_room_${mappingResult.roomid}_cleaning_mode`];
    msg.payload_segments = {"segments": mappingResult.roomid};
    // Map roomid to corresponding zone
    var roomidToZoneMap = {
        1: "房間1",
        2: "房間2",
        3: "房間3",
        4: "房間4"
    };

6.各節點設定內容
按鈕的共20個


執行掃地房間與模式選擇

執行掃地

喇叭音量設定

TTS設定

Line通知設定

因超出文章字數限制
完整Floww請到此查看

以上為本次分享
希望能幫到需要的朋友們

1個讚

上面的方法按鍵太多
所以想把分區改成類似TV選輸入源的方式
原本使用input select來寫但是在HK中顯示出來的都是開關
後來參考E大的說明要改用 Universal media player
但可能是我資質太差一直搞不定
後來用了一些歪招透過smartir去設定



終於把想要的功能弄出來
配合上面的分享內容再加上smartir來完成我要的效果

前置作業

  1. 需在HACS安裝smartir,大部分人應該都有安裝了這邊就不另外說明
    沒有安裝的可以參考 Kris Smartir教學
    複製下列json放到 custom_components/smartir/codes/media_player/xxxx.json
    xxxx你可以自己隨便選一個不衝突的數字 我自己用的是1164.json
{
  "manufacturer": "Logitech",
  "supportedModels": [
    "Dreame L20 Ultra"
  ],
  "supportedController": "Broadlink",
  "commandsEncoding": "Base64",
  "commands": {
    "sources": {
      "全屋": "",
      "房間1": "",
      "房間2": "",
      "房間3": "",
      "房間4": "",
      "空": ""
    }
  }
}

  1. 創建需要用到的元件
    設定內容看你要放到 /config/configruaction.yaml 還是 packages裡面都可以
    依照你自己習慣去放
    我自己是放在/config/packages/dreamel20ultra.yaml裡面
    yaml 內容如下
smartir:
media_player:
  - platform: smartir
    name: L20掃地模式
    unique_id: l20_sweeping_mode
    device_code: 1164
    controller_data: remote.rm4c_pro
    power_sensor: switch.tp_link_power_strip_2186_zhui_mi_l20cha_zuo
  - platform: smartir
    name: L20拖地模式
    unique_id: l20_mopping_mode
    device_code: 1164
    controller_data: remote.rm4c_pro
    power_sensor: switch.tp_link_power_strip_2186_zhui_mi_l20cha_zuo
  - platform: smartir
    name: L20掃拖模式
    unique_id: l20_sweeping_and_mopping_mode
    device_code: 1164
    controller_data: remote.rm4c_pro
    power_sensor: switch.tp_link_power_strip_2186_zhui_mi_l20cha_zuo
  - platform: smartir
    name: L20先掃後拖模式
    unique_id: l20_mopping_after_sweeping_mode
    device_code: 1164
    controller_data: remote.rm4c_pro
    power_sensor: switch.tp_link_power_strip_2186_zhui_mi_l20cha_zuo

sensor:
  - platform: template
    sensors:
      l20_sweeping_source:
        friendly_name: "Dreame L20掃地模式狀態"
        value_template: "{{ state_attr('media_player.ls20_sao_di_mo_shi', 'source') }}"
  - platform: template
    sensors:
      l20_mopping_source:
        friendly_name: "Dreame L20拖地模式狀態"
        value_template: "{{ state_attr('media_player.l20_tuo_di_mo_shi', 'source') }}"
  - platform: template
    sensors:
      l20_mopping_after_sweeping_source:
        friendly_name: "Dreame L20先掃後拖模式狀態"
        value_template: "{{ state_attr('media_player.l20_xian_sao_hou_tuo_mo_shi', 'source') }}"
  - platform: template
    sensors:
      l20_sweeping_and_mopping_source:
        friendly_name: "Dreame L20掃拖模式狀態"
        value_template: "{{ state_attr('media_player.l20_sao_tuo_mo_shi', 'source') }}"

smartir 設定裡面的
power_sensor: 隨便找個給他不影響使用,我是用接L20的插座來用
device_code: 1164 看你上面的json給的編號是什麼改成那個編號
確認沒有問題後就可以重開HA讓新建的元件能夠生效

  1. 將media player傳到HK備用
    使用homekit bridge的請自行勾選傳過去
    homekit.yaml設定內容如下
-  
  port: 51811
  name: 掃地機
  filter:

    include_entities:
      - media_player.ls20_sao_di_mo_shi
      - media_player.l20_tuo_di_mo_shi
      - media_player.l20_xian_sao_hou_tuo_mo_shi
      - media_player.l20_sao_tuo_mo_shi

  entity_config:
     media_player.ls20_sao_di_mo_shi:
      name: "掃地模式"
     media_player.l20_tuo_di_mo_shi:
      name: "拖地模式"
     media_player.l20_xian_sao_hou_tuo_mo_shi:
      name: "先掃後拖模式"
     media_player.l20_sao_tuo_mo_shi:
      name: "掃拖模式"

改好重開HA

4.設定NR flow


弄4個 events: state 節點裡面用剛剛創的4個sensor當判斷

function內容如下

var roomid;
switch (msg.payload) {
    case "全屋":
        roomid = "all_room";
        break;
    case "房間1":
        roomid = "room_1";
        break;
    case "房間2":
        roomid = "room_2";
        break;
    case "房間3":
        roomid = "room_3";
        break;
    case "房間4":
        roomid = "room_4";
        break;
    default:
        roomid = "unknown_room";
}

var mode;
switch (msg.topic) {
    case "sensor.l20_sweeping_source":
        mode = "_sweeping";
        break;
    case "sensor.l20_mopping_source":
        mode = "_mopping";
        break;
    case "sensor.l20_sweeping_and_mopping_source":
        mode = "_sweeping_and_mopping";
        break;
    case "sensor.l20_mopping_after_sweeping_source":
        mode = "_mopping_after_sweeping";
        break;
    default:
        mode = "_unknown_mode";
}

var entity_id = "input_button." + roomid + mode;
msg.payload_entityID = { "entity_id": entity_id };

// 新的判斷條件
var sourceMedia;
switch (msg.topic) {
    case "sensor.l20_sweeping_source":
        sourceMedia = "media_player.ls20_sao_di_mo_shi";
        break;
    case "sensor.l20_mopping_source":
        sourceMedia = "media_player.l20_tuo_di_mo_shi";
        break;
    case "sensor.l20_mopping_after_sweeping_source":
        sourceMedia = "media_player.l20_xian_sao_hou_tuo_mo_shi";
        break;
    case "sensor.l20_sweeping_and_mopping_source":
        sourceMedia = "media_player.l20_sao_tuo_mo_shi";
        break;
    default:
        sourceMedia = "unknown_media_player";
}

msg.payload_resetsource = { "entity_id": sourceMedia, "source": "空" };

return msg;

執行掃地的 call service 節點設定


清空模式的 call service 節點設定

會多一個清空模式主要是選單沒辦法重複選同樣的
所以在執行你選的房間後需要讓他跳到空
這樣下次操作同一個房間的時候才不會無法動作

另外如果要改房間名稱
需要注意 smartit json的名稱 function裡面的名稱都要跟著改

以上希望能幫到需要的人

2個讚