I want to turn on the lights at a certain time tarting on the second Sunday of March, and ending on the first Sunday in November. I then want them to turn on at a different time between the first Sunday in November and the second Sunday in March. This year the second Sunday in March is the 10th, but it won’t be the 10th next year, so I cannot set it by numerical date.
There are multiple ways to do that… here’s one that can be done without extra helper entities:
trigger:
- alias: March to November
platform: time
at: "07:30:30"
id: '1'
- alias: November to March
platform: time
at: "08:30:30"
id: '0'
condition:
- condition: template
value_template: "{{ now().timetuple().tm_isdst == trigger.id | int }}"
action:
I’m mentioning this to you only because, as an experienced user, you might find this handy in the future (you may already be aware of it). For beginners, it might be confusing.
The value of the first trigger’s id is automatically 0 (as a string). The next trigger’s id is 1 and so on. So even if you don’t explicitly specify a value for id, it will have a default value representing its position in the list of triggers (and it will be the same value as its idx property).
If you swap the order of the two triggers in your example, the id value for the “November to March” Time Trigger will automatically be 0 so you don’t have to explicitly indicate id: 0 and can safely remove that line.
I am somewhat familiar with c++, but am fairly new to home assistant, and a complete novice with yaml. I do most things via the UI. Would this solution be creating custom triggers that I would then use in the automations section of the UI
I will definitely look into this once u better understand the basics of all of this as I would eventually like to have finer control over when the tiger basketball then just the beginning of the month.
Would I place the code in configuration.yaml, or is there a way to better organize everything? I would ideally like to have a lights.yaml, triggers.yaml, etc… if that’s a thing. If it is, would I still need some code in configuration.yaml to call the others?
If you need a primer on transcribing YAML automation configuration to the UI Editor there is a slightly dated video available here.
No, the most recent post I made uses 2 normal Time triggers with assigned IDs (this is available in the drop down menu for the trigger under “Edit ID”:
triggers at 11am if it’s the 2nd sunday of the month.
home assistant will then generate the full yaml and put it in the automation.yaml page or you (or the script.yaml if you’re doing a script).
if you’re just learning yaml to start, i would encourage you to use the ui, let it build the yaml. then at the end, go look and learn from the yaml it generated.
start by doing only the yaml and templating that you must do… let the ui guide you for the rest.
I would like to try and use a combination of what you two are saying, and yes, this is for daylight savings time. Is there anyway to have the lights turn-on on the second Sunday of March at 2000 hrs and continue to do so every day until the first Sunday of November when they will turn on at 1800 hrs until the second Sunday of March the next year?
Sorry to reopen this post but I have a qustion about the usage and this seems to be the only thread related to this topic.
So my goal is to create all-day calendar entries for every third friday of a month because this is when the paper trash is collected. I have made a script to automatically create calendar entries. For each month there is an action that looks like this:
This works well for every month - except for June 2024. June 1st is a saturday. So time.jinja counts (6, 3, 5) as the 21st of June but (6, 3, 6) as the 15th resulting in a negative duration and thus a failure to create the event.
Technically this is correct behaviour as they are both the third occurencies of given weekday but it is not a desired result.
So my question is: Is there any way to set the end date to “one day after the start date” or something? - Or is there a better way to do this?
Also: could someone kindly explain what “[:10]” does? I can’t find anything about it in the documentation, I just know the script doesn’t work without it…
I know this date is in the past and doesn’t matter anymore specifically, but I would like a working universal solution that I don’t have to check on every other year.
Do you actually need a script? Your problem is categorically different than the original post… OP wanted an annual repeat that accounted for the Month, Week index, and Day of the week.
The Repeat Monthy option in the “Add Event” dialog can handle what you are trying to do, and have it repeat forever:
This is one way to perform slicing based on index number. This is a basic method used in Python and, as such, is considered outside the scope of Home Assistant documentation. In this case it selects the first 10 elements of the datetime string so it returns some like 2024-03-10 instead of something like 2024-03-10T00:00:00-05:00. The calendar.create_event has been updated since the start of this thread to allow datetime date objects. Slicing will still work, but it isn’t the only option.