Help with vacuum automation Getting specific sub attribute of another attribute

Hi there,

I’m pretty new to automations and templating in Home Assistant.

I’m trying to achieve a new condition for my roomba automation.

I’m trying to read the attribute “completed” from the entity “sensor.noo_noo_cleaning_history” from todays cleaning jobs (Attribute block starts with date + Starttime) which will be “false” or “true” depending, if the roomba finished cleaning or not.

To do so, I’ve read a lot about templating but the issue is, I can not simply read the attribute without specifying the date and start-time of the cleaning job, because the completed attribute is part of the whole Cleaning-Job attribute. The value will change each time a cleaning job is started, and I would like to regex for todays date.

Something like

{{state_attr(‘sensor.noo_noo_cleaning_history’,$(today.completed)) }}

Here’s what I came up with so far:

In the template section I’m able to read the attribute by defining the actual cleaning job in a specific format

{{state_attr(‘sensor.noo_noo_cleaning_history’,‘09-23 13:30’) }}

which will give me:

{‘timestamp’: 1727091007.0, ‘cleaning_time’: ‘0 min’, ‘cleaned_area’: ‘1 m²’, ‘status’: ‘Cleaning’, ‘completed’: False, ‘water_tank’: ‘Not installed’}

The issue is I only need the attribute “completed” of this output and I also want to read the attributes of all of the cleaning jobs of today without knowing the exact time. e.g. “09-23 *”.

To simplify:
I just need the information if any cleaning-job of today has been completed.

How do I extract this sub-attribute from my entity?

Screenshot of the entity with the attributes:

The automation looks like this:

alias: Roomba Automation V 2.0
description: >-
 When nobody is at home, or by 13:30 everyday, the roomba will check if today was already cleaned. If not, it will do so.
trigger:
  - platform: state
    entity_id:
      - zone.home
    to: "0"
    from: "1"
  - platform: time
    at: "13:30:00"
condition:
  - condition: or
    conditions:
      - condition: template
        value_template: >-
          {{states.sensor.noo_noo_cleaning_history.last_changed.day !=
          now().day}}
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{states.sensor.noo_noo_cleaning_history.last_changed.day ==
              now().day}}
          - condition: numeric_state
            entity_id: sensor.noo_noo_cleaned_area
            below: 30
action:
  - device_id: 96a0196aa052b18e902568b640fbed8c
    domain: vacuum
    entity_id: edaec8e0a5656e916552e9a4343bbc8a
    type: clean
mode: single

At the moment I found a workaround by reading the “cleaned_area” Entity, while I know, that the total cleaning amount will always be higher than 30 if completed. But it’s not as clever as I want it to be.

Any help is greatly appreciated as I like to dive deepter into templating and automations.

Can you post the results of this template in from the template editor as text, not an image? (Developer tools → template)

{{ states.sensor.noo_noo_cleaning_history.attributes }}

Sure,

{'09-23 13:30': {'timestamp': 1727091007.0, 'cleaning_time': '0 min', 'cleaned_area': '1 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-23 10:21': {'timestamp': 1727079680.0, 'cleaning_time': '37 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-21 16:36': {'timestamp': 1726929418.0, 'cleaning_time': '37 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-20 13:30': {'timestamp': 1726831808.0, 'cleaning_time': '0 min', 'cleaned_area': '0 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-19 17:18': {'timestamp': 1726759100.0, 'cleaning_time': '39 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-19 13:30': {'timestamp': 1726745408.0, 'cleaning_time': '0 min', 'cleaned_area': '0 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-18 16:41': {'timestamp': 1726670517.0, 'cleaning_time': '39 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-18 15:56': {'timestamp': 1726667816.0, 'cleaning_time': '15 min', 'cleaned_area': '16 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-18 13:46': {'timestamp': 1726659991.0, 'cleaning_time': '42 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-17 16:07': {'timestamp': 1726582042.0, 'cleaning_time': '38 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-16 17:12': {'timestamp': 1726499543.0, 'cleaning_time': '41 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-15 18:30': {'timestamp': 1726417842.0, 'cleaning_time': '40 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-14 15:53': {'timestamp': 1726322022.0, 'cleaning_time': '35 min', 'cleaned_area': '32 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-14 13:30': {'timestamp': 1726313407.0, 'cleaning_time': '0 min', 'cleaned_area': '0 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-13 12:28': {'timestamp': 1726223283.0, 'cleaning_time': '0 min', 'cleaned_area': '0 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-12 13:30': {'timestamp': 1726140607.0, 'cleaning_time': '39 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-11 11:10': {'timestamp': 1726045853.0, 'cleaning_time': '43 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-10 15:01': {'timestamp': 1725973310.0, 'cleaning_time': '0 min', 'cleaned_area': '0 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-10 14:16': {'timestamp': 1725970606.0, 'cleaning_time': '40 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-08 14:31': {'timestamp': 1725798705.0, 'cleaning_time': '36 min', 'cleaned_area': '33 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-07 14:57': {'timestamp': 1725713875.0, 'cleaning_time': '33 min', 'cleaned_area': '32 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-06 12:04': {'timestamp': 1725617091.0, 'cleaning_time': '44 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-04 16:28': {'timestamp': 1725460132.0, 'cleaning_time': '0 min', 'cleaned_area': '1 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, '09-04 13:30': {'timestamp': 1725449410.0, 'cleaning_time': '39 min', 'cleaned_area': '34 m²', 'status': 'Cleaning', 'completed': True, 'water_tank': 'Not installed'}, '09-04 12:03': {'timestamp': 1725444230.0, 'cleaning_time': '3 min', 'cleaned_area': '4 m²', 'status': 'Cleaning', 'completed': False, 'water_tank': 'Not installed'}, 'device_class': 'timestamp', 'icon': 'mdi:clipboard-text-clock', 'friendly_name': 'Noo Noo Cleaning History'}

Yah, I need the full result. Not abbreviated.

If you’re worried about sensitive information, PM it to me

Ok, so which one do you want? There’s 2 cleaning times for today one is complete the other is not

{% set attributes = states.sensor.noo_noo_cleaning_history.attributes %}
{% set today = '^' ~ (now().date() | string)[5:] %}
{% set last_cleaning = attributes.items() | selectattr('0', 'search', today) | sort(attribute='0', reverse=True) | map(attribute='1') | first | default({}) %}
{{ last_cleaning.completed }}

That will get you the last ran cleaning today

Thank you so much! This will get the job done.