I have a value template someone helped me with to run an automation on the first of every month. This code is Greek to me. Can any coding guru’s help me modify this to run every three months? Maybe January 1, April 1, July 1, October 1…
What I have now…
{% set n = now() %} {{ n.day == 1 and 1 <= n.month <= 12 }}
Also, anybody know of a good reference for this? Like a “Yaml For Dummies”? Or whatever code this is? I’d like to learn more about this for the future.
Okay, since I know this is related… I have made cards that conditionally show when the UV Index reaches a certain value. The idea is that if the UV Index reaches between 6 and 7, for example, a card will show with a sunscreen recommendation.
The problem with this is that the card only shows if it’s value is precisely 6. Right now it’s 6.16 so it doesn’t show. I know this must be done with a template somehow, but I’m not sure how to go about it. I need to create an entity that returns a value based on a range (I’m thinking), and then base the condition on that entity. So if the value is between 6.00 and 6.99 the entity would show “6”. Between 7.00 and 7.99 the entity would show “7”, etc…
Now you have a binary_sensor that switches on when the UV index is 6 or above, and off when it is below. You can now use the built in Home Assistant conditional card to show the relevant cards now, based on whether the binary_sensor is on or off.
I have all the cards built, I just created a sensor like in your first post. The rounded value from your first example is what I use as the condition now, and it works great from what I can tell. I’ll have to get a few sunny days and see how it functions.
Okay, I tried to add a specific time to that. No dice. I tried all kinds of variants such as this.
{% set n = now() %} {{ n.day == 25 and n.time == 1125 and n.month in [9] }}
Hoping to have something run on a specific date/time each year, like at 11:25 AM on September 25th. I still can’t believe this isn’t included as a condition in a home automation platform, but I digress. I’d like to set my furnace mode based on specific dates/times each year, like turn it on every October 1st, and off come spring.
Note: I tend to use >= in template triggers like this instead of == just to cover the edge case where the trigger time doesn’t register exactly, but it may not be necessary.
You could also use a Calendar trigger if you have integrated calendars or use a custom integration like Anniversaries to store the date.
I put in a specific time as the trigger, and used the above as a condition as a workaround.
{% set n = now() %} {{ n.day == 25 and n.month in [9] }}
I put what you said in the template editor and when the date time ticked by it still said 'false". I’m assuming because the condition is only true for one second… That’s perfect if that’s the case. I’ll test it out and see how it works.