Basically I want the lights to turn on if either me or my wife comes home, or if we both come home at the same time, but do not trigger if one of us is already home.
My main problem is that when both of us come home at the same time (same car), I’ve found no way to check if the other one has already been home for some time, and both states seem to change instantaneously.
Below works if both of us don’t come home at the same time.
- alias: Turn on indoor lights when Me or Wife come home
trigger:
- platform: state
entity_id: device_tracker.google_maps_me, device_tracker.google_maps_wife
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: device_tracker.google_maps_me
state: 'not_home'
- condition: state
entity_id: device_tracker.google_maps_wife
state: 'home'
- condition: and
conditions:
- condition: state
entity_id: device_tracker.google_maps_me
state: 'home'
- condition: state
entity_id: device_tracker.google_maps_wife
state: 'not_home'
- condition: time
before: '22:30:00'
after: '06:30:00'
action:
- service: switch.turn_on
entity_id: group.normal_lights
- service: light.turn_on
entity_id: group.normal_lights
Use group.all_devices in the trigger. Assuming there are just the two device_tracker entities, this group will be home if either or both of you are home, and not_home if both of you are not home.
This will trigger whenever the first person comes home. Then it will not trigger again until you are both not home, and then someone comes home. Basically it will trigger whenever the result of the expression changes from false to true.
- alias: Turn on indoor lights when we both get home
trigger:
- platform: state
entity_id: group.device_trackers
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: time
before: '22:30:00'
after: '06:30:00'
action:
- service: switch.turn_on
entity_id: group.normal_lights
- service: light.turn_on
entity_id: group.normal_lights
- alias: Turn on indoor lights when Me or Wife get home
trigger:
- platform: state
entity_id: device_tracker.google_maps_me, device_tracker.google_maps_wife
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: device_tracker.google_maps_me
state: 'not_home'
- condition: state
entity_id: device_tracker.google_maps_wife
state: 'home'
- condition: and
conditions:
- condition: state
entity_id: device_tracker.google_maps_me
state: 'home'
- condition: state
entity_id: device_tracker.google_maps_wife
state: 'not_home'
- condition: time
before: '22:30:00'
after: '06:30:00'
action:
- service: switch.turn_on
entity_id: group.normal_lights
- service: light.turn_on
entity_id: group.normal_lights
That is way more complicated than it needs to be. This should work:
- alias: Turn on indoor lights when we get home
trigger:
- platform: state
entity_id: group.device_trackers
to: 'home'
condition:
- condition: time
before: '22:30:00'
after: '06:30:00'
action:
- service: homeassistant.turn_on
entity_id: group.normal_lights
This will handle if either of you comes home while the other is out, or if you both come home at the same time (which, BTW, really can’t happen, since each change of state is processed separately.) You don’t need another automation.
And although I haven’t tried it myself, I’m pretty sure the homeassistant.turn_on service will handle a heterogeneous group of entities.
It’s like seeing someone trying to walk through a wall right next to a door, and just keep pushing as if it’s the correct way to get in.
If you add a group the group will take care of all logic and display it’s intention as the state.
Creating your own logic hides the intention and will make it hard to debug.
Invalid config for [group]: [view] is an invalid option for [group]. Check: group->group->person_trackers->view. (See /config/configuration.yaml, line 8).
line 8 is empty
line 9 group: !include groups.yaml
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
packages: !include_dir_named packages
of course if it fails for that only reason i can rename things quickly
but tracking persons works for me… ie they change states like they should when i check it
A trick that should work to get a more meaningful error message is to combine the two yaml codes in to one. Example:
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
#group: !include groups.yaml
group:
device_trackers:
name: Device Trackers
view: false
entities:
- device_tracker.google_maps_me
- device_tracker.google_maps_wife
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
packages: !include_dir_named packages
Now it should point at the correct line.
Once you got it correct you can simply copy it back to the groups file and revert the configuration.yaml back to its original state.