YAML Check please

Hi all;

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!

Hello Ignacio Rosenberg,

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.

2 Likes

Oops, fixed. Did not know that existed.

to is not a valid key for a State condition, state is the proper key.

Generally, long waits and log durations (aka for) can be problematic because they do not survive restart or reload.

I see, so it would be something like:

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

Is this right?

You have “smart quotes” that need to be fixed around the zero.

FWIW, if you are doing this in the Automation Editor, your comments will not be saved.

Gotcha, so…


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

Admittedly that has also brought up an error on HA:

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.

Half AI, half myself…

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):

alias: Vacation Ventilate
description: ""
triggers:
  - trigger: time
    at: "09:00:00"
    weekday:
      - tue
      - fri
conditions:
  - condition: state
    entity_id: zone.home
    state: "0"
    for:
      days: 2
actions:
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.ventilate
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.ventilate_off
mode: single
1 Like