Integrate Valetudo Robot In to Home Assistant

In this article we’ll descibe how to make your Valetudo map segments known to Home Assistant and how to create a card allowing the selecting of map segments.

We’ll assume you already have the robot talking to HA via mqtt.

Note that you’ll need to change the vacuum name ‘PossibleSecondaryNarwhal’ in the examples below to whatever your vacuum is called

First we need to check how the map segments are named and numbered.

Open up settings > integrations and entities > entities and look for your map segment entiity which should be provided by mqtt:

Open it up and hit ‘attributes’. You should see you map segments and corresponding name/id listed:

image

Take note of the names and in the HA root (same location as the configuration.yaml) create a new file: customize.yaml

In this file we’ll create the boolean entries. For each segment create an entry like so:

input_boolean.vacuum_hallway:
  room_id: "2"
input_boolean.vacuum_livingroom:
  room_id: "6"
input_boolean.vacuum_bedroom:
  room_id: "5"
input_boolean.vacuum_kitchen:
  room_id: "4"
input_boolean.vacuum_office:
  room_id: "1"

Save the file.

Next create a file named ‘groups.yaml’ in the same location and add the code below. Change the entries to match your segment names:

vacuum_rooms:
  name: Vacuum Rooms
  entities:
    - input_boolean.vacuum_bedroom
    - input_boolean.vacuum_hallway
    - input_boolean.vacuum_entrance
    - input_boolean.vacuum_kitchen
    - input_boolean.vacuum_livingroom
    - input_boolean.vacuum_office

Next we’ll need to create the corresponding config in configuration.yaml. Add the following but change the segment names to your segments and change the icons if desired:

input_boolean:
  vacuum_entrance:
    name: Entrance
    icon: mdi:door-closed
  vacuum_hallway:
    name: Hallway
    icon: mdi:foot-print
  vacuum_livingroom:
    name: Living Room
    icon: mdi:sofa
  vacuum_bedroom:
    name: Bedroom
    icon: mdi:bed-empty
  vacuum_kitchen:
    name: Kitchen
    icon: mdi:silverware-fork-knife
  vacuum_office:
    name: Office
    icon: mdi:laptop

Next we’ll add the script that takes care of segment cleaning. If you don’t already have a scripts file create it (same location as customize.yaml) and add the following (again, change the name to whatever your vacuum is called):

vacuum_clean_segments:
  sequence:
  - service: script.turn_on
    target:
      entity_id: script.vacuum_clean_segments_message
    data:
      variables:
        segments: '{{expand("group.vacuum_rooms") | selectattr("state","eq","on")
          | map(attribute="attributes.room_id") | list | to_json}}'
  mode: single
  alias: vacuum_clean_segments
  icon: mdi:arrow-right
vacuum_clean_segments_message:
  alias: vacuum_clean_segments_message
  sequence:
  - service: mqtt.publish
    data:
      topic: valetudo/PossibleSecondaryNarwhal/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": {{segments}}}'
  mode: single

If you want to add a nice dashboard button download the auto-entities and button-card. cards through hacs. Create a new card using the config below but change the name of the vacuum to whatever yours is called:

type: vertical-stack
cards:
  - type: custom:auto-entities
    card:
      type: entities
      state_color: true
      title: Rooms to Vacuum
    filter:
      include:
        - group: group.vacuum_rooms
      exclude: []
    show_empty: true
    sort:
      method: friendly_name
      reverse: false
      numeric: false
  - type: custom:button-card
    tap_action:
      action: call-service
      service: script.vacuum_clean_segments
      confirmation: true
      service_data: {}
      target: {}
    lock:
      enabled: >-
        [[[return states['group.vacuum_rooms'].state !== 'on' ||
        states['vacuum.valetudo_possiblesecondarynarwhal'].state !== 'docked']]]
      exemptions: []
    entity: script.vacuum_clean_segments
    name: Vacuum selected segments
    show_state: false
    show_icon: false
  - type: entities
    entities:
      - entity: select.valetudo_possiblesecondarynarwhal_fan
        name: Fan Speed
    theme: dark_orange

That should do it.