Template Vacuum


The template platform creates vacuums that combine integrations and provides the ability to run scripts or invoke services for each of the start, pause, stop, return_to_base, clean_spot, locate and set_fan_speed commands of a vacuum.

To enable Template Vacuums in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
vacuum:
  - platform: template
    vacuums:
      living_room_vacuum:
        start:
          service: script.vacuum_start

Configuration Variables

vacuums map Required

List of your vacuums.

friendly_name string (Optional)

Name to use in the frontend.

unique_id string (Optional)

An ID that uniquely identifies this vacuum. Set this to a unique value to allow customization through the UI.

value_template template (Optional)

Defines a template to get the state of the vacuum. Valid value: docked/cleaning/idle/paused/returning/error

battery_level_template template (Optional)

Defines a template to get the battery level of the vacuum. Legal values are numbers between 0 and 100.

fan_speed_template template (Optional)

Defines a template to get the fan speed of the vacuum.

attribute_templates map (Optional)

Defines templates for attributes of the sensor.

attribute: template template Required

The attribute and corresponding template.

availability_template template (Optional, default: true)

Defines a template to get the available state of the component. If the template returns true, the device is available. If the template returns any other value, the device will be unavailable. If availability_template is not configured, the component will always be available.

start action Required

Defines an action to run when the vacuum is started.

pause action (Optional)

Defines an action to run when the vacuum is paused.

stop action (Optional)

Defines an action to run when the vacuum is stopped.

return_to_base action (Optional)

Defines an action to run when the vacuum is given a return to base command.

clean_spot action (Optional)

Defines an action to run when the vacuum is given a clean spot command.

locate action (Optional)

Defines an action to run when the vacuum is given a locate command.

set_fan_speed action (Optional)

Defines an action to run when the vacuum is given a command to set the fan speed.

fan_speeds string | list (Optional)

List of fan speeds supported by the vacuum.

Working without entities

If you use a template that depends on the current time or some other non-deterministic result not sourced from entities, the template won’t repeatedly update but will only update when the state of a referenced entity updates. For ways to deal with this issue, see Working without entities in the Template Sensor integration.

Examples

Control vacuum with Harmony Hub

This example shows how you can use a Template Vacuum to control an IR vacuum cleaner using the Harmony Hub Remote component.

vacuum:
  - platform: template
    vacuums:
      living_room_vacuum:
        start:
          - service: remote.send_command
            data:
              entity_id: remote.harmony_hub
              command: Clean
              device: 52840686
        return_to_base:
          - service: remote.send_command
            data:
              entity_id: remote.harmony_hub
              command: Home
              device: 52840686
        clean_spot:
          - service: remote.send_command
            data:
              entity_id: remote.harmony_hub
              command: SpotCleaning
              device: 52840686

Vacuum with state

This example shows how to use templates to specify the state of the vacuum.

vacuum:
  - platform: template
    vacuums:
      living_room_vacuum:
        value_template: "{{ states('sensor.vacuum_state') }}"
        battery_level_template: "{{ states('sensor.vacuum_battery_level')|int }}"
        fan_speed_template: "{{ states('sensor.vacuum_fan_speed') }}"
        start:
            service: script.vacuum_start
        pause:
            service: script.vacuum_pause
        stop:
            service: script.vacuum_stop
        return_to_base:
            service: script.vacuum_return_to_base
        clean_spot:
            service: script.vacuum_clean_spot
        locate:
            service: script.vacuum_locate_vacuum
        set_fan_speed:
            service: script.vacuum_set_fan_speed
            data:
              speed: "{{ fan_speed }}"
        fan_speeds:
            - Low
            - Medium
            - High

Add Custom Attributes

This example shows how to add custom attributes.

vacuum:
  - platform: template
    vacuums:
      living_room_vacuum:
        value_template: "{{ states('sensor.vacuum_state') }}"
        battery_level_template: "{{ states('sensor.vacuum_battery_level')|int }}"
        fan_speed_template: "{{ states('sensor.vacuum_fan_speed') }}"
        attribute_templates:
          status: >-
            {% if (states('sensor.robot_vacuum_robot_cleaner_movement') == "after" and states('sensor.robot_vacuum_robot_cleaner_cleaning_mode') == "stop")  %}
              Charging to Resume
            {% elif states('sensor.robot_vacuum_robot_cleaner_cleaning_mode') == "auto" %}
              Cleaning
            {% else %}
              Charging
            {% endif %}