Im integrating with grocy and would like to have a simple button for chore completion. So the first think i’d like to do is check if the chore is due today. I have a sensor with multiple nested fields and I am just a bit too under qualified to figure this out. Here is what the sensor looks like.
sensor.grocy_chores
chores:
- id: 1
name: Open Blinds
description: ''
period_type: daily
period_config: ''
period_days: 0
track_date_only: false
rollover: true
assignment_type: in-alphabetical-order
assignment_config: '4'
next_execution_assigned_to_user_id: 4
userfields: null
last_tracked_time: null
next_estimated_execution_time: '2021-05-05T14:15:12+00:00'
last_done_by: null
track_count: null
next_execution_assigned_user:
id: 4
username: john
first_name: John
last_name: Gratis
display_name: John Gratis
unit_of_measurement: Chore(s)
friendly_name: Grocy chores
icon: 'mdi:broom'
Im trying to gather if the next_estimated_execution_time is today. What i’d like to do is truncate that to a date with only the day, aka 2021-05-05 and see if that matches today. What I have so far is this:
{{ state_attr('sensor.grocy_chores', 'chores')[0]['next_estimated_execution_time'] }}
That works. However, I cannot figure out how to get the specific chore i want! I was thinking it would be something along the lines of:
{{ state_attr('sensor.grocy_chores.chores', 'name')['Open Blinds']['next_estimated_execution_time'] }}
but nothing i do seems to work. I know I’m missing an elementary understanding somewhere, so hoping the community here can get me past this hurdle.
A bit more complicated
To extract the value do this
{% for item in states.sensor.grocy_chores.attributes.chores %}
{% if item['name'] == 'Open Blinds' %}
{{ item['next_estimated_execution_time'] }}
{% endif %}
{% endfor %}
To check if it is today, there multiple ways, but for example you can do this
{% for item in states.sensor.grocy_chores.attributes.chores %}
{% if item['name'] == 'Open Blinds' %}
{{ item['next_estimated_execution_time'].split('T')[0] == now().strftime('%Y-%m-%d') }}
{% endif %}
{% endfor %}
2 Likes
Thank you so much! I have not worked much with looping through objects, guess its time i learn! I do appreciate you taking the time to put that together, ill be reverse engineering it to my needs. thanks again.
Just wanted to resurrect this topic as I have a very similar problem.
Would there be a way to check if there are any chores due within the next 3 days?
What I ultimately want to do is have an area on my dashboard that only shows if there are chores due within 3 days (or possibly 1 day, but I’m guessing this would be relatively easy to change).
Here are the attributes for the sensor.grocy_chores entity:
state_class: measurement
chores:
- id: 1
name: Water Plants
description: ''
period_type: weekly
period_config: tuesday
period_days: 1
track_date_only: true
rollover: false
assignment_type: in-alphabetical-order
assignment_config: '2'
next_execution_assigned_to_user_id: 2
userfields: null
last_tracked_time: null
next_estimated_execution_time: '2023-04-19T23:59:59'
last_done_by: null
track_count: 0
next_execution_assigned_user:
id: 2
username: martin
first_name: Martin
last_name: Granger
display_name: Martin Granger
- id: 2
name: test chore
description: ''
period_type: weekly
period_config: friday
period_days: 1
track_date_only: true
rollover: false
assignment_type: in-alphabetical-order
assignment_config: '2'
next_execution_assigned_to_user_id: 2
userfields: null
last_tracked_time: '2023-04-20T00:00:00'
next_estimated_execution_time: '2023-04-28T23:59:59'
last_done_by:
id: 1
username: admin
first_name: null
last_name: null
display_name: admin
track_count: 0
next_execution_assigned_user:
id: 2
username: martin
first_name: Martin
last_name: Granger
display_name: Martin Granger
count: 2
unit_of_measurement: Chore(s)
icon: mdi:broom
friendly_name: Grocy chores
Thanks - I’m actually using that card, but I only want it to appear if there is a chore due. That’s where the template needs to come in I think.
Have you tried setting show_empty: false
? I’ve got a bunch of chores due right now, so I can’t test it…
If that doesn’t work, you could use a Conditional card, but they do not accept templates, so you would need to set up a template binary sensor.
{% set days = 3 %}
{{ state_attr('sensor.grocy_chores', 'chores')
| map(attribute ='next_estimated_execution_time')
| sort | reject('gt', (today_at()+timedelta(days=(days+1)))|string)
| list | count > 0 }}
I dont think the show_empty: will fork as with chores, many of them are weekly therefore even if you have done all the chores, they still remain.
I’ll give the template a go - thanks for looking at it
This works great! Many thanks for your help!
Just for completion if others find this:
I created two sensors, one for Chores and one for Taks:
I could then use these as conditions in the conditional card to display the Grocy lists.
- platform: template
sensors:
tasks_check:
friendly_name: 'Tasks Check'
value_template: >
{% set days = 3 %}
{{ state_attr('sensor.grocy_tasks', 'tasks')
| map(attribute ='count')
| list | count > 0 }}
- platform: template
sensors:
chores_check:
friendly_name: 'Chores Check'
value_template: >
{% set days = 3 %}
{{ state_attr('sensor.grocy_chores', 'chores')
| map(attribute ='next_estimated_execution_time')
| sort | reject('gt', (today_at()+timedelta(days=(days+1)))|string)
| list | count > 0 }}
1 Like
Hi Martin_Granger,
Umm. would you mind sharing How you created the two sensors sensor.grocy_chores & sensor.grocy_tasks?
They are created by installing the Grocy chores card in HACS: