new to automations, this is my first one. I would like to add the sun to this automation and if someone is home don’t fire automation, for example this automation should only happen when its dark outside or after sunset and before sunrise and on one is home. The “input_select.dave_status_dropdown” and input_select.linda_status_dropdown" index to “home” after 5 minutes, so after 5 minutes ever time the front door sensor goes to open it doesn’t keep turning on the dining light Thanks for any help.
> - alias: Dave or Linda Home turn on dinning lite
> trigger:
> - platform: state
> entity_id: binary_sensor.front_door_alarm_opened
> from: 'off'
> to: 'on'
> condition:
> condition: or
> conditions:
> - condition: state
> entity_id: input_select.dave_status_dropdown
> state: 'Just Arrived'
> - condition: state
> entity_id: input_select.linda_status_dropdown
> state: 'Just Arrived'
> action:
> - service: light.turn_on
> entity_id: light.dining_light
> data:
> brightness: 255
Hi ramdisk.
Maybe you have to insert an AND condition to your conditions, and change your OR condition with another AND, for the automation to work. Try changing from
condition:
condition: or
conditions:
- condition: state
entity_id: input_select.dave_status_dropdown
state: ‘Just Arrived’
- condition: state
entity_id: input_select.linda_status_dropdown
state: ‘Just Arrived’
to:
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: and
conditions:
- condition: state
entity_id: input_select.dave_status_dropdown
state: 'Away'
- condition: state
entity_id: input_select.linda_status_dropdown
state: 'Away'
Note that your OR condition was replaced by an AND condition, and the states need to be inverted from “Just arrived” to “Away” (or somewhat you’ve defined in your configuration).
fwiw, since condition are by default And, this can be shortened to:
condition:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: state
entity_id: input_select.dave_status_dropdown
state: 'Away'
- condition: state
entity_id: input_select.linda_status_dropdown
state: 'Away'
which make an issue obvious, being both after sunset and before sunrise…? Not sure if that passes at all. Search other threads in this, it has been discussed elsewhere
Sure you can. Rookie mistake. Thanks!
About after sunset and before sunrise, it seems be obvious, but for some unknown reason, in my configuration, it doesn’t work with just one of these sun conditions.
{{is_state('sun.sun','below_horizon') and
is_state('input_select.dave_status_dropdown','Away') and
is_state('input_select.linda_status_dropdown','Away')}}
after sunset and before sunrise both = below_horizon …
you can do it just like you originally had it with the addition of an ‘and’ condtion for the sun:
- alias: Dave or Linda Home turn on dinning lite
trigger:
- platform: state
entity_id: binary_sensor.front_door_alarm_opened
from: 'off'
to: 'on'
condition:
condition : and
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: or
conditions:
- condition: state
entity_id: input_select.dave_status_dropdown
state: 'Just Arrived'
- condition: state
entity_id: input_select.linda_status_dropdown
state: 'Just Arrived'
action:
- service: light.turn_on
entity_id: light.dining_light
data:
brightness: 255
You could do the sun conditions as an ‘or’ or an ‘and’.
The sun state is determined in relation to midnight. so “after: sunset” means from sunset to midnight and “before: sunrise” means from midnight to sunrise.
So in that case using either ‘and’ or ‘or’ would effectively end in the same result. i.e. ((between sunset and midnght) and (midnight and sunrise)) or ((between sunset and midnight) or (between midnight and sunrise))
back for I must correct a mistake I made, sorry for that. Missed the fact that OP needed an ‘or’ for the input_selects. Which proves my point tbh, for the unreadability of these nested conditions…
anyways, there are a few more options possible to enhance this automation:
- alias: Dave or Linda Home turn on dining light #fixed typo
trigger:
platform: state # only 1 trigger? no need for the -
entity_id: binary_sensor.front_door_alarm_opened
# from: 'off' # since it is a binary, only one state is needed
to: 'on'
condition:
- condition: template
value_template: >
{{is_state('sun.sun','below_horizon') #can't stress enough the need for short and simple conditions versus complex and multi-interpretable sets of conditions
- condition: template
value_template: >
{{ is_state('input_select.dave_status_dropdown','Away') or
is_state('input_select.linda_status_dropdown','Away')}}
action:
service: light.turn_on # only 1 action? no need for the -
entity_id: light.dining_light
data:
brightness: 255
this is an automation which can completely be checked in the dev-tools, which is an enormous plus…
you right even take it one step further by doing this:
- alias: Dave or Linda Home turn on dining light #fixed typo
trigger:
platform: state # only 1 trigger? no need for the -
entity_id: binary_sensor.front_door_alarm_opened
# from: 'off' # since it is a binary, only one state is needed
# to: 'on' no to: in the trigger, but use it as condition. It causes the automation to trigger on 'off' also, but has as advantage the 'on' can be checked in the condition and dev-template tool
condition:
- condition: template
value_template: >
{{ is_state('binary_sensor.front_door_alarm_opened','on') }}
- condition: template
value_template: >
{{is_state('sun.sun','below_horizon') #can't stress enough the need for short and simple conditions versus complex and multi-interpretable sets of conditions
- condition: template
value_template: >
{{ is_state('input_select.dave_status_dropdown','Away') or
is_state('input_select.linda_status_dropdown','Away')}}
action:
service: light.turn_on # only 1 action? no need for the -
entity_id: light.dining_light
data:
brightness_pct: 100 # gives a better clue of the brightness in %