Smart Gardening - Help with templating

Hello fellow Home Automators,
i’m trying to get my head more around templating, especially in creating template sensors and so far i am not able to accomplish, what i had in mind.
I would like my home automation to be more thoughtful of my garden (my green thumb still need to develop), so i’m trying to create sensors to help or identify the right time to fertilize the grass, to understand when the grass is in the phase of growing (dependant on ground temperature) and when not, et cetera. In the end i would like to write automations, who will tell or remind me, when is the right time to do what and when.
I would love to improve on Home Assistants gardening skills, as the garden grows smarter with each and every sensor, we put in in the ground, or on the roof.

Alright the first thing i would love to find out is, how i can create a template sensor, which will take the average temperature from one specific sensor from the last 48 hours and sets the state of template sensor to “growing” or “sleeping” based on, if that average temperature is under 8 degrees celsius (in that case it would be “sleeping”). Ideally the icon changes with it, based on its state (mdi:grass mdi:sleep).

Is there anyone, who would be willing to help me in accomplishing this?
Thanks in advance and best regards

Chris

Statistics sensors state is the average value.
So just set up a statistics sensor with 48 hour timespan (mag_age).

This is where you need the template.
And it’s quite easy.

{% if(states('sensor.statistics') | float >= 8) %}
Growing
{% else %}
Sleeping
{% endif %}

Regarding switching icon then you need to do that in customize.yaml

1 Like

Thanks a lot Hellis81 for your fast and helpful response!
It has worked exactly, as you’ve explained.
I only had to add an extra (default=“unknown”) to float, so home assistant knows what the default value is.
Best Wishes
Chris