Skip to content

Instantly share code, notes, and snippets.

@lcnittl
Last active November 29, 2021 20:10
Show Gist options
  • Save lcnittl/37eb489d0577db0cd10f2724862ee3c1 to your computer and use it in GitHub Desktop.
Save lcnittl/37eb489d0577db0cd10f2724862ee3c1 to your computer and use it in GitHub Desktop.
Home Assistant automation for Deebot-4-Home-Assistant to check whether all rooms are correctly configured in the robot
alias: Vacuum Check Room Config
description: ''
trigger:
- platform: device
device_id: "ENTER DEVICE ID"
domain: vacuum
entity_id: vacuum.rambot
type: docked
condition:
- condition: or
conditions:
- condition: template
value_template: >-
{# Are any rooms from the list missing in the robot? -> true #}
{%- set missing_room = namespace(is_any=false) -%}
{%- for room in rooms -%}
{%- set room_is_missing = room not in state_attr(trigger.entity_id, "rooms") -%}
{%- set missing_room.is_any = missing_room.is_any or room_is_missing -%}
{%- endfor -%}
{{ missing_room.is_any }}
- condition: template
value_template: >-
{# Are any rooms from the robot missing in the list? -> true #}
{%- set sperfluous_room = namespace(is_any=false) -%}
{%- for room in state_attr(trigger.entity_id, "rooms") -%}
{%- set room_is_superfluous = room not in rooms -%}
{%- set sperfluous_room.is_any = sperfluous_room.is_any or room_is_superfluous -%}
{%- endfor -%}
{{ sperfluous_room.is_any }}
action:
- service: notify.all_devices
data:
message: >-
{# Notify about missing rooms, if any #}
{%- set var_store = namespace(missing_rooms=[]) -%}
{%- for room in rooms -%}
{%- set room_is_missing = room not in state_attr(trigger.entity_id, "rooms") -%}
{%- if room_is_missing -%}
{%- set var_store.missing_rooms = var_store.missing_rooms + [room] -%}
{%- endif -%}
{%- endfor -%}
{%- if var_store.missing_rooms|length > 0 -%}
Missing room{%- if var_store.missing_rooms|length > 1 -%}s{%- endif -%}: {{ var_store.missing_rooms|join(", ") }}.
{%- endif %}
{# Notify about superfluous rooms, if any #}
{%- set var_store = namespace(superfluous_rooms=[]) -%}
{%- for room in state_attr(trigger.entity_id, "rooms") -%}
{%- set room_is_superfluous = room not in rooms -%}
{%- if room_is_superfluous -%}
{%- set var_store.superfluous_rooms = var_store.superfluous_rooms + [room] -%}
{%- endif -%}
{%- endfor -%}
{%- if var_store.superfluous_rooms|length > 0 -%}
Superfluous room{%- if var_store.superfluous_rooms|length > 1 -%}s{%- endif -%}: {{ var_store.superfluous_rooms|join(", ") }}.
{%- endif %}
title: '{{ state_attr(trigger.entity_id, ''friendly_name'') }} Room Config Error'
data:
url: /lovelace/cleaning
clickAction: /lovelace/cleaning
group: Vacuum Error
color: '#BB1E10'
mode: single
variables:
rooms:
- bathroom
- bedroom
- corridor
- kids_room
- kitchen
- living_room
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment