I decided to start with split configuration files,and the first thing I tried was sun triggered switch.It worked perfect.I tried to combine it with presence detection and it’s not working at all.
Here is my automation rule:
alias: Turn the lights on when home in the evening
trigger:
platform: sun
event: sunset
offset: "-01:00:00"
condition:
condition: state
entity_id: group.all_devices
state: home
action:
service: homeassistant.turn_on
entity_id: group.living_room, group.kitchen
No errors at all,but it’s not working.
When I trigger it from the automation frontend is OK
First can you post your configuration using the </> button? It allows the forum to maintain your spacing and can show if there is a error in the way you have things indented.
Is anyone not home? I think with the way you have it setup everyone would have to be home. So if anyone from the group.all_devices isn’t home it won’t trigger. Also if that group contains any computers or other devices and they aren’t powered on it won’t trigger. You may want to narrow that down to just a few select entities.
Thanks for the edit,i tried several times to edit the post with no result.When I press </> button it says indent preformatted text by 4 spaces and only the first line looks in preview like it should to be.
I replaced group.all_devices with device_tracker.mitko which is my device.
How to check the rule before next sunset.Maybe I’ve got to set the time several hours back in “states” section?
@serengeti76: the easy way to post code is to copy from your source and paste into the editor. Next, highlight everything you just posted and THEN press the code formatting button.
alias: Turn the lights on when home in the evening
trigger:
platform: sun
event: sunset
offset: "-01:00:00"
condition:
condition: state
entity_id: device_tracker.mitko
state: home
action:
service: homeassistant.turn_on
entity_id: group.living_room, group.kitchen
here is the new file,thanks for the tip.
I created a new rule which contains group.all_devices
alias: Send email when Family is home.
trigger:
platform: state
entity_id: group.all_devices
to: 'home'
action:
service: notify.***********_*********
data:
message: 'Family is home'
and is working fine,sends email when my pone connects to the home wi-fi network.
Now I see that there is difference between two files,one can’t tell before see them together.I’ll try with the new formatting
alias: Turn the lights on when home in the evening
trigger:
platform: sun
event: sunset
offset: "-01:00:00"
condition:
condition: state
entity_id: device_tracker.mitko
state: home
action:
service: homeassistant.turn_on
entity_id: group.living_room, group.kitchen
Yep now is working I’m happy with the result.Thanks for your help @silvrr and @rpitera.At least I know how to post my .yaml files
My question is will that automation work when I arrive home after sunset or in this “offset” time period.
Since your trigger is one hour before sunset with a condition that you are home I think it will only go off at that time.
If you want a automation to turn the lights off when you get home I think you need to have the opposite. Trigger that your state goes from away to home and a condition that the sun is below a certain angle in the sky.
The effect was that if I triggered any activity on the Harmony Hub, it would bring the lights up to full, wait a minute and a half and then slowly fade down.
Actually that’s not quite right; group.all_devices is special, it will return ‘home’ if any of the included devices is ‘home’. I use it this way extensively.
alias: Turn the lights off when not home
trigger:
platform: state
entity_id: device_tracker.mitko
state: not_home
action:
service: homeassistant.turn_off
entity_id: group.living_room, group.kitchen
Plus that rule:
alias: Turn the lights on when home in the evening
trigger:
platform: state
entity_id: device_tracker.mitko
state: home
condition:
condition: sun
after: sunset
after_offset: "-00:45:00"
action:
service: homeassistant.turn_on
entity_id: group.living_room, group.kitchen
Now sky is the limit!
Thanks for your help,I was stuck with this for a week
Just an FYI: group.all_devices will set it’s state home if even one member is home, so it is actually possible to use that as the entity ID that triggers the action.