MontyRisk
(Monty Risk)
November 5, 2021, 2:53pm
1
I have several Roborock vacuums and have one automation for all vacuums to provide a notification when complete. I took advantage of some of the dynamic attributes to do so.
Since some of the attributes have been changed to sensors, I am at a loss to get up and running again. How can I dynamically use the value_template to evaluate a sensor based on the vacuum being docked since I used to use the attributes?
The names of the sensors I could use are (and repeat for the other two vacuums respectively)
sensor.one_last_clean_start
sensor.one_last_clean_end
sensor.one_last_clean_duration
- alias: Vacuum - Completed
trigger:
- platform: state
entity_id:
- vacuum.one
- vacuum.two
- vacuum.three
from: 'returning'
to: 'docked'
condition:
- condition: template
value_template: "{{ as_timestamp(trigger.to_state.attributes.clean_stop)-as_timestamp(trigger.to_state.attributes.clean_start) < 25000}}"
123
(Taras)
November 5, 2021, 3:22pm
2
Post examples of the values of sensor.one_last_clean_start
and sensor.one_last_clean_end
.
MontyRisk
(Monty Risk)
November 5, 2021, 4:02pm
3
sensor.one_last_clean_start: 2021-11-05T08:00:01
sensor.one_last_clean_end: 2021-11-05T09:24:56
sensor.one_last_clean_duration: 5095
123
(Taras)
November 5, 2021, 5:04pm
4
Try this
condition:
- condition: template
value_template: >
{% set start = 'sensor.{}_last_clean_start'.format(trigger.to_state.object_id) | as_timestamp %}
{% set end = 'sensor.{}_last_clean_end'.format(trigger.to_state.object_id) | as_timestamp %}
{{ end - start < 25000 }}
MontyRisk
(Monty Risk)
November 5, 2021, 6:14pm
5
Thanks. I received this error:
Error evaluating condition in ‘Vacuum - Completed’: In ‘condition’: In ‘template’ condition: TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’
MontyRisk
(Monty Risk)
November 5, 2021, 7:20pm
7
- alias: Vacuum - Completed
trigger:
- platform: state
entity_id:
- vacuum.one
- vacuum.two
- vacuum.three
from: 'returning'
to: 'docked'
condition:
- condition: template
value_template: >
{% set start = 'sensor.{}_last_clean_start'.format(trigger.to_state.object_id) | as_timestamp %}
{% set end = 'sensor.{}_last_clean_end'.format(trigger.to_state.object_id) | as_timestamp %}
{{ end - start < 25000 }}
# - condition: template
# value_template: "{{ as_timestamp(trigger.to_state.attributes.clean_stop)-as_timestamp(trigger.to_state.attributes.clean_start) < 25000}}"
# - condition: template
# value_template: "{{ as_timestamp(trigger.to_state.attributes.clean_stop) | timestamp_custom('%Y-%m-%d') == states('sensor.date') }}"
action:
- service: notify.bullet
data_template:
title: "Vacuum Complete"
message: "{% if trigger.entity_id == 'vacuum.one' and now().isoweekday() == 3 and as_timestamp(now()) | timestamp_custom('%H') < '07' %}
Bedroom Vacuum Completed
{% elif trigger.entity_id == 'vacuum.one' and now().isoweekday() == 1 and as_timestamp(now()) | timestamp_custom('%H') < '07' %}
Dining Room Vacuum Completed
{% else %}
{{ state_attr(trigger.entity_id, 'friendly_name') }} Vacuum Completed
{% endif %}"
123
(Taras)
November 5, 2021, 7:22pm
8
Did you test it by making one of the three vacuums change state from returning
to docked
?
123
(Taras)
November 5, 2021, 7:31pm
10
OK. I see my mistake now. I forgot to include the states()
function!
Try this revised version.
condition:
- condition: template
value_template: >
{% set start = states('sensor.{}_last_clean_start'.format(trigger.to_state.object_id)) | as_timestamp %}
{% set end = states('sensor.{}_last_clean_end'.format(trigger.to_state.object_id)) | as_timestamp %}
{{ end - start < 25000 }}
MontyRisk
(Monty Risk)
November 5, 2021, 7:42pm
11
That did the trick! Thank you very much!!!
1 Like