Time automation for my cats

I’m trying to change up the feeding time for my cats. I have a whole home announcement telling humans and cats that it’s “dinner time” (which means the cats don’t nag us as much).

Because I’m experimenting with quantity and time of feedings, I really want something that is easily adjustable. Right now, I have multiple timers, automations, template sensors, input booleans, and time/date stamps. If I want to change feedings from 3 hours apart to 2.5 hours apart, that’s a lot of places to change.

This is the template sensor I’m currently using:

{{ (today_at(states('input_datetime.cats_last_fed_at')) + timedelta(hours = states('input_number.cats_will_be_fed_in_x_intervals') | float(0))).strftime('%H:%M:%S') }}

It looks at the last time the cats were fed, looks to see how many hours apart the feedings are, and then gives me a time. Perfect.

Except, if I create it as helper template with a device class of “timestamp” it renders as result as “unknown”. Fair enough.

So, in the automations, I’m using these for each time frame.

{{ now().hour >= 10 and now().hour < 13 and is_state('input_boolean.cats_1st_feeding_done','off')  }}
{{ now().hour >= 13 and now().hour < 15.5 and is_state('input_boolean.cats_2nd_feeding_done','off')  }}

etc.

And this works, but if I change the time, I have to go into each template and update the hours and trust I don’t make a typo along the way.

Would someone please help me find a better way to set up these templates? is there something else that I could easily update that could be used in place of the now().hour that I’m using? Or some way of formating my first example so that it can be used as a template in a time trigger? (If that’s even possible.)

Thank you so much!

Because the template isn’t producing a timestamp in ISO format (which is expected if you set a Template Sensor’s device_class to timestamp).

This would be acceptable:

{{ (today_at(states('input_datetime.cats_last_fed_at')) + timedelta(hours = states('input_number.cats_will_be_fed_in_x_intervals') | float(0))).isoformat() }}
1 Like

You are awesome! (As always :slight_smile: )

Thank you!

1 Like