Advertisement
xangin

Vacuum X10+ HA automations & scripts

Aug 6th, 2023 (edited)
1,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 19.62 KB | None | 0 0
  1. # 將檔案放在package內
  2. # 這邊有做以下自動化&腳本:
  3. # 1. 先掃地後再自動拖地
  4. # 2. 根據房門開關來決定清掃哪些區域
  5. # 3. 掃地的區域順序與拖地的順序不同
  6. # 4. 拖地完成後會清洗兩次拖布再烘乾兩次
  7. # 有用額外的input boolean來做判斷以及用notify做line通知
  8. ###############################################################################
  9. #                               Automation
  10. ###############################################################################
  11.  
  12. automation:
  13.   - id: vacuum_button_click_start_clean
  14.     alias: vacuum_button_click_start_clean
  15.     description: 掃地機-按鈕後開始掃地
  16.     trigger:
  17.       - platform: state
  18.         entity_id: input_button.start_vacuum
  19.       - platform: state
  20.         entity_id: sensor.click_vacuumctrl_action
  21.         to: 'on'      
  22.     condition:
  23.       - condition: state
  24.         entity_id: vacuum.xiaomi_x10
  25.         state: 'docked'
  26.     action:
  27.       - service: vacuum.set_fan_speed
  28.         data:
  29.           entity_id: vacuum.xiaomi_x10
  30.           fan_speed: 'Turbo'
  31.       - service: select.select_option
  32.         data:
  33.           option: sweeping
  34.         target:
  35.           entity_id: select.xiaomi_x10_cleaning_mode          
  36.       - service: input_boolean.turn_on
  37.         data:
  38.           entity_id: input_boolean.vacuum_start_clean  
  39.       - service: notify.simon_home_notify
  40.         data:
  41.           message: "開始掃地"          
  42.       - service: script.turn_on
  43.         data:
  44.           entity_id: script.choose_clean_area  
  45.      
  46.   - id: vacuum_button_click_start_mopping
  47.     alias: vacuum_button_click_start_mopping
  48.     description: 掃地機-按鈕後開始拖地
  49.     trigger:
  50.       - platform: state
  51.         entity_id: input_button.strat_mop
  52.       - platform: state
  53.         entity_id: sensor.click_vacuumctrl_action
  54.         to: 'off' #'brightness_move_down'
  55.       - platform: state
  56.         entity_id: input_boolean.vacuum_is_mopping
  57.         to: 'on'      
  58.     condition:
  59.       condition: and
  60.       conditions:
  61.         - condition: state
  62.           entity_id: vacuum.xiaomi_x10
  63.           state: 'docked'
  64.         #避免第一次先按拖地,必須先掃地後才能按拖地
  65.         - condition: state
  66.           entity_id: input_boolean.vacuum_start_clean
  67.           state: 'on'
  68.     action:
  69.       - service: vacuum.set_fan_speed
  70.         data:
  71.           entity_id: vacuum.xiaomi_x10
  72.           fan_speed: 'Silent'
  73.       - service: select.select_option
  74.         data:
  75.           option: mopping
  76.         target:
  77.           entity_id: select.xiaomi_x10_cleaning_mode  
  78.       - data:
  79.           entity_id: input_boolean.vacuum_start_clean
  80.         service: input_boolean.turn_off          
  81.       - delay:
  82.           seconds: 1
  83.       - service: select.select_option
  84.         data:
  85.           option: slightly_dry
  86.         target:
  87.           entity_id: select.xiaomi_x10_mop_pad_humidity
  88.       - delay:
  89.           milliseconds: 300
  90.       - service: script.turn_on
  91.         data:
  92.           entity_id: script.choose_clean_area        
  93.  
  94.   - id: vacuum_clean_finish_notify
  95.     alias: "通知-掃地機器人完成清掃發送通知"
  96.     trigger:
  97.     - entity_id: vacuum.xiaomi_x10
  98.       platform: state
  99.       from: 'returning'
  100.       to: 'docked'
  101.     condition:
  102.       condition: and
  103.       conditions:
  104.         - condition: state
  105.           entity_id: input_boolean.vacuum_start_clean
  106.           state: 'on'
  107.         - condition: template
  108.           value_template: "{{ int(states('sensor.xiaomi_x10_cleaning_time')) > 1 }}"          
  109.     action:
  110.       - service: notify.line_notify
  111.         data:
  112.           message: >
  113.           《掃地機》 {{ '\n' -}}
  114.            掃地完成! 一共花了 {{ states('sensor.xiaomi_x10_cleaning_time') }} 分鐘清掃 {{ states('sensor.xiaomi_x10_cleaned_area') }} m²
  115.            {% if int(states('sensor.xiaomi_x10_sensor_dirty_time_left')) < 1  %}
  116.            {{ '\n' -}}感應器需要清潔囉!
  117.            {% endif %}
  118.            {% if int(states('sensor.xiaomi_x10_main_brush_time_left')) < 5  %}
  119.            {{ '\n' -}}主刷頭剩下{{ int(states('sensor.xiaomi_x10_main_brush_time_left')) }}小時需要更換囉,記得購買!
  120.            {% endif %}
  121.            {% if int(states('sensor.xiaomi_x10_side_brush_time_left')) < 5  %}
  122.            {{ '\n' -}}側刷頭剩下{{ int(states('sensor.xiaomi_x10_side_brush_time_left')) }}小時需要更換囉,記得購買!
  123.            {% endif %}
  124.            {% if int(states('sensor.xiaomi_x10_filter_time_left')) < 5 %}
  125.            {{ '\n' -}}濾網剩下{{ int(states('sensor.xiaomi_x10_filter_time_left')) }}小時需要更換囉,記得購買!
  126.            {% endif %}
  127.            {% if int(states('sensor.xiaomi_x10_mop_pad_time_left')) < 5 %}
  128.            {{ '\n' -}}拖布剩下{{ int(states('sensor.xiaomi_x10_mop_pad_time_left')) }}小時需要更換囉,記得購買!
  129.            {% endif %}          
  130.       - service: input_text.set_value
  131.         target:
  132.           entity_id: input_text.vacuum_area
  133.         data:
  134.           value: " "          
  135.       - service: button.press
  136.         data: {}
  137.         target:
  138.           entity_id: button.xiaomi_x10_start_auto_empty      
  139.       - wait_for_trigger:
  140.           - platform: state
  141.             entity_id: sensor.xiaomi_x10_auto_empty_status
  142.             from: 'active'
  143.             to: 'idle'
  144.         timeout:
  145.           minutes: 1
  146.         continue_on_timeout: true
  147.       - if:  #如果id==0表示有成功觸發
  148.           - "{{ wait.trigger.id != '0' }}"
  149.         then:
  150.           - service: notify.simon_home_notify
  151.             data:
  152.               message: "《掃地機》 集塵超時,繼續執行"
  153.         else:
  154.           - service: notify.simon_home_notify
  155.             data:
  156.               message: "《掃地機》 集塵完畢"          
  157.       - data:
  158.           entity_id: input_boolean.vacuum_is_mopping
  159.         service: input_boolean.turn_on                  
  160.       - service: notify.simon_home_notify
  161.         data:
  162.           message: "《掃地機》 開始拖地"
  163.          
  164.          
  165.   - id: vacuum_mopping_finish_notify
  166.     alias: "通知-掃地機器人完成拖地發送通知"
  167.     trigger:
  168.       - platform: state
  169.         entity_id: sensor.xiaomi_x10_self_wash_base_status
  170.         from: 'idle'
  171.         to: 'washing'
  172.     condition:
  173.       - condition: state
  174.         entity_id: input_boolean.vacuum_is_mopping
  175.         state: 'on'  
  176.       - condition: template
  177.         value_template: "{{ int(states('sensor.xiaomi_x10_cleaning_time')) > 1 }}"
  178.       - condition: state
  179.         entity_id: sensor.xiaomi_x10_task_status
  180.         state: 'completed'    
  181.     action:
  182.       - data:
  183.           entity_id: input_boolean.vacuum_is_mopping
  184.         service: input_boolean.turn_off
  185.       - service: input_text.set_value
  186.         target:
  187.           entity_id: input_text.vacuum_area
  188.         data:
  189.           value: " "        
  190.       - service: notify.line_notify
  191.         data:
  192.           message: >
  193.            《掃地機》 {{ '\n' -}} 拖地完成! 一共花了 {{ states('sensor.xiaomi_x10_cleaning_time') }} 分鐘清掃 {{ states('sensor.xiaomi_x10_cleaned_area') }} m²
  194.       - service: vacuum.set_fan_speed
  195.         data:
  196.           entity_id: vacuum.xiaomi_x10
  197.           fan_speed: 'Turbo'      
  198.        
  199.   - id: vacuum_mop_washing_drying_twice
  200.     alias: vacuum_mop_washing_drying_twice
  201.     description: 掃地機-拖布清洗兩次後再烘乾兩次
  202.     trigger:
  203.       - platform: state
  204.         entity_id: sensor.xiaomi_x10_state
  205.         from: 'washing'
  206.         to: 'drying'        
  207.     condition:
  208.       - condition: state
  209.         entity_id: select.xiaomi_x10_cleaning_mode
  210.         state: 'mopping'
  211.     action:
  212.       - service: automation.turn_off
  213.         data:
  214.           entity_id: automation.vacuum_second_drying
  215.       #避免重複觸發此自動化    
  216.       - service: select.select_option
  217.         data:
  218.           option: sweeping
  219.         target:
  220.           entity_id: select.xiaomi_x10_cleaning_mode            
  221.       - service: notify.simon_home_notify
  222.         data:
  223.           message: "第一次清洗完第一次烘乾"            
  224.       - service: button.press
  225.         data: {}
  226.         target:
  227.           entity_id: button.xiaomi_x10_manual_drying
  228.       - wait_for_trigger:
  229.           - platform: state
  230.             entity_id: sensor.xiaomi_x10_state
  231.             from: 'drying'
  232.             to: 'charging'
  233.         timeout:
  234.           minutes: 2
  235.         continue_on_timeout: true
  236.       - if:   #如果id==0表示有成功觸發
  237.           - "{{ wait.trigger.id != '0' }}"
  238.         then:
  239.           - service: notify.simon_home_notify
  240.             data:
  241.               message: "第一次烘乾暫停超時,繼續執行"
  242.         else:
  243.           - service: notify.simon_home_notify
  244.             data:
  245.               message: "第一次烘乾暫停"            
  246.       - service: button.press
  247.         data: {}
  248.         target:
  249.           entity_id: button.xiaomi_x10_self_clean
  250.       - service: notify.simon_home_notify
  251.         data:
  252.           message: "第二次清洗開始"
  253.       - wait_for_trigger:
  254.           - platform: state
  255.             entity_id: sensor.xiaomi_x10_state
  256.             from: 'washing'
  257.             to: 'drying'
  258.         timeout:
  259.           minutes: 5
  260.         continue_on_timeout: true
  261.       - if:  #如果id==0表示有成功觸發
  262.           - "{{ wait.trigger.id != '0' }}"
  263.         then:
  264.           - service: notify.simon_home_notify
  265.             data:
  266.               message: "第二次清洗超時,繼續執行"
  267.         else:
  268.           - service: notify.simon_home_notify
  269.             data:
  270.               message: "第二次清洗完成,開始第一次烘乾"            
  271.       - service: automation.turn_on
  272.         data:
  273.           entity_id: automation.vacuum_second_drying          
  274.          
  275.   - id: vacuum_second_drying
  276.     alias: vacuum_second_drying
  277.     description: 掃地機-拖布烘乾第二次
  278.     initial_state: false
  279.     trigger:
  280.       - platform: state
  281.         entity_id: sensor.xiaomi_x10_self_wash_base_status
  282.         from: 'drying'
  283.         to: 'idle'
  284.     condition: []
  285.     action:        
  286.       - service: notify.simon_home_notify
  287.         data:
  288.           message: "第二次烘乾開始"            
  289.       - service: button.press
  290.         data: {}
  291.         target:
  292.           entity_id: button.xiaomi_x10_manual_drying
  293.       - delay:
  294.           seconds: 1
  295.       - service: automation.turn_off
  296.         data:
  297.           entity_id: automation.vacuum_second_drying          
  298.          
  299.   - id: vacuum_start_clean_reset
  300.     alias: vacuum_start_clean_reset
  301.     description: 掃地機-午夜布林重設
  302.     trigger:
  303.       - platform: time
  304.         at: "00:01:00"
  305.     condition:
  306.       - or:
  307.           - condition: state
  308.             entity_id: input_boolean.vacuum_start_clean
  309.             state: 'on'
  310.           - condition: state
  311.             entity_id: input_boolean.vacuum_is_mopping
  312.             state: 'on'            
  313.     action:
  314.       - data:
  315.           entity_id:
  316.             - input_boolean.vacuum_start_clean
  317.             - input_boolean.vacuum_is_mopping
  318.         service: input_boolean.turn_off
  319.        
  320. ###############################################################################
  321. #                               Script
  322. ###############################################################################
  323.  
  324. script:
  325.   choose_clean_area:
  326.     alias: "根據房門的開關來選擇清掃區域"
  327.     sequence:
  328.       - choose:
  329.           - alias: "全區清掃"
  330.             conditions:
  331.               - condition: state
  332.                 entity_id: binary_sensor.door_mainroom_contact
  333.                 state: 'on'
  334.               - condition: state
  335.                 entity_id: binary_sensor.door_guestroom_contact
  336.                 state: 'on'                
  337.             sequence:
  338.               - service: input_text.set_value
  339.                 target:
  340.                   entity_id: input_text.vacuum_area
  341.                 data:
  342.                   value: "全區清掃"                  
  343.               - service: notify.simon_home_notify
  344.                 data:
  345.                   message: "清掃區域:全區清掃"            
  346.               - service: script.turn_on
  347.                 data:
  348.                   entity_id: script.vacuum_area_all
  349.                    
  350.           - alias: "排除主臥"
  351.             conditions:
  352.               - condition: state
  353.                 entity_id: binary_sensor.door_mainroom_contact
  354.                 state: 'off'
  355.               - condition: state
  356.                 entity_id: binary_sensor.door_guestroom_contact
  357.                 state: 'on'                
  358.             sequence:
  359.               - service: input_text.set_value
  360.                 target:
  361.                   entity_id: input_text.vacuum_area
  362.                 data:
  363.                   value: "排除主臥"            
  364.               - service: notify.simon_home_notify
  365.                 data:
  366.                   message: "清掃區域:排除主臥"              
  367.               - service: script.turn_on
  368.                 data:
  369.                   entity_id: script.vacuum_area_except_master_room
  370.  
  371.           - alias: "排除客房"
  372.             conditions:
  373.               - condition: state
  374.                 entity_id: binary_sensor.door_mainroom_contact
  375.                 state: 'on'
  376.               - condition: state
  377.                 entity_id: binary_sensor.door_guestroom_contact
  378.                 state: 'off'                
  379.             sequence:
  380.               - service: input_text.set_value
  381.                 target:
  382.                   entity_id: input_text.vacuum_area
  383.                 data:
  384.                   value: "排除客房"              
  385.               - service: notify.simon_home_notify
  386.                 data:
  387.                   message: "清掃區域:排除客房"            
  388.               - service: script.turn_on
  389.                 data:
  390.                   entity_id: script.vacuum_area_except_guest_room
  391.                  
  392.           - alias: "排除主臥及客房"
  393.             conditions:
  394.               - condition: state
  395.                 entity_id: binary_sensor.door_mainroom_contact
  396.                 state: 'off'
  397.               - condition: state
  398.                 entity_id: binary_sensor.door_guestroom_contact
  399.                 state: 'off'                
  400.             sequence:
  401.               - service: input_text.set_value
  402.                 target:
  403.                   entity_id: input_text.vacuum_area
  404.                 data:
  405.                   value: "排除主臥及客房"              
  406.               - service: notify.simon_home_notify
  407.                 data:
  408.                   message: "清掃區域:排除主臥及客房"            
  409.               - service: script.turn_on
  410.                 data:
  411.                   entity_id: script.vacuum_area_except_master_guest
  412.  
  413.  
  414.  
  415.   vacuum_area_except_guest_room:
  416.     alias: "區域清掃-排除客房"
  417.     sequence:
  418.       - choose:
  419.           - alias: "掃地"
  420.             conditions:
  421.               - condition: state
  422.                 entity_id: select.xiaomi_x10_cleaning_mode
  423.                 state: 'sweeping'              
  424.             sequence:
  425.               - service: dreame_vacuum.vacuum_clean_segment
  426.                 data:
  427.                   segments:
  428.                    - 2
  429.                     - 3
  430.                     - 4
  431.                     - 5
  432.                     - 7
  433.                     - 6
  434.                 target:
  435.                   entity_id: vacuum.xiaomi_x10  
  436.  
  437.           - alias: "拖地"
  438.             conditions:
  439.               - condition: state
  440.                 entity_id: select.xiaomi_x10_cleaning_mode
  441.                 state: 'mopping'              
  442.             sequence:
  443.               - service: dreame_vacuum.vacuum_clean_segment
  444.                 data:
  445.                   segments:
  446.                    - 4
  447.                     - 2
  448.                     - 3
  449.                     - 5
  450.                     - 7
  451.                     - 6
  452.                 target:
  453.                   entity_id: vacuum.xiaomi_x10
  454.  
  455.   vacuum_area_except_master_room:
  456.     alias: "區域清掃-排除主臥"
  457.     sequence:
  458.       - choose:
  459.           - alias: "掃地"
  460.             conditions:
  461.               - condition: state
  462.                 entity_id: select.xiaomi_x10_cleaning_mode
  463.                 state: 'sweeping'              
  464.             sequence:
  465.               - service: dreame_vacuum.vacuum_clean_segment
  466.                 data:
  467.                   segments:
  468.                    - 1
  469.                     - 3
  470.                     - 4
  471.                     - 5
  472.                     - 7
  473.                     - 6
  474.                 target:
  475.                   entity_id: vacuum.xiaomi_x10  
  476.  
  477.           - alias: "拖地"
  478.             conditions:
  479.               - condition: state
  480.                 entity_id: select.xiaomi_x10_cleaning_mode
  481.                 state: 'mopping'              
  482.             sequence:
  483.               - service: dreame_vacuum.vacuum_clean_segment
  484.                 data:
  485.                   segments:
  486.                    - 4
  487.                     - 1
  488.                     - 3
  489.                     - 5
  490.                     - 7
  491.                     - 6
  492.                 target:
  493.                   entity_id: vacuum.xiaomi_x10
  494.  
  495.  
  496.   vacuum_area_except_master_guest:
  497.     alias: "區域清掃-排除主臥及客房"
  498.     sequence:
  499.       - choose:
  500.           - alias: "掃地"
  501.             conditions:
  502.               - condition: state
  503.                 entity_id: select.xiaomi_x10_cleaning_mode
  504.                 state: 'sweeping'              
  505.             sequence:
  506.               - service: dreame_vacuum.vacuum_clean_segment
  507.                 data:
  508.                   segments:
  509.                    - 3
  510.                     - 4
  511.                     - 5
  512.                     - 7
  513.                     - 6
  514.                 target:
  515.                   entity_id: vacuum.xiaomi_x10  
  516.  
  517.           - alias: "拖地"
  518.             conditions:
  519.               - condition: state
  520.                 entity_id: select.xiaomi_x10_cleaning_mode
  521.                 state: 'mopping'              
  522.             sequence:
  523.               - service: dreame_vacuum.vacuum_clean_segment
  524.                 data:
  525.                   segments:
  526.                    - 4
  527.                     - 3
  528.                     - 5
  529.                     - 7
  530.                     - 6
  531.                 target:
  532.                   entity_id: vacuum.xiaomi_x10
  533.  
  534.  
  535.                
  536.   vacuum_area_all:
  537.     alias: "區域清掃-全區"
  538.     sequence:
  539.       - choose:
  540.           - alias: "掃地"
  541.             conditions:
  542.               - condition: state
  543.                 entity_id: select.xiaomi_x10_cleaning_mode
  544.                 state: 'sweeping'              
  545.             sequence:
  546.               - service: dreame_vacuum.vacuum_clean_segment
  547.                 data:
  548.                   segments:
  549.                    - 2
  550.                     - 1
  551.                     - 3
  552.                     - 4
  553.                     - 5
  554.                     - 7
  555.                     - 6
  556.                 target:
  557.                   entity_id: vacuum.xiaomi_x10
  558.  
  559.           - alias: "拖地"
  560.             conditions:
  561.               - condition: state
  562.                 entity_id: select.xiaomi_x10_cleaning_mode
  563.                 state: 'mopping'              
  564.             sequence:  
  565.               - service: dreame_vacuum.vacuum_clean_segment
  566.                 data:
  567.                   segments:
  568.                    - 4
  569.                     - 2
  570.                     - 1
  571.                     - 3
  572.                     - 5
  573.                     - 7
  574.                     - 6
  575.                 target:
  576.                   entity_id: vacuum.xiaomi_x10
  577.                  
  578.            
  579.  
  580.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement