Can't make my automation work (weather, presence and date conditions)

Hello Guys,

I started to make an automation for my Terrace blind. The 4 conditions to open the sun cover are:

  • 7:00 am
  • between 10th of June and 10th of September (i’m using a blueprint for date conversion)
  • AND when I’m home
  • AND when the weather is good (sunny or partly cloudy)

Here is the automation yaml. As I’m french, some part are french too…:wink:

Did I make a mistake ? How could I make it work? I’m pretty confident about the time and date conditions, less for the weather and presence.

My presence update (linked to the homeassistant app on IOS) seems to be working fine (map updated).

alias: Store terrasse
description: Uniquement en été quand il fait beau
trigger:
  - platform: time
    at: '7:00'
condition:
  - condition: state
    entity_id: person.thomas
    state: home
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: input_number.month_day
        above: '0610'
        below: '0910'
  - condition: and
    conditions:
      - condition: state
        entity_id: weather.maison
        state: sunny, partlycloudy
action:
  - service: cover.close_cover
    target:
      entity_id: cover.store_terrasse
mode: single

Any idea ?

Tks

I think your condition: and is wrong. It looks like you have 2 different and conditions and are both missing the second and conditions.

How about this?

alias: Store terrasse
description: Uniquement en été quand il fait beau
trigger:
  - platform: time
    at: '7:00'
condition:
  - condition: state
    entity_id: person.thomas
    state: home
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: input_number.month_day
        above: '0610'
        below: '0910'
      - condition: state
        entity_id: weather.maison
        state: sunny, partlycloudy
action:
  - service: cover.close_cover
    target:
      entity_id: cover.store_terrasse
mode: single

Conditions are AND logic by default. So all you need is this:

condition:
  - condition: state
    entity_id: person.thomas
    state: home
  - condition: numeric_state
    entity_id: input_number.month_day
    above: '0610'
    below: '0910'
  - condition: state
    entity_id: weather.maison
    state: sunny, partlycloudy
1 Like

Conditions are and by default. I’m not sure the weather condition would pass as true with both states listed. You may need to use AND and OR conditions.

- alias: Store terrasse
  description: Uniquement en été quand il fait beau
  trigger:
  - platform: time
    at: '7:00'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: person.thomas
      state: home
    - condition: numeric_state
      entity_id: input_number.month_day
      above: '0610'
      below: '0910'
    - condition: or
      conditions:
        - condition: state
          entity_id: weather.maison
          state: sunny
        - condition: state
          entity_id: weather.maison
          state: partlycloudy
  action:
  - service: cover.close_cover
    target:
      entity_id: cover.store_terrasse
  mode: single
1 Like

You can use lists like this*:

      - condition: state
        entity_id: weather.maison
        state: sunny, partlycloudy

Or like this:

      - condition: state
        entity_id: weather.maison
        state: 
          - sunny
          - partlycloudy

See the example here: https://www.home-assistant.io/docs/scripts/conditions/#state-condition

* As long as you are not using the UI editior.

1 Like

Testing if an entity is matching a set of possible conditions; The condition will pass if the entity matches one of the states given.

That’s good to know, thanks for the tip.

@Tomsupergreen — does the cover close if you trigger the automation manually, bypassing the trigger and condition?

What do you get as a result from for this template in the Developer Tools / Template editor?

{{ states('person.thomas') }}
{{ states('input_number.month_day') }}
{{ states('weather.maison') }}

Thanks all for you help !! I really appreciate.

@Troon yes, the cover close if I run the automation manually, so the action is correct.

I did not even know that the developper tools could help like that.

Here is the results:

home
0.0
partlycloudy

If I understand well, the weather and presence is not the problem at all…but the date.

Yes, you’re right. Have you copied this code from somewhere else? input_number.month_day isn’t something that the system provides. Instead of:

    - condition: numeric_state
      entity_id: input_number.month_day
      above: '0610'
      below: '0910'

try:

  - "{{ (6,10) <= (now().month, now().day) <= (9,10) }}"

for a full automation of:

- alias: Store terrasse
  description: Uniquement en été quand il fait beau
  id: 9132cd0c-0765-4625-9ff4-dfb3b5990437

  trigger:
    - platform: time
      at: '07:00'

  condition:
    - condition: state
      entity_id: person.thomas
      state: home
    - "{{ (6,10) <= (now().month, now().day) <= (9,10) }}"
    - condition: state
      entity_id: weather.maison
      state: sunny, partlycloudy

  action:
    - service: cover.close_cover
      target:
        entity_id: cover.store_terrasse

I’ve added an id (just a UUID4) so that you can use the Automation Debugger.

EDIT: corrected shorthand condition format

I tried to change the date condition with this and I have an error:

Message malformed: Unexpected value for condition: ‘{{ (6,10) <= (now().month, now().day) <= (9,10) }}’. Expected numeric_state, state, sun, template, time, zone, and, or, not, device @ data[‘condition’][1]

Remove the condition: from the front:

- "{{ (6,10) <= (now().month, now().day) <= (9,10) }}"

Apologies. Edited prior post.

Thank you guys !!

It seems it’s only working with “or condition” for the weather.

Here is the code working fine:

alias: Store terrasse
description: Uniquement en été quand il fait beau
trigger:
  - platform: time
    at: '07:00'
condition:
  - condition: state
    entity_id: person.thomas
    state: home
  - condition: template
    value_template: '{{ (6,10) <= (now().month, now().day) <= (9,10) }}'
  - condition: or
    conditions:
      - condition: state
        entity_id: weather.maison
        state: sunny
      - condition: state
        entity_id: weather.maison
        state: partlycloudy
action:
  - service: cover.close_cover
    target:
      entity_id: cover.store_terrasse
mode: single

If you’re using the UI automation editor, that’s a known problem:

Yep. I should have made this more obvious:

I’m back with some more. This automation works fine however I would like to make sure that if the rain come after the automation triggered, my blind will automatically open. Or in any case when rain is comming.

This time it should be:

  • when it’s rainy, lightening, …

What i’m not sure is, do the weather change state will trigger the automation? So I also included a time trigger (every 15 min the system check the weather).

I’m not sure if it’s possible to add a condition like “only when the blind is already close”.

Here is my code:

alias: Store terasse pluie
description: quand il pleut
trigger:
  - platform: time_pattern
    minutes: '15'
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: weather.home
        state: hail
      - condition: state
        entity_id: weather.home
        state: lightning-rainy
      - condition: state
        entity_id: weather.home
        state: pouring
      - condition: state
        entity_id: weather.home
        state: rainy
      - condition: state
        entity_id: weather.home
        state: lightning
action:
  - service: cover.open_cover
    target:
      entity_id: cover.store_terrasse
mode: single

But of course it seems to be not working. Right now my weather.home state is “rainy” but the automation is not triggered.

Any idea ?

If you want every 15 minutes, you need minutes: '/15' (docs). Yours is triggering at xx:15 only.

Why not trigger off the weather directly though? Example below: you cannot use the UI editor to write the trigger list like that though. You’ll also need to check if my “cover is closed” condition works, as I don’t have any covers to know what the state looks like:

alias: Store terasse pluie
description: quand il pleut
id: ace1de9d-9ad1-4742-b0dd-dc3a363b4a4d

trigger:
  - platform: state
    entity_id: weather.home
    to:
      - "hail"
      - "lightning-rainy"
      - "pouring"
      - "rainy"
      - "lightning"

condition:
  - condition: state
    entity_id: cover.store_terrasse
    state: 'closed'

action:
  - service: cover.open_cover
    target:
      entity_id: cover.store_terrasse

Thank you.

I already tried something like that. It does not work. I checked the cover state and it s detected as closed, so I could use this condition.

However now it’s working but I had to include the “or” condition for each weather state.

alias: Store terasse pluie (toute les 10 min, si store ouvert)
description: ''
trigger:
  - platform: time_pattern
    minutes: /10
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: weather.maison
        state: hail
      - condition: state
        entity_id: weather.maison
        state: lightning-rainy
      - condition: state
        entity_id: weather.maison
        state: pouring
      - condition: state
        entity_id: weather.maison
        state: rainy
      - condition: state
        entity_id: weather.maison
        state: lightning
  - condition: state
    entity_id: cover.store_terrasse
    state: closed
action:
  - service: cover.open_cover
    target:
      entity_id: cover.store_terrasse
mode: single