humbertogontijo / homeassistant-roborock

Roborock integration for Home Assistant. This integration uses your devices from the Roborock App
GNU General Public License v3.0
665 stars 69 forks source link

Add or update time left for accessories life #79

Closed ampersandru closed 1 year ago

ampersandru commented 1 year ago

Love the update with the new sensors. What shows on the device page under diagnostic for accessories is in hours, but when I add the accessory entity (Main brush left, side brush left, filter left, etc) shows up in seconds. Additionally, the "water shortage" entity shows up as "OK" in the device page but "off" when added as an entity.

Two requests:

Device Page: image

When adding the entities: image

shred86 commented 1 year ago

The integration provides the native value from Roborock's API which is in seconds. Home Assistant displays this as hours, minutes and seconds as you see in the devices page.

Is that the Xiaomi Vacuum Map Card or a custom one you made? If it's the former, there's an issue open in their GitHub about being compatible with this integration. I think this is just something the Lovelace card will have to convert into the desired units or how the state information is displayed. It looks like that Lovelace card is just adding the binary sensor as a generic class instead of the "problem" class as it's defined, which is what shows "OK" when the binary sensor state is "on". Same with the time, should be a device class of "timestamp" which I think HA will then auto format to hh:mm:ss.

medfiras commented 1 year ago

in my case i'm using this card and it's working as well

image

and i'm also using lovelace-xiaomi-vacuum-map-card you can use multiplier: 0.0002777777777777778 example:

  - tile_id: filter_left
    label: Filter left
    unit: h
    multiplier: 0.0002777777777777778
    hold_action:
      action: call-service
      service: vacuum.send_command
      confirmation: true
      service_data:
        command: reset_consumable
        params: filter_work_time
        entity_id: vacuum.roborock
    entity: sensor.roborock_filter_left
    icon: mdi:air-filter
    precision: 0
    translations: {}

image

ampersandru commented 1 year ago

Thanks for the comments and tips, I was using a generic vacuum card, switched it to the xiaomi one and it shows up properly now (except water tank status)

Boss-man commented 1 year ago

in my case i'm using this card and it's working as well

image

Would you mind sharing this setup including the pictures ? :)

medfiras commented 1 year ago

Sure !

bellow you can find my vacuum dashboard, it should look like this

image

and the code + images bellow

- theme: Backend-selected
    title: Roborock
    path: roborock
    icon: mdi:robot-vacuum
    type: custom:masonry-layout
    layout:
      width: 300
      max_cols: 4
    badges: []
    cards:
      - type: custom:vertical-stack-in-card
        cards:
          - type: custom:mushroom-vacuum-card
            entity: vacuum.roborock
            icon_animation: true
            commands:
              - on_off
              - stop
              - start_pause
              - locate
              - clean_spot
              - return_home
          - type: entities
            entities:
              - entity: input_select.aspimode
              - entity: input_select.vacuumfanspeed
              - entity: input_select.vacuumscrubintensity
            state_color: false
      - type: vertical-stack
        cards:
          - type: custom:xiaomi-vacuum-card
            entity: vacuum.roborock
            image: /local/vacuum/roborock-s7.jpg
            name: Roborock
            vendor: xiaomi
            state:
              status:
                key: state
            attributes:
              main_brush:
                key: main_brush_remaining
              side_brush:
                key: side_brush_remaining
              filter:
                key: filter_remaining
              sensor:
                key: sensor_dirty_remaining
          - type: horizontal-stack
            cards:
              - elements:
                  - entity: sensor.roborock_side_filter_left_pct
                    style:
                      background-color: rgba(0, 0, 0, 0.3)
                      bottom: 0px
                      color: orange
                      font-size: 30px
                      left: 0px
                      right: 0px
                      transform: translate(0%,0%)
                    title: '% Remaining Until Side Brush Should Be Replaced'
                    type: state-label
                    suffix: '%'
                  - entity: sensor.roborock_side_brush_remaining
                    style:
                      bottom: 0px
                      color: white
                      font-size: 16px
                      line-height: 16px
                      right: 0px
                      transform: translate(0%,0%)
                    prefix: ''
                    title: Hours Remaining Until Side Brush Should Be Replaced
                    type: state-label
                  - icon: mdi:restart
                    style:
                      color: white
                      padding: 7px
                      right: 0px
                      top: 0px
                      transform: translate(0%,0%)
                    tap_action:
                      action: call-service
                      confirmation:
                        text: >-
                          Are you sure you want to reset the hours remaining
                          counter for replacing the side brush?
                      service: vacuum.send_command
                      service_data:
                        command: reset_consumable
                        entity_id: vacuum.roborock
                        params:
                          - side_brush_work_time
                    title: Reset Hours
                    type: icon
                image: /local/vacuum/78b77a9bf083ea3c23e5a9355670e4270e9fdc0f.png
                type: picture-elements
              - elements:
                  - entity: sensor.roborock_sensors_left_pct
                    style:
                      background-color: rgba(0, 0, 0, 0.3)
                      bottom: 0px
                      color: orange
                      font-size: 30px
                      left: 0px
                      right: 0px
                      transform: translate(0%,0%)
                    title: '% Remaining Until Sensors Should Be Cleaned'
                    type: state-label
                    suffix: '%'
                  - entity: sensor.roborock_sensor_dirty_remaining
                    style:
                      bottom: 0px
                      color: white
                      font-size: 16px
                      line-height: 16px
                      right: 0px
                      transform: translate(0%,0%)
                    prefix: ''
                    title: Hours Remaining Until Sensors Should Be Cleaned
                    type: state-label
                  - icon: mdi:restart
                    style:
                      color: white
                      padding: 7px
                      right: 0px
                      top: 0px
                      transform: translate(0%,0%)
                    tap_action:
                      action: call-service
                      confirmation:
                        text: >-
                          Are you sure you want to reset the hours remaining
                          counter for cleaning the sensors?
                      service: vacuum.send_command
                      service_data:
                        command: reset_consumable
                        entity_id: vacuum.roborock
                        params:
                          - sensor_dirty_time
                    title: Reset Hours
                    type: icon
                image: /local/vacuum/ab339ca78a5d3fd1961b09b3cd89445d02735d03.png
                type: picture-elements
          - type: horizontal-stack
            cards:
              - elements:
                  - entity: sensor.roborock_filter_left_pct
                    style:
                      background-color: rgba(0, 0, 0, 0.3)
                      bottom: 0px
                      color: orange
                      font-size: 30px
                      left: 0px
                      right: 0px
                      transform: translate(0%,0%)
                    title: '% Remaining Until Filter Should Be Replaced'
                    type: state-label
                    suffix: '%'
                  - entity: sensor.roborock_filter_remaining
                    style:
                      bottom: 0px
                      color: white
                      font-size: 16px
                      line-height: 16px
                      right: 0px
                      transform: translate(0%,0%)
                    prefix: ''
                    title: Hours Remaining Until Filter Should Be Replaced
                    type: state-label
                  - icon: mdi:restart
                    style:
                      color: white
                      padding: 7px
                      right: 0px
                      top: 0px
                      transform: translate(0%,0%)
                    tap_action:
                      action: call-service
                      confirmation:
                        text: >-
                          Are you sure you want to reset the hours remaining
                          counter for replacing the filter?
                      service: vacuum.send_command
                      service_data:
                        command: reset_consumable
                        entity_id: vacuum.roborock
                        params:
                          - filter_work_time
                    title: Reset Hours
                    type: icon
                image: /local/vacuum/114947eecff06c2aaad544954ffcff7bec045fff.png
                type: picture-elements
              - elements:
                  - entity: sensor.roborock_main_filter_left_pct
                    style:
                      background-color: rgba(0, 0, 0, 0.3)
                      bottom: 0px
                      color: orange
                      font-size: 30px
                      left: 0px
                      right: 0px
                      transform: translate(0%,0%)
                    title: '% Remaining Until Main Brush Should Be Replaced'
                    type: state-label
                    suffix: '%'
                  - entity: sensor.roborock_main_brush_remaining
                    style:
                      bottom: 0px
                      color: white
                      font-size: 16px
                      line-height: 16px
                      right: 0px
                      transform: translate(0%,0%)
                    prefix: ''
                    title: Hours Remaining Until Main Brush Should Be Replaced
                    type: state-label
                  - icon: mdi:restart
                    style:
                      color: white
                      padding: 7px
                      right: 0px
                      top: 0px
                      transform: translate(0%,0%)
                    tap_action:
                      action: call-service
                      confirmation:
                        text: >-
                          Are you sure you want to reset the hours remaining
                          counter for replacing the main brush?
                      service: vacuum.send_command
                      service_data:
                        command: reset_consumable
                        entity_id: vacuum.roborock
                        params:
                          - main_brush_work_time
                    title: Reset Hours
                    type: icon
                image: /local/vacuum/759d304a70d49a534a9a2bf75241b0c7086e8192.png
                type: picture-elements
      - type: custom:xiaomi-vacuum-map-card
        language: fr
        preset_name: Live map
        entity: vacuum.roborock
        map_source:
          camera: camera.roborock
        calibration_source:
          camera: true
        scan_interval:
          seconds: 5
        map_modes:
          - name: Zone cleanup
            icon: mdi:select-drag
            run_immediately: false
            coordinates_rounding: true
            selection_type: MANUAL_RECTANGLE
            max_selections: 5
            repeats_type: EXTERNAL
            max_repeats: 3
            service_call_schema:
              service: roborock.vacuum_clean_zone
              service_data:
                zone: '[[selection]]'
                repeats: '[[repeats]]'
                entity_id: '[[entity_id]]'
            predefined_selections: []
            variables: {}
          - name: Zones list
            icon: mdi:floor-plan
            run_immediately: false
            coordinates_rounding: true
            selection_type: PREDEFINED_RECTANGLE
            max_selections: 5
            repeats_type: EXTERNAL
            max_repeats: 3
            service_call_schema:
              service: roborock.vacuum_clean_zone
              service_data:
                zone: '[[selection]]'
                repeats: '[[repeats]]'
                entity_id: '[[entity_id]]'
            predefined_selections:
              - zones:
                  - - 21485
                    - 28767
                    - 24236
                    - 32131
                  - - 23217
                    - 27379
                    - 24216
                    - 28737
                label:
                  text: Bedroom
                  x: 22932
                  'y': 30339
                  offset_y: 35
                icon:
                  name: mdi:bed
                  x: 22932
                  'y': 30339
              - zones:
                  - - 27782
                    - 27563
                    - 29678
                    - 29369
                label:
                  text: Kitchen
                  x: 28760
                  'y': 28403
                  offset_y: 35
                icon:
                  name: mdi:pot-mix
                  x: 28760
                  'y': 28403
            variables: {}
          - name: Rooms
            icon: mdi:floor-plan
            run_immediately: false
            coordinates_rounding: true
            selection_type: ROOM
            max_selections: 999
            repeats_type: REPEAT
            max_repeats: 3
            service_call_schema:
              service: roborock.vacuum_clean_segment
              service_data:
                segments: '[[selection]]'
                entity_id: '[[entity_id]]'
            predefined_selections:
              - id: '16'
                icon:
                  name: mdi:table-chair
                  x: 27500
                  'y': 28150
                label:
                  text: Salle à manger
                  x: 27500
                  'y': 28150
                  offset_y: 35
                outline:
                  - - 24550
                    - 25000
                  - - 30450
                    - 25000
                  - - 30450
                    - 31300
                  - - 24550
                    - 31300
              - id: '17'
                icon:
                  name: mdi:chef-hat
                  x: 23400
                  'y': 26675
                label:
                  text: Cuisine
                  x: 23400
                  'y': 26675
                  offset_y: 35
                outline:
                  - - 21600
                    - 25150
                  - - 25200
                    - 25150
                  - - 25200
                    - 28200
                  - - 21600
                    - 28200
              - id: '18'
                icon:
                  name: mdi:map-marker-path
                  x: 25375
                  'y': 22975
                label:
                  text: Couloire
                  x: 25375
                  'y': 22975
                  offset_y: 35
                outline:
                  - - 24050
                    - 21050
                  - - 26700
                    - 21050
                  - - 26700
                    - 24900
                  - - 24050
                    - 24900
              - id: '19'
                icon:
                  name: mdi:sofa
                  x: 28600
                  'y': 23000
                label:
                  text: Séjour
                  x: 28600
                  'y': 23000
                  offset_y: 35
                outline:
                  - - 26750
                    - 21050
                  - - 30450
                    - 21050
                  - - 30450
                    - 24950
                  - - 26750
                    - 24950
              - id: '20'
                icon:
                  name: mdi:bed
                  x: 22550
                  'y': 22500
                label:
                  text: Chambre invité
                  x: 22550
                  'y': 22500
                  offset_y: 35
                outline:
                  - - 21050
                    - 21000
                  - - 24050
                    - 21000
                  - - 24050
                    - 24000
                  - - 21050
                    - 24000
              - id: '21'
                icon:
                  name: mdi:toilet
                  x: 22925
                  'y': 24275
                label:
                  text: WC
                  x: 22925
                  'y': 24275
                  offset_y: 35
                outline:
                  - - 21850
                    - 23650
                  - - 24000
                    - 23650
                  - - 24000
                    - 24900
                  - - 21850
                    - 24900
            variables: {}
          - name: Pin & Go
            icon: mdi:map-marker-plus
            run_immediately: false
            coordinates_rounding: true
            selection_type: MANUAL_POINT
            max_selections: 999
            repeats_type: NONE
            max_repeats: 1
            service_call_schema:
              service: roborock.vacuum_goto
              service_data:
                x_coord: '[[point_x]]'
                y_coord: '[[point_y]]'
                entity_id: '[[entity_id]]'
            predefined_selections: []
            variables: {}
          - name: Points
            icon: mdi:map-marker
            run_immediately: false
            coordinates_rounding: true
            selection_type: PREDEFINED_POINT
            max_selections: 999
            repeats_type: NONE
            max_repeats: 1
            service_call_schema:
              service: roborock.vacuum_goto
              service_data:
                x_coord: '[[point_x]]'
                y_coord: '[[point_y]]'
                entity_id: '[[entity_id]]'
            predefined_selections:
              - position:
                  - 28006
                  - 28036
                label:
                  text: Emptying
                  x: 28006
                  'y': 28036
                  offset_y: 35
                icon:
                  name: mdi:broom
                  x: 28006
                  'y': 28036
              - position:
                  - 32143
                  - 26284
                label:
                  text: Sofa
                  x: 32143
                  'y': 26284
                  offset_y: 35
                icon:
                  name: mdi:sofa
                  x: 32143
                  'y': 26284
            variables: {}
          - name: Path
            icon: mdi:map-marker-path
            run_immediately: false
            coordinates_rounding: true
            selection_type: MANUAL_PATH
            max_selections: 999
            repeats_type: NONE
            max_repeats: 1
            service_call_schema:
              service: script.vacuum_follow_path
              service_data:
                service: roborock.vacuum_goto
                mode: individual
                path: '[[selection]]'
                entity_id: '[[entity_id]]'
            predefined_selections: []
            variables: {}
        tiles:
          - tile_id: status
            entity: vacuum.roborock
            label: Status
            attribute: state
            icon: mdi:robot-vacuum
            unit: ''
            translations:
              docked: Sur la base
              cleaning: Nettoyage
          - tile_id: battery_level
            entity: vacuum.roborock
            label: Battery
            attribute: battery_level
            icon: mdi:battery-charging-100
            unit: '%'
          - tile_id: fan_speed
            entity: vacuum.roborock
            label: Fan speed
            attribute: fan_speed
            icon: mdi:fan
            translations:
              silent: Silent
              standard: Standard
              medium: Medium
              turbo: Turbo
              auto: Auto
              gentle: Gentle
          - tile_id: sensor_dirty_left
            label: Sensors left
            unit: h
            multiplier: 0.0002777777777777778
            hold_action:
              action: call-service
              service: vacuum.send_command
              confirmation: true
              service_data:
                command: reset_consumable
                params: sensor_dirty_time
                entity_id: vacuum.roborock
            entity: sensor.roborock_sensor_dirty_remaining
            icon: mdi:eye-outline
            precision: 0
            translations: {}
          - tile_id: filter_left
            label: Filter left
            unit: h
            multiplier: 0.0002777777777777778
            hold_action:
              action: call-service
              service: vacuum.send_command
              confirmation: true
              service_data:
                command: reset_consumable
                params: filter_work_time
                entity_id: vacuum.roborock
            entity: sensor.roborock_filter_remaining
            icon: mdi:air-filter
            precision: 0
            translations: {}
          - tile_id: main_brush_left
            label: Main brush left
            unit: h
            multiplier: 0.0002777777777777778
            hold_action:
              action: call-service
              service: vacuum.send_command
              confirmation: true
              service_data:
                command: reset_consumable
                params: main_brush_work_time
                entity_id: vacuum.roborock
            entity: sensor.roborock_main_brush_remaining
            icon: mdi:brush
            precision: 0
            translations: {}
          - tile_id: side_brush_left
            label: Side brush left
            unit: h
            multiplier: 0.0002777777777777778
            hold_action:
              action: call-service
              service: vacuum.send_command
              confirmation: true
              service_data:
                command: reset_consumable
                params: side_brush_work_time
                entity_id: vacuum.roborock
            entity: sensor.roborock_side_brush_remaining
            icon: mdi:brush
            precision: 0
            translations: {}
          - tile_id: cleaning_count
            label: Cleaning count
            entity: sensor.roborock_total_clean_count
            icon: mdi:counter
            precision: 0
            translations: {}
        icons:
          - icon: mdi:play
            conditions:
              - entity: vacuum.roborock
                value_not: cleaning
              - entity: vacuum.roborock
                value_not: error
              - entity: vacuum.roborock
                value_not: returning
            tooltip: Start
            tap_action:
              action: call-service
              service: vacuum.start
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:pause
            conditions:
              - entity: vacuum.roborock
                value_not: docked
              - entity: vacuum.roborock
                value_not: idle
              - entity: vacuum.roborock
                value_not: error
              - entity: vacuum.roborock
                value_not: paused
            tooltip: Pause
            tap_action:
              action: call-service
              service: vacuum.pause
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:stop
            conditions:
              - entity: vacuum.roborock
                value_not: docked
              - entity: vacuum.roborock
                value_not: idle
              - entity: vacuum.roborock
                value_not: error
              - entity: vacuum.roborock
                value_not: paused
            tooltip: Stop
            tap_action:
              action: call-service
              service: vacuum.stop
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:home-map-marker
            conditions:
              - entity: vacuum.roborock
                value_not: docked
              - entity: vacuum.roborock
                value_not: returning
            tooltip: Return to base
            tap_action:
              action: call-service
              service: vacuum.return_to_base
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:target-variant
            conditions:
              - entity: vacuum.roborock
                value_not: docked
              - entity: vacuum.roborock
                value_not: error
              - entity: vacuum.roborock
                value_not: cleaning
              - entity: vacuum.roborock
                value_not: returning
            tooltip: Clean spot
            tap_action:
              action: call-service
              service: vacuum.clean_spot
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:map-marker
            tooltip: Locate
            tap_action:
              action: call-service
              service: vacuum.locate
              service_data:
                entity_id: vacuum.roborock
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: 'Off'
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Silent
          - icon: mdi:fan-remove
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Silent
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Balanced
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Balanced
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Turbo
          - icon: mdi:fan-speed-3
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Turbo
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Max
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Max
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Max+
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Max+
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: Custom
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value: Custom
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: 'Off'
          - icon: mdi:fan-alert
            conditions:
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: 'Off'
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Silent
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Balanced
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Turbo
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Max
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Max+
              - entity: vacuum.roborock
                attribute: fan_speed
                value_not: Custom
            tooltip: Change fan speed
            tap_action:
              action: call-service
              service: vacuum.set_fan_speed
              service_data:
                entity_id: vacuum.roborock
                fan_speed: 'Off'
          - icon: mdi:home-floor-0
            tooltip: RDC
            tap_action:
              action: call-service
              service: vacuum.send_command
              service_data:
                entity_id: vacuum.roborock
                command: load_multi_map
                params: 0
          - icon: mdi:home-floor-1
            tooltip: Etage
            tap_action:
              action: call-service
              service: vacuum.send_command
              service_data:
                entity_id: vacuum.roborock
                command: load_multi_map
                params: 1
        vacuum_platform: send_command

and here images :)

78b77a9bf083ea3c23e5a9355670e4270e9fdc0f 759d304a70d49a534a9a2bf75241b0c7086e8192 114947eecff06c2aaad544954ffcff7bec045fff ab339ca78a5d3fd1961b09b3cd89445d02735d03 roborock

You need to add sensors for pct :)

  - platform: template
    sensors:
      roborock_main_filter_left_pct:
        value_template: "{{ (states('sensor.roborock_main_brush_remaining')|float / 3600 / 300 * 100) | round }}"
  - platform: template
    sensors:
      roborock_side_filter_left_pct:
        value_template: "{{ (states('sensor.roborock_side_brush_remaining')|float / 3600 / 200 * 100) | round }}"
  - platform: template
    sensors:
      roborock_sensors_left_pct:
        value_template: "{{ (states('sensor.roborock_sensor_dirty_remaining')|float / 3600 / 60 * 100) | round }}"
  - platform: template
    sensors:
      roborock_filter_left_pct:
        value_template: "{{ (states('sensor.roborock_filter_remaining')|float / 3600 / 150 * 100) | round }}"
Boss-man commented 1 year ago

Sure !

bellow you can find my vacuum dashboard, it should look like this

This is gold! Thank you very much :)

humbertogontijo commented 1 year ago

This issue was more about how to show the info than an issue itself. I left it open because of the valuable comments about cards. I'm closing it now, but feel free to add this information to the discussion tab