Skip to content

Instantly share code, notes, and snippets.

@gtrabanco
Last active January 9, 2022 15:53
Show Gist options
  • Save gtrabanco/87320443dcd30ac10990f87b0c423e19 to your computer and use it in GitHub Desktop.
Save gtrabanco/87320443dcd30ac10990f87b0c423e19 to your computer and use it in GitHub Desktop.
Vacuum Configuration for Home Assistant
# Vacuum-extended-config
# Version: 1.0.0
# Author: Gabriel Trabanco Llano <[email protected]>
# https://github.com/gtrabanco https://keybase.io/gtrabanco
# LICENSE: UNLICENSED. Do whatever you want with this stuff but attribution will be
# very welcome from my ego.
# Versión en español: https://gist.github.com/gtrabanco/476bc119448319a1db510f6948361f47
# You can add this file entirely but need to change <valetudo_or_ha_ip> and <valetudo_port> manually.
# homeassistant:
# packages:
# vacuum: !include vacuum.yaml
# THINGS YOU SHOULD CHANGE
# · If you have multiple vacuum you should change the prefix "vacuum_" on all entities because entity names should be unique.
# · You should change also all entities names "vacuum.robot" for your vacuum entity which should be "vacuum.<identifier_configured_in_valetudo>"
# · Remember to enable access to valetudo with a port if you are using Congatudo-add-on as explained here: https://freecon.ga/blog/get-area-and-time-in-ha-from-valetudo/
# · Change the mqtt prefix and vacuum identifier in mqtt sensors.
# Requirements to have actionable notfications that shows the map when pending:
# · Home Assistant > 2021.05
# · iOS/Android Companion App.
# · NODE-RED with the palette `node-red-contrib-valetudo`
# · This flow (requires configuration):
# [{"id":"68cdb83722fb413c","type":"tab","label":"Vacuum: Save map","disabled":false,"info":"Save current map to a png file in:\n/share/vacuum/current_map.png","env":[]},{"id":"3e8d57cacbf1b976","type":"mqtt in","z":"68cdb83722fb413c","name":"<valetudo_prefix>/<vacuum_identifier>/MapData/map-data","topic":"<valetudo_prefix>/<vacuum_identifier>/MapData/map-data","qos":"0","datatype":"auto","broker":"a0efc2dff11d94d6","nl":false,"rap":true,"rh":0,"inputs":0,"x":280,"y":140,"wires":[["983c7005bc28067a"]]},{"id":"e4f72565521ec2cf","type":"file","z":"68cdb83722fb413c","name":"/media/vacuum/current_map.png","filename":"/media/vacuum/current_map.png","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":940,"y":140,"wires":[[]]},{"id":"983c7005bc28067a","type":"valetudo-map-png","z":"68cdb83722fb413c","name":"","drawPath":true,"drawCharger":true,"drawRobot":true,"scale":4,"defer":2000,"cropX1":"","cropX2":"","cropY1":"","cropY2":"","x":650,"y":140,"wires":[["e4f72565521ec2cf","1a868008115d7360"]]},{"id":"e27d3dc13af41951","type":"comment","z":"68cdb83722fb413c","name":"Change the topic - Cambiar el topic","info":"The topic for your conga can be other and not this one, is probable: valetudo/robot...\nYou may change only until second slash \"/\" (not included the slash).\nTo know yours you can use mqtt explorer or see it in \"Congatudo Addon\" > \"Settings\" > \"MQTT\"\n\nUntil the first slash \"/\" is, in the absolute botton, the option \"Topic prefix\".\n\nThe next word (\"robot\" in my case), is the \"Identifier\".\n\n--\n\nEl topic para tu conga no tiene porque ser este, es probable que sea: valetudo/robot...\nSolo deberías cambiar hasta la segunda barra (no incluida).\nPuedes usar mqtt explorer para averiguarlo o verlo en el addon de congatudo > settings > mqtt\n\nHasta la primera barra \"/\" está abajo del todo, es la opción que se llama \"Topic prefix\".\n\nLo que va después (\"robot\" en mi caso) de la primera barra es el \"Identifier\".\n","x":270,"y":100,"wires":[]},{"id":"ace748d133cdfa03","type":"comment","z":"68cdb83722fb413c","name":"Path to store the map - Almacenar el mapa","info":"Here the path to the map. Important check that is checked \"Create Directory If It Doesn't Exist?\".\n\nTo used this map with actionable notifications you need to store on `/media` path.\n\n--\n\nAqui la ruta al mapa. Es importante que compruebes que está marcado \"Create Directory If It Doesn't Exist?\".\n\nPara ver el mapa en las notificaciones, necesitas almacenar el mapa en `/media`.\n","x":640,"y":100,"wires":[]},{"id":"932a6df3e920f0fb","type":"comment","z":"68cdb83722fb413c","name":"Save Map as file","info":"You should change:\n- \"valetudo\" for your vaccum topic.\n- \"robot\" for your vacuum identifier.\n","x":130,"y":60,"wires":[]},{"id":"1a868008115d7360","type":"base64","z":"68cdb83722fb413c","name":"","action":"","property":"payload","x":860,"y":200,"wires":[["22de8811fba8cde6"]]},{"id":"22de8811fba8cde6","type":"change","z":"68cdb83722fb413c","name":"","rules":[{"t":"set","p":"vacuum_current_map","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":200,"wires":[[]]},{"id":"a0efc2dff11d94d6","type":"mqtt-broker","name":"Home Assistant MQTT","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
# Tested on: Home Assistant 2021.12.5, 2021.12.8
# iframe only works if you connect to home assistant through http, if you use https you must set up
# a proxy through https to the vacuum, that can be done with nginx-proxy-manager, synology....
# If you use Congatudo-addon you can skip panel_iframe configuration
panel_iframe:
vacuum:
title: "Vacuum"
url: "http://<valetudo_or_ha_ip>:<valetudo_port>"
icon: "mdi:robot-vacuum"
rest:
- scan_interval: 5
resource: "http://<valetudo_or_ha_ip>:<valetudo_port>/api/v2/robot/state/attributes"
sensor:
- name: "Vacuum current clean area"
state_class: "measurement"
json_attributes_path: "$[4]"
json_attributes:
- __class
- metadata
- type
- value
value_template: >-
{% set current_value = int(value_json[4]['value'], 0) %}
{% if current_value > 0 %}
{{ current_value | float / 10000 }}
{% else %}
{{ current_value | float }}
{% endif %}
- name: "Vacuum current clean duration"
state_class: "total"
json_attributes_path: "$[3]"
json_attributes:
- __class
- metadata
- type
- value
value_template: >-
{{ int(value_json[3]['value'],0) }}
rest_command:
vacuum_accept_map:
url: "http://<valetudo_or_ha_ip>:<valetudo_port>/api/v2/robot/capabilities/PendingMapChangeHandlingCapability"
method: PUT
verify_ssl: false
content_type: "application/x-www-form-urlencoded"
payload: 'action=accept'
binary_sensor vacuum_pending_map:
platform: rest
scan_interval: 3
name: "Vacuum has pending map"
resource: "http://<valetudo_or_ha_ip>:<valetudo_port>/api/v2/robot/capabilities/PendingMapChangeHandlingCapability"
value_template: >-
{{ value_json['pending'] }}
binary_sensor vacuum_mop_attached:
platform: mqtt
name: "Vacuum Mop Attached"
# Change for yours <vacuum_mqtt_prefix>/<vacuum_identifier>/AttachmentStateAttribute/mop
state_topic: "valetudo/robot/AttachmentStateAttribute/mop"
payload_on: "true"
payload_off: "false"
qos: 0
binary_sensor vacuum_dustbin_attached:
platform: mqtt
name: "Vacuum Dustbin Attached"
# Change for yours <vacuum_mqtt_prefix>/<vacuum_identifier>/AttachmentStateAttribute/dustbin
state_topic: "valetudo/robot/AttachmentStateAttribute/dustbin"
payload_on: "true"
payload_off: "false"
qos: 0
binary_sensor vacuum_watertank_attached:
platform: mqtt
name: "Vacuum Watertank Attached"
# Change for yours <vacuum_mqtt_prefix>/<vacuum_identifier>/AttachmentStateAttribute/watertank
state_topic: "valetudo/robot/AttachmentStateAttribute/watertank"
payload_on: "true"
payload_off: "false"
qos: 0
sensor vacuum_today_cleaning_number:
platform: history_stats
name: "Vacuum today total cleanings"
# Change for your vacuum entity
entity_id: vacuum.robot
state: "cleaning"
type: "count"
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
sensor vacuum_today_cleaning_time:
platform: history_stats
name: "Vacuum total time cleaning today"
# Change for your vacuum entity
entity_id: vacuum.robot
state: "cleaning"
type: "time"
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
input_number:
vacuum_last_clean_area:
name: "Vacuum last clean area"
icon: "mdi:texture-box"
min: 0
max: 9999999
step: 1
mode: box
vacuum_last_clean_duration:
name: "Vacuum last clean duration"
icon: "mdi:timer"
min: 0
max: 9999999
step: 1
mode: box
script:
vacuum_accept_pending_map:
alias: Vacuum Accept Pending Map
sequence:
- service: rest_command.vacuum_accept_map
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: rest.reload
- service: persistent_notification.dismiss
data:
notification_id: "vacuum_pending_map"
mode: single
icon: "mdi:map-check-outline"
automation:
- alias: "Vacuum: Accept Pending Map"
description: "Accept pending map when accepted through notification"
trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "ACCEPT_VACUUM_PENDING_MAP"
condition:
- condition: state
entity_id: binary_sensor.vacuum_has_pending_map
state: 'on'
action:
- service: rest_command.vacuum_accept_map
- alias: 'Vacuum: Dismiss Pending Map Notifications'
description: 'Dismiss all possible to dismiss notifications when pending map is set to off'
trigger:
- platform: state
entity_id: binary_sensor.vacuum_has_pending_map
to: 'off'
from: 'on'
condition:
- condition: state
entity_id: binary_sensor.vacuum_has_pending_map
state: "off"
action:
- service: persistent_notification.dismiss
data:
notification_id: "vacuum_pending_map"
- service: notify.notify
data:
message: "clear_notification"
data:
tag: "vacuum_pending_map"
- alias: 'Vacuum: Notify Pending Map'
description: 'Notify if the vacuum has a pending map to be accepted'
trigger:
- platform: state
entity_id: binary_sensor.vacuum_has_pending_map
- platform: homeassistant
event: start
- platform: state
# Change for your vacuum entity
entity_id: vacuum.robot
condition:
- condition: and
conditions:
- condition: state
# Change for your vacuum entity
entity_id: vacuum.robot
state: docked
- condition: state
entity_id: binary_sensor.vacuum_has_pending_map
state: 'on'
action:
- service: persistent_notification.create
data:
notification_id: "vacuum_pending_map"
title: "Vacuum: Pending Map"
message: "The map of your vacuum should be accepted by running the script [`script.vacuum_accept_pending_map`](/config/script/dashboard)."
- service: notify.notify
data:
message: "Do you want to accept this map?"
title: "Vacuum map changed"
data:
tag: "vacuum_pending_map"
url: “/config/script/dashboard”
# To work this requires NODE-RED with the palette `node-red-contrib-valetudo`
# and also with the flow:
# [{"id":"68cdb83722fb413c","type":"tab","label":"Vacuum: Save map","disabled":false,"info":"Save current map to a png file in:\n/share/vacuum/current_map.png","env":[]},{"id":"3e8d57cacbf1b976","type":"mqtt in","z":"68cdb83722fb413c","name":"<valetudo_prefix>/<vacuum_identifier>/MapData/map-data","topic":"<valetudo_prefix>/<vacuum_identifier>/MapData/map-data","qos":"0","datatype":"auto","broker":"a0efc2dff11d94d6","nl":false,"rap":true,"rh":0,"inputs":0,"x":280,"y":140,"wires":[["983c7005bc28067a"]]},{"id":"e4f72565521ec2cf","type":"file","z":"68cdb83722fb413c","name":"/media/vacuum/current_map.png","filename":"/media/vacuum/current_map.png","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":940,"y":140,"wires":[[]]},{"id":"983c7005bc28067a","type":"valetudo-map-png","z":"68cdb83722fb413c","name":"","drawPath":true,"drawCharger":true,"drawRobot":true,"scale":4,"defer":2000,"cropX1":"","cropX2":"","cropY1":"","cropY2":"","x":650,"y":140,"wires":[["e4f72565521ec2cf","1a868008115d7360"]]},{"id":"e27d3dc13af41951","type":"comment","z":"68cdb83722fb413c","name":"Change the topic - Cambiar el topic","info":"The topic for your conga can be other and not this one, is probable: valetudo/robot...\nYou may change only until second slash \"/\" (not included the slash).\nTo know yours you can use mqtt explorer or see it in \"Congatudo Addon\" > \"Settings\" > \"MQTT\"\n\nUntil the first slash \"/\" is, in the absolute botton, the option \"Topic prefix\".\n\nThe next word (\"robot\" in my case), is the \"Identifier\".\n\n--\n\nEl topic para tu conga no tiene porque ser este, es probable que sea: valetudo/robot...\nSolo deberías cambiar hasta la segunda barra (no incluida).\nPuedes usar mqtt explorer para averiguarlo o verlo en el addon de congatudo > settings > mqtt\n\nHasta la primera barra \"/\" está abajo del todo, es la opción que se llama \"Topic prefix\".\n\nLo que va después (\"robot\" en mi caso) de la primera barra es el \"Identifier\".\n","x":270,"y":100,"wires":[]},{"id":"ace748d133cdfa03","type":"comment","z":"68cdb83722fb413c","name":"Path to store the map - Almacenar el mapa","info":"Here the path to the map. Important check that is checked \"Create Directory If It Doesn't Exist?\".\n\nTo used this map with actionable notifications you need to store on `/media` path.\n\n--\n\nAqui la ruta al mapa. Es importante que compruebes que está marcado \"Create Directory If It Doesn't Exist?\".\n\nPara ver el mapa en las notificaciones, necesitas almacenar el mapa en `/media`.\n","x":640,"y":100,"wires":[]},{"id":"932a6df3e920f0fb","type":"comment","z":"68cdb83722fb413c","name":"Save Map as file","info":"You should change:\n- \"valetudo\" for your vaccum topic.\n- \"robot\" for your vacuum identifier.\n","x":130,"y":60,"wires":[]},{"id":"1a868008115d7360","type":"base64","z":"68cdb83722fb413c","name":"","action":"","property":"payload","x":860,"y":200,"wires":[["22de8811fba8cde6"]]},{"id":"22de8811fba8cde6","type":"change","z":"68cdb83722fb413c","name":"","rules":[{"t":"set","p":"vacuum_current_map","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":200,"wires":[[]]},{"id":"a0efc2dff11d94d6","type":"mqtt-broker","name":"Home Assistant MQTT","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
image: "/media/local/vacuum/current_map.png"
actions:
- action: "ACCEPT_VACUUM_PENDING_MAP"
title: "Accept"
actiovationMode: "background"
icon: "mdi:map-check-outline"
activationMode: "background"
authenticationRequired: true
destructive: no
- action: "ACCEPT_VACUUM_PENDING_MAP"
title: "Dismiss"
activationMode: "background"
authenticationRequired: false
destructive: true
- action: "URI"
title: "Execute manually on App"
uri: "/config/script/dashboard"
- alias: 'Vacuum: Last Clean Area'
description: 'Update vacuum last clean area'
trigger:
- platform: state
entity_id: sensor.vacuum_current_clean_area
- platform: state
# Change for your vacuum entity
entity_id: vacuum.robot
to: cleaning
for:
hours: 0
minutes: 0
seconds: 2
#entity_id: sensor.vacuum_current_clean_area
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.vacuum_current_clean_area
above: '0'
- condition: state
# Change for your vacuum entity
entity_id: vacuum.robot
state: cleaning
action:
- service: input_number.set_value
data_template:
entity_id: input_number.vacuum_last_clean_area
value: >-
{{ states("sensor.vacuum_current_clean_area") | float(default=0) }}
mode: single
- alias: 'Vacuum: Update last Clean Duration'
description: 'Update vacuum last clean duration time'
trigger:
- platform: state
entity_id: sensor.vacuum_current_clean_duration
- platform: state
# Change for your vacuum entity
entity_id: vacuum.robot
to: cleaning
for:
hours: 0
minutes: 0
seconds: 2
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.vacuum_current_clean_duration
above: '0'
- condition: state
# Change for your vacuum entity
entity_id: vacuum.robot
state: cleaning
action:
- service: input_number.set_value
data_template:
entity_id: input_number.vacuum_last_clean_duration
value: >-
{{ int(states("sensor.vacuum_current_clean_duration"),0) }}
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment