Weather and Azimuth automation problem with and/or contitions

Hi There, i have a question regarding an automation while using the sun and weather entities in combination with and/or statements and i am hoping to find an answer here…

The automation should work like that:

  • run every 15 mins
  • check if the sun’s azimuth is between 150 and 250
    AND
  • check if the weather condition is EITHER sunny OR partlycloudy
    AND
  • check if the daytime is between 12pm and 06pm
    AND
  • check if the doorsensor is not reporting an open door

I have tried with the attached yaml code, but it always exits with the following statement:

Heres my code:

alias: Raffstore Küche & Essbereich schließen über Azimuth und Wetter
description: ''
trigger:
  - platform: time_pattern
    minutes: /15
condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: azimuth
    above: '150'
    below: '250'
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.wetterstation_condition
        state: partlycloudy
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.wetterstation_condition
            state: sunny
  - condition: and
    conditions:
      - condition: time
        after: '12:00'
        before: '18:00'
  - condition: and
    conditions:
      - condition: not
        conditions:
          - type: is_open
            condition: device
            device_id: 31c8401c9bf4dcd17102dfb4037890b4
            entity_id: binary_sensor.tursensor_essbereich_door
            domain: binary_sensor
action:
  - device_id: eda4ac05ced81c47276515968f333143
    domain: mobile_app
    type: notify
    title: 'Azimuth:'
    message: Closing to 0
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - device_id: eda4ac05ced81c47276515968f333143
    domain: mobile_app
    type: notify
    title: 'Azimuth:'
    message: Tilting to 2
mode: single

Can someone point me the right direction please?
Thanks for helping me out.

Brgds - Andre

Your conditions are easy to sort out. Conditions are AND logic by default, so:

condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: azimuth
    above: '150'
    below: '250'
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.wetterstation_condition
        state: sunny
      - condition: state
        entity_id: sensor.wetterstation_condition
        state: partlycloudy
  - condition: time
    after: '12:00'
    before: '18:00'
  - condition: state
    entity_id: binary_sensor.tursensor_essbereich_door
    state: 'off' # this might be 'on' depending on your sensor.

You can probably do this with a better trigger though. A bunch of state triggers that only trigger when any of those entities changes would be better than checking every 15 minutes 24/7.

1 Like

@tom_l - Thanks for your help, now i understand what the and/or statement does.
Think that should solve this, will try that and report back.

If you don’t mind, can you maybe gimme an example what you mean with a bunch of state triggers?

Thanks :slight_smile:

alias: Raffstore Küche & Essbereich schließen über Azimuth und Wetter
description: ''
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: azimuth
    above: '150'
    below: '250'
  - platform: state
    entity_id: sensor.wetterstation_condition
    to:
      - 'partlycloudy'
      - 'sunny'
  - platform: time
    at: '12:00:00'
  - platform: state
    entity_id: binary_sensor.tursensor_essbereich_door
    to: 'off'
condition:
  - "{{ 150 < state_attr('sun.sun', 'azimuth') < 250 }}"
  - "{{ states('sensor.wetterstation_condition') in ['partlycloudy', 'sunny'] }}"
  - "{{ 12 <= now().hour < 18 }}"
  - "{{ is_state('binary_sensor.tursensor_essbereich_door', 'off') }}"
action:
  - device_id: eda4ac05ced81c47276515968f333143
    domain: mobile_app
    type: notify
    title: 'Azimuth:'
    message: Closing to 0
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - device_id: eda4ac05ced81c47276515968f333143
    domain: mobile_app
    type: notify
    title: 'Azimuth:'
    message: Tilting to 2
mode: single

Instead of using a Time Pattern Trigger to check conditions repeatedly, you use a (nearly) matching set of triggers and conditions. The resulting automation triggers only when it’s necessary as opposed to triggering repeatedly (frequently when unnecessary).

2 Likes

You guys are awful - thanks for your help - really appreciate that.
I will test the different varants and report back.

Thank you again - Andre

Thank you for your support - it works as desired.