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