224 lines
7.6 KiB
YAML
224 lines
7.6 KiB
YAML
---
|
|
|
|
homeassistant:
|
|
customize:
|
|
package.node_anchors:
|
|
common_attrs: &common_attrs
|
|
package: "vacuum_robot"
|
|
common_attrs_templated: &common_attrs_templated
|
|
templated: true
|
|
<<: *common_attrs
|
|
|
|
sensor.vacuum_robot_segments:
|
|
friendly_name: "vacuum-robot Segments"
|
|
source_entity_id: "sensor.valetudo_vacuum_robot_map_segments"
|
|
comment: "Newer one with more jinja magic"
|
|
<<: *common_attrs
|
|
|
|
sensor.vacuum_robot_segments_2:
|
|
friendly_name: "vacuum-robot Segments 2"
|
|
source_entity_id: "sensor.valetudo_vacuum_robot_map_segments"
|
|
comment: "Older one I forgot I made, less jinja magic"
|
|
<<: *common_attrs
|
|
|
|
sensor.wifi_signal_vacuum_robot:
|
|
friendly_name: "Vacuum robot WiFi signal"
|
|
<<: *common_attrs_templated
|
|
|
|
sensor.vacuum_robot_current_area:
|
|
friendly_name: "Vacuum robot current area"
|
|
<<: *common_attrs_templated
|
|
|
|
sensor.vacuum_robot_total_area:
|
|
friendly_name: "Vacuum robot total area"
|
|
<<: *common_attrs_templated
|
|
|
|
sensor.battery_level_vacuum_robot:
|
|
friendly_name: "Vacuum robot"
|
|
<<: *common_attrs_templated
|
|
|
|
binary_sensor.vacuum_robot:
|
|
friendly_name: "Vacuum robot"
|
|
<<: *common_attrs_templated
|
|
|
|
binary_sensor.vacuum_robot_charging:
|
|
friendly_name: "Vacuum robot charging"
|
|
<<: *common_attrs_templated
|
|
|
|
sensor.vacuum_robot_last_cleaned:
|
|
friendly_name: "Vacuum robot last cleaned"
|
|
<<: *common_attrs_templated
|
|
|
|
input_boolean.vacuum_robot_closed_room:
|
|
friendly_name: Vacuum robot cleaning a closed room (no return to dock)
|
|
<<: *common_attrs
|
|
|
|
|
|
|
|
input_boolean:
|
|
vacuum_robot_closed_room:
|
|
name: vacuum_robot_closed_room
|
|
icon: "mdi:robot-vacuum"
|
|
|
|
template:
|
|
- sensor:
|
|
- name: vacuum_robot_segments
|
|
unique_id: vacuum_robot_segments
|
|
icon: mdi:vector-selection
|
|
unit_of_measurement: areas
|
|
availability: |
|
|
{{ has_value(this.attributes.get("source_entity_id")|string) }}
|
|
state: |
|
|
{{ states(this.attributes.source_entity_id) }}
|
|
# Amazingly, this doesnt raise an error and instead returns an empty list:
|
|
# {{ states['sensor.foobar'].attributes | items | list }}
|
|
# The 'states.' part is important, otherwise it does raise an error, works with
|
|
# any domain.
|
|
#
|
|
# Using 'states' as a dict seems to be syntactic sugar, since the same is true for
|
|
# {{ states.sensor.foobar.attributes | items | list }}
|
|
#
|
|
# This seems to rely on the 'list' filter returning an empty list if there is an error,
|
|
# which is not standard jinja. So using the 'default' filter makes it more clear.
|
|
#
|
|
# Both of these work the same, and return '{}' as expected
|
|
# {{ states.sensor.foobar.attribute|default({}) }}
|
|
# {{ states['sensor.foobar].attributes|default({}) }}
|
|
#
|
|
# Since we have the source entity id in an attribute, we use the dict syntactic sugar.
|
|
#
|
|
# It's worh nothing that 'map("reverse")' returns a generator, and at that point we
|
|
# have a list of generators.
|
|
#
|
|
# Sidenote: I figured out experimenting with this is using 'map(attribute="0")', but
|
|
# I didnt get very far with that one.
|
|
attributes:
|
|
map: |
|
|
{% set attrs = states[this.attributes.source_entity_id].attributes|default({}) -%}
|
|
{%
|
|
set segments = attrs
|
|
| items
|
|
| selectattr("0", "is_number")
|
|
| map("reverse")
|
|
%}
|
|
{{ dict(segments) }}
|
|
|
|
|
|
# This also works, I forgot I had made this
|
|
- name: vacuum_robot_segments_2
|
|
unique_id: vacuum_robot_segments_2
|
|
icon: mdi:vector-selection
|
|
unit_of_measurement: areas
|
|
state: |
|
|
{{ states(this.attributes.source_entity_id) }}
|
|
availability: |
|
|
{{ has_value(this.attributes.get("source_entity_id")|string) }}
|
|
attributes:
|
|
map: |
|
|
{% set source_entity_id = this.attributes.get("source_entity_id") -%}
|
|
{% set source_sensor = source_entity_id.split(".")[1] -%}
|
|
{% for attr in states.sensor[source_sensor].attributes.items()|default([]) -%}
|
|
{% if is_number(attr[0]) -%}
|
|
{{ attr[1] }}: {{ attr[0] }}
|
|
{% endif -%}
|
|
{% endfor %}
|
|
|
|
|
|
- name: wifi_signal_vacuum_robot
|
|
unique_id: wifi_signal_vacuum_robot
|
|
state_class: measurement
|
|
device_class: power_factor
|
|
unit_of_measurement: "%"
|
|
icon: >-
|
|
mdi:wifi
|
|
availability: >-
|
|
{{ is_number(states("sensor.valetudo_vacuum_robot_wi_fi_configuration")) }}
|
|
state: >-
|
|
{% set x = states("sensor.valetudo_vacuum_robot_wi_fi_configuration") %}
|
|
{{
|
|
min(max(2 * (x|float + 100.0), 0.0), 100.0)
|
|
}}
|
|
|
|
- name: vacuum_robot_total_area
|
|
unique_id: vacuum_robot_total_area
|
|
state_class: measurement
|
|
unit_of_measurement: "m²"
|
|
availability: >-
|
|
{{ is_number(states("sensor.valetudo_vacuum_robot_total_statistics_area")) }}
|
|
state: >-
|
|
{% set sqcm = states("sensor.valetudo_vacuum_robot_total_statistics_area") %}
|
|
{% set sqm = sqcm|float / (100*100) %}
|
|
{{ sqm | float | round(2) }}
|
|
|
|
- name: vacuum_robot_current_area
|
|
unique_id: vacuum_robot_current_area
|
|
state_class: measurement
|
|
unit_of_measurement: "m²"
|
|
availability: >-
|
|
{{ is_number(states("sensor.valetudo_vacuum_robot_current_statistics_area")) }}
|
|
state: >-
|
|
{% set sqcm = states("sensor.valetudo_vacuum_robot_current_statistics_area") %}
|
|
{% set sqm = sqcm|float / (100*100) %}
|
|
{{ sqm | float | round(2) }}
|
|
|
|
- name: battery_level_vacuum_robot
|
|
unique_id: battery_level_vacuum_robot
|
|
state_class: measurement
|
|
device_class: "battery"
|
|
unit_of_measurement: "%"
|
|
availability: >-
|
|
{{ is_number(state_attr("vacuum.valetudo_meatyenchantedsquirrel", "battery_level")) }}
|
|
state: >-
|
|
{{ state_attr("vacuum.valetudo_meatyenchantedsquirrel", "battery_level") }}
|
|
|
|
- binary_sensor:
|
|
- name: vacuum_robot
|
|
unique_id: vacuum_robot
|
|
icon: |
|
|
{% if is_state(this.entity_id, "on") %}
|
|
mdi:robot-vacuum
|
|
{% else %}
|
|
mdi:robot-vacuum-off
|
|
{% endif %}
|
|
availability: |
|
|
{{ has_value("vacuum.valetudo_meatyenchantedsquirrel") }}
|
|
device_class: running
|
|
state: |
|
|
{% set vac = "vacuum.valetudo_meatyenchantedsquirrel" %}
|
|
{{
|
|
is_state(vac, "cleaning")
|
|
or not (
|
|
is_state(vac, "docked")
|
|
or is_state(vac, "paused")
|
|
or is_state(vac, "idle")
|
|
or is_state(vac, "off")
|
|
)
|
|
}}
|
|
|
|
- name: vacuum_robot_charging
|
|
unique_id: vacuum_robot_charging
|
|
icon: |
|
|
{{ state_attr("vacuum.valetudo_meatyenchantedsquirrel", "battery_icon") }}
|
|
availability: >-
|
|
{{ has_value("vacuum.valetudo_meatyenchantedsquirrel") }}
|
|
device_class: battery_charging
|
|
state: >-
|
|
{{ "charging" in state_attr("vacuum.valetudo_meatyenchantedsquirrel", "battery_icon") }}
|
|
|
|
- trigger:
|
|
- platform: state
|
|
entity_id:
|
|
- binary_sensor.vacuum_robot
|
|
from: "off"
|
|
to: "on"
|
|
sensor:
|
|
- name: vacuum_robot_last_cleaned
|
|
unique_id: vacuum_robot_last_cleaned
|
|
icon: mdi:robot-vacuum
|
|
device_class: timestamp
|
|
state: |
|
|
{{ now().isoformat() }}
|
|
|
|
|
|
|