Chore Helper binary_sensor

I’m using the custom integration Chore Helper.

On my dashboard I would like to have a conditional card that shows me that there are due or overdue tasks. When I press on it it takes me to a subview with all tasks.
Schermafbeelding 2024-03-26 153953

Everything is in place, except the conditional logic for this card.

What I would like to have is a template binary sensor that returns True when there are due or overdue tasks.

Every chore has a sensor entity where the state represents the days until the chore has to be executed. A negative value means it’s overdue and 0 means it’s due.

A list of the Chore entities can be acquired with this template:

{{ integration_entities('chore_helper') }}

Which returns:

['calendar.chores', 'sensor.onderhoud_gasketel', 'sensor.beddengoed_verschonen', 'sensor.onderhoud_vaatwasser', 'sensor.onderhoud_wasmachine', 'sensor.onderhoud_dampkap', 'sensor.doucheafvoer_reinigen', 'sensor.parket_onderhouden', 'sensor.zetel_inspuiten']

Now it’s get a little too complicated for me: I’m looking for a template that returns True when at least one of these sensor states is “value <= 0

Could someone point me in the right direction?

TYIA!

I managed to put together the template sensor. For anyone interested:

template:
  - trigger:
      platform: time_pattern
      minutes: "/5" # every 5 minutes
    binary_sensor:
      unique_id: chore_helper_active
      name: "Chore Helper Active"
      icon: mdi:account-hard-hat
      state: >
        {% set ns = namespace(chore_active=false) %}
        {% for state in states.sensor if state.entity_id in integration_entities('chore_helper') %}
          {% if state.state | float <= 0 %}
            {% set ns.chore_active = true %}
          {% endif %}
        {% endfor %}
        {{ ns.chore_active }}

Here’s an alternative that doesn’t start by selecting all sensors, only the ones in the chore_helper integration.

      state: >
        {{ integration_entities('chore_helper')
          | select('match', 'sensor') | map('states')
          | map('int', 'unknown') | reject('eq', 'unknown')
          | select('le', 0) | list | count > 0}}
1 Like