We travel a lot so I’m (attempting) to write a script where if the house has been empty for 3 days it will run a ventilation scene to move some air around for an hour; and to have this happen every week. I do have a scene to turn it on and one to turn it off. I cobbled this together from a bunch of posts…I’m pretty useless at coding. Can someone tell me if this makes sense:
alias: Weekly Ventilation If Home Empty for 3 Days
description: >
Every week, check if home has been empty for 3 days. If so, run the Ventilate scene for 1 hour.
trigger:
- platform: time
at: "09:00:00" # Adjust to any time you'd like this to run weekly
condition:
- condition: state
entity_id: zone.home
to: “0”
for:
days: 3
action:
- service: scene.turn_on
target:
entity_id: scene.ventilate
- delay: "01:00:00"
- service: scene.turn_on
target:
entity_id: scene.ventilate_off
mode: single
Thanks for coming here and asking a question.
Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. Editing your original is the preferred way. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix it from the site FAQ Page. How to help us help you - or How to ask a good question.
alias: Weekly Ventilation If Home Empty for 3 Days
description: >
Every week, check if home has been empty for 3 days. If so, run the Ventilate scene for 1 hour.
trigger:
- platform: time
at: "09:00:00" # Adjust to any time you'd like this to run weekly
condition:
- condition: state
entity_id: zone.home
state: “0”
for:
days: 3
action:
- service: scene.turn_on
target:
entity_id: scene.ventilate
- delay: "01:00:00"
- service: scene.turn_on
target:
entity_id: scene.ventilate_off
mode: single
alias: Weekly Ventilation If Home Empty for 3 Days
description: >
Every week, check if home has been empty for 3 days. If so, run the Ventilate scene for 1 hour.
trigger:
- platform: time
at: "09:00:00" # Adjust to any time you'd like this to run weekly
condition:
- condition: state
entity_id: zone.home
state: 0
for:
days: 3
action:
- service: scene.turn_on
target:
entity_id: scene.ventilate
- delay: "01:00:00"
- service: scene.turn_on
target:
entity_id: scene.ventilate_off
mode: single
It looks like your yaml is a mix of old and new style format. You also used something meant for a trigger as a condition. Did you write this or did you use AI? My advice would be to build an automation in the automation editor and learn from it how to format the code before writing yaml by hand.
That’s because you removed the quotes completely instead of fixing them by replacing them with straight quotes. When configuring in YAML you need to make sure to use the expected data type… States are always strings, so you need to use quotes to identify that the zero is a string not an integer.
If you really want this to be weekly, you need to add a Weekday; either directly to your Time trigger or in a separate Time condition. As it is, the automation is triggering every day at 9:00am.
That makes sense, I modified one from the visual editor now, hopefully this fixes the formatting issues (and made some changes to make it more usable):