I’ve made an automation to trigger a switch between a time period when one of us gets home, or if we are home when the sun sets.
Strangely it doesn’t get triggered when I get home after sunset.
# Lichten aan bij zonsondergang of wanneer iemand thuis tussen 16.00-23.00
- alias: 'Keukenverlichting aan bij thuis of thuiskomst'
trigger:
- platform: sun
event: sunset
offset: '-00:00:00'
- platform: state
entity_id: device_tracker.iphonemaurice
to: 'home'
- platform: state
entity_id: device_tracker.iphone_van_yvette_2
to: 'home'
condition:
- condition: state
entity_id: device_tracker.iphonemaurice
state: 'home'
- condition: state
entity_id: device_tracker.iphone_van_yvette_2
state: 'home'
- condition: time
after: '16:00:00'
before: '23:00:00'
action:
service: switch.turn_on
entity_id: switch.sonoff_voortuin
I just copied and edited a full written example from the Hassio website:
It’s probably because not all conditions are satisfied, when you get home. Please be aware that conditions are AND by default. So the switch will only turn on if you are home AND the other person is home AND it’s between 16 - 23.
The example you edited uses a group in the trigger and in the condition and the group shows home when at least one person is home.
Either group your device trackers or make multiple automations.
Your conditions require that both of you are home for this automation to complete. Is that what you intend? One of you arriving home when the other is not wouldn’t satisfy the conditions. Note that you can use “or” logic in conditions (default is and).
Check out that link in my response. It gives a n “or” example. Getting the syntax right the first time can be a bit tricky - use the “check config” button on the server control page after you make changes to confirm you’ve got it right.
# Lichten aan bij zonsondergang of wanneer iemand thuis tussen 16.00-23.00
- alias: 'Keukenverlichting aan bij thuis of thuiskomst'
trigger:
- platform: sun
event: sunset
offset: '-00:00:00'
- platform: state
entity_id: device_tracker.iphonemaurice
to: 'home'
- platform: state
entity_id: device_tracker.iphone_van_yvette_2
to: 'home'
condition:
condition: or
conditions:
- condition: state
entity_id: device_tracker.iphonemaurice
state: 'home'
- condition: state
entity_id: device_tracker.iphone_van_yvette_2
state: 'home'
- condition: time
after: '16:00:00'
before: '23:00:00'
action:
service: switch.turn_on
entity_id: switch.sonoff_voortuin
Yeah I would like that part. But merely I would like to turn on the switch if one of us comes home after the sun het set. So I think it’s correct but I need to remove the “Time is between” part.
I edited it a bit yesterday. YAML validator says it’s valid, but when reloading my automations it’s not…
# Lichten aan bij zonsondergang of wanneer iemand thuis tussen 16.00-23.00
- alias: 'Keukenverlichting aan bij thuis of thuiskomst'
trigger:
- platform: state
entity_id: device_tracker.iphonemaurice
to: 'home'
- platform: state
entity_id: device_tracker.iphone_van_yvette_2
to: 'home'
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
offset: '-00:30:00'
action:
service: switch.turn_on
entity_id: switch.shelly_shsw_1_c42b0b
Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘conditions’][0][‘offset’]. Got None
extra keys not allowed @ data[‘condition’][0][‘conditions’][0][‘state’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘conditions’][0][‘condition’]. Got None. (See /config/configuration.yaml, line 12). Please check the docs at https://home-assistant.io/integrations/automation/
The way I suggested (condition: sun below horizon) lines up the sun condition with the sun trigger. So the light will only come on at sunset or later.
If you use your condition, the light will come home if you arrive within 30 minutes of sunset (or after sunset). Which is probably a good way to do it. I like to have my lights come on before sunset since it gets dark inside before the sun is below the horizon.