Hello, I’m a little confused about how to add OR and AND condition to my automation, I would like to execute some actions and some of them just execute based on a condition.
In my automation I want to open the blind only if the sun elevation is above 0 or if its after sunrise
alias: Switch - PC On (Xiaomi)
description: ''
trigger:
- device_id: 3961eddd38b44c35a9a6d6b4f719ee84
domain: deconz
platform: device
subtype: turn_on
type: remote_button_short_press
condition: []
action:
- type: turn_on
device_id: 8b9f32942ebb1e018a1d3582a38d94aa
entity_id: light.h6159_80df
domain: light
brightness_pct: 100
- service: script.1593064896372
data: {}
- delay: '00:00:05'
- service: script.pc_led_orange
data: {}
- condition: or
conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: '0'
- condition: sun
after: sunrise
- device_id: 6cecceaf6c9fdc7445da5e5a3bf7444d
domain: cover
entity_id: cover.shelly_shsw_25_40f520014146
type: set_position
position: 90
mode: single
Can’t have it work … any help would be appreciated.
Thanks!
tom_l
December 15, 2020, 8:09am
2
These are the same thing. If the elevation is above zero it is after sunrise.
All you need is the example in the docs .
condition:
condition: state # 'day' condition: from sunrise until sunset
entity_id: sun.sun
state: 'above_horizon'
Or do you mean from sunrise to midnight?
1 Like
Hey @tom_l , thanks for the reply.
You’re right, both conditions are the same, I will use the one in the examples, anyway one of my doubts are about how are being applied the conditions, they are only applied to the very next action? or to all the further actions?
In my example, if the sun elevation is above 0, the cover would be opened, but if I add another action after this, will be executed no matter sun condition?
alias: Switch - PC On (Xiaomi)
description: ''
trigger:
- device_id: 3961eddd38b44c35a9a6d6b4f719ee84
domain: deconz
platform: device
subtype: turn_on
type: remote_button_short_press
condition: []
action:
- type: turn_on
device_id: 8b9f32942ebb1e018a1d3582a38d94aa
entity_id: light.h6159_80df
domain: light
brightness_pct: 100
- service: script.1593064896372
data: {}
- delay: '00:00:05'
- service: script.pc_led_orange
data: {}
- condition: or
conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: '0'
- condition: sun
after: sunrise
- device_id: 6cecceaf6c9fdc7445da5e5a3bf7444d
domain: cover
entity_id: cover.shelly_shsw_25_40f520014146
type: set_position
position: 90
- service: notify.mobile_app_oneplus
data:
title: Some title
message: some message
mode: single
Would notify.mobile_app_oneplus
be executed even if the sun elevation is below 0?
I don’t know if I have explained myself.
Thanks.
tom_l
December 15, 2020, 10:00am
4
If the condition evaluates to false all further actions are skipped. So no, the mobile will not be notified.
If you want to conditionally run a single action then do more, look at the choose:
action. https://www.home-assistant.io/docs/scripts#choose-a-group-of-actions
1 Like
Thanks! I’ll take a look at the choose:
action. Thanks for clarifying how or and and works