Today a blog about the household and how you can make it a little bit smarter, and easy to track. If you have a house then you can’t escape it, someday you’ll have to do something in the household if you want to live comfortably.
The usecase
I want to be able to keep track in Home Assistant when a household task was last done, how many days ago and with a simple click I can change the date to today. This works with the main tasks that come back once a week or 2 weeks.
Inspired by a piece of paper with tasks in a week schedule, I started to convert this usecase into something workable in Home Assistant. Below I will discuss what I have made per integration / platform in Home Assistant. You can find the references to the github files by clicking on the name of a yaml file.
Input_datetime
First I created an input_datetime for each task, provided with a friendly name and a tracking on the date only (in my view time is not necessary). See also code below.
vacuuming:
name: Vacuuming
has_date: true
Sensor
Then we use a template sensor to calculate when a task was last done in days. It’s important that you first make a date or time sensor of the time_date integration. Then you can make the template sensors, don’t forget the “entity_id: sensor.date“ or “entity_id: sensor.time”! This ensures that the template sensor updates itself every day or every minute, because it responds to the state change of the entity.
# Vacuuming
template:
- sensors:
- name: Days after vacuuming
entity_id: sensor.time
unit_of_measurement: 'days'
value_template: "{{ ((as_timestamp(now()) - state_attr('input_datetime.vacuuming','timestamp')) | int / 86400) | round(0) }}"
Input_select
We are now going to work on the piece in which we can adjust the date.
To update the date I use an input_select for choosing the task.
household_task:
name: Select Household Task
options:
- Stofzuigen
- Dweilen
- Badkamer schoonmaken
- Toilet schoonmaken
- Afstoffen
- Beddengoed verschonen
- Studio opruimen
Script
Then I created a script, that actually updates the date when you press execute and it knows which task it needs to update, based on the input_select from above.
set_date_household_task:
alias: 'Zet datum op vandaag'
sequence:
- service: input_datetime.set_datetime
data_template:
entity_id: >
{% if is_state ("input_select.household_task", "Stofzuigen") %} input_datetime.vacuuming
{% elif is_state ("input_select.household_task", "Dweilen") %} input_datetime.mopping
{% elif is_state ("input_select.household_task", "Badkamer schoonmaken") %} input_datetime.cleaning_the_bathroom
{% elif is_state ("input_select.household_task", "Toilet schoonmaken") %} input_datetime.clean_the_toilet
{% elif is_state ("input_select.household_task", "Afstoffen") %} input_datetime.dust_off
{% elif is_state ("input_select.household_task", "Beddengoed verschonen") %} input_datetime.change_bedding
{% elif is_state ("input_select.household_task", "Studio opruimen") %} input_datetime.clean_up_studio
{% endif %}
date: '{{ now().strftime("%Y-%m-%d") }}'
Lovelace layout
We can now make a start on the layout in lovelace.
For this I use a number of cards and I also made a separate view in my config.
The structure
-| Vertical stack in card
—-| Love lock card
——–| Entities card
————| Secondaryinfo entity row card
—-| Entities card
I have divided it into 2 parts:
– 1st part shows the tasks with number of days ago and the date.
– 2nd part is to select and update a task with a new date.
title: Huishouden
icon: mdi:calendar-check
path: household
cards:
- type: custom:stack-in-card
mode: vertical
cards:
- type: 'custom:love-lock-card'
popup: confirm
cards:
- type: entities
title: Huishoudelijke Taken
show_header_toggle: false
entities:
- entity: input_datetime.vacuuming
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_vacuuming.state ]] Dagen geleden"
- entity: input_datetime.mopping
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_mopping.state ]] Dagen geleden"
- entity: input_datetime.cleaning_the_bathroom
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_cleaning_the_bathroom.state ]] Dagen geleden"
- entity: input_datetime.clean_the_toilet
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_clean_the_toilet.state ]] Dagen geleden"
- entity: input_datetime.dust_off
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_dust_off.state ]] Dagen geleden"
- entity: input_datetime.change_bedding
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_change_bedding.state ]] Dagen geleden"
- entity: input_datetime.clean_up_studio
type: custom:secondaryinfo-entity-row
secondary_info: "[[ sensor.days_after_clean_up_studio.state ]] Dagen geleden"
- type: entities
title: Werk Taak Bij
show_header_toggle: false
entities:
- input_select.household_task
- script.set_date_household_task
To prevent that you can simply change the date, the first part is in a love lock card and the number of days ago I show through a secondaryinfo entity row card.
Notifications
After publishing, there appeared to be some little problems in the notification, which I have now hopefully fixed. The blog has been adjusted to the new changes. Related Github commit.
Finally, I wanted Home Assistant to send a notification when a task had to be picked up.
For this automation I spent a whole night for brainstorming and debugging, the challenge was to cram everything into 1 automation (I failed 🙁 ), in a way that everything works well and the action only returns tasks that exceed the threshold.
Afterwards I split the first automation into 2 automations, one for triggering and giving the green light. The other will actually send the notification based on the given green light.
- alias: '[House] - Household task over date'
description: >-
Trigger when task comes above certain value
id: 670c5c63-4a1d-4bd3-a473-2933673cce3b
mode: single
trigger:
- platform: numeric_state
entity_id:
- sensor.days_after_clean_up_studio
- sensor.days_after_change_bedding
- sensor.days_after_clean_the_toilet
- sensor.days_after_cleaning_the_bathroom
above: 13
- platform: numeric_state
entity_id:
- sensor.days_after_dust_off
- sensor.days_after_vacuuming
- sensor.days_after_mopping
above: 6
condition:
# This prevents triggering after every HA restart
- condition: state
entity_id: input_boolean.maintenance_mode
state: 'off'
# Prevents multiple notify messages :)
- condition: state
entity_id: input_boolean.task_notify
state: 'off'
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.task_notify
# Send the notification
- alias: '[House] - Send household tasks overview'
description: >-
Send a notification via Telegram about household
id: 908c4538-a60d-4a66-8b24-fb8b2680b66c
mode: single
trigger:
- platform: state
entity_id: input_boolean.task_notify
to: 'on'
action:
- service: notify.telegram_klaas
data_template:
title: '*Huishoudelijke reminder!*'
message: |-
Je moet nog de volgende taken doen:
{% if (states('sensor.days_after_dust_off') | int) > 6 %} - Afstoffen ({{ states('sensor.days_after_dust_off') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_vacuuming') | int) > 6 %} - Stofzuigen ({{ states('sensor.days_after_vacuuming') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_mopping') | int) > 6 %} - Dweilen ({{ states('sensor.days_after_mopping') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_clean_up_studio') | int) > 13 %} - Studio opruimen ({{ states('sensor.days_after_clean_up_studio') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_change_bedding') | int) > 13 %} - Beddengoed verschonen ({{ states('sensor.days_after_change_bedding') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_clean_the_toilet') | int) > 13 %} - Toilet schoonmaken ({{ states('sensor.days_after_clean_the_toilet') }} dagen geleden) {% endif %}
{% if (states('sensor.days_after_cleaning_the_bathroom') | int) > 13 %} - Badkamer schoonmaken ({{ states('sensor.days_after_cleaning_the_bathroom') }} dagen geleden) {% endif %}
- delay:
seconds: 2
- service: input_boolean.turn_off
target:
entity_id: input_boolean.task_notify
First automation
The first automation is triggered based on when the number of days (numeric_state) from the task sensors exceeds a certain value (also called as threshold), in this case above 6 (1 week) or 13 (2 weeks). There are now also several conditions. The first is to prevent you from receiving a notification every time you restart Home Assistant. I prevent this with a input_boolean thats requiring my maintenance mode to be “off” (I always have this mode “on” when I working on the config).
condition:
# This prevents triggering after every HA restart
- condition: state
entity_id: input_boolean.maintenance_mode
state: 'off'
The following condition is to prevent you from being spammed several times in succession with the same notification. If 2 or more count sensors exceed the threshold value, only the first one now comes through. I do this by adding an extra input_boolean that must also be switched “off”.
input_boolean:
task_notify:
name: Huishoudelijke notificatie
icon: mdi:checkbox-multiple-marked-outline
# Prevents multiple notify messages :)
- condition: state
entity_id: input_boolean.task_notify
state: 'off'
The action consists of no more than turning “on” the same input_boolean (task_notify) from above.
Second automation
The 2nd automation is triggered by the state change from the input_boolean (task_notify) to “on”.
The action is full of if statements, per task it checks whether the sensor value is above the threshold. If so then the task will be displayed in the message, if not then it will be an empty line. As an extra option, it also shows the number of days from the task sensors.
What brings the future?
In the future I would like to determine the threshold value with an input_number, probably the automation will have to be split if you want to use more than 1 threshold.
Are things not clear? Or if you have come to ideas by reading this blog, about how I can make it cooler and better? Share it with me! Via Twitter, mail or Github.
Alternative
If you afterwards think that this approach does not suit in your config (which is possible ofcourse), then take a look at the Grocy add-on, the custom component from Grocy and the custom lovelace card from Isa (@teachingbirds).
3 comments
I really like this post! Thanks a lot.
I did find two dead link. Which are the first link in the Sensor paragraph and the link in the Script paragraph.
Thnx for letting me know! It has also been immediately adjusted.
Thanks for your posting, that’s exactly what I am looking for: to utilize a mechanism to track and remind me of some recurring maintenance tasks like changing the filter of the extractor hood, cleaning up the brewing unit in the coffee machine or checking the water pressure in the gas boiler..
I found different solutions for this but yours is the cleanest I found. I like it, thank you!