Open/close garage based on presence sensor

Hi
I am just starting out and having hard time with setting up an automation.
I have 2 variables - garage door state and family presence.
Both are working fine independently - family status changes fine and garage door status changes fine.
I just cannot work out how to do the automation so that:

  • door automatically closes if nobody home but garage door is left open
  • open door if its closed but someone is detected as returned home

Thank you

Just make an automation with 2 triggers:

  • family presence to home
  • family presence to away

As action you pick a chooser,

  • if family presence is home => open door
  • else (default) => close door

State of the door does not matter as no harm is done in calling “close” if the door is already closed.

trigger:
  - platform: state
    entity_id: group.family
    from: 'home'
condition:
  - condition: state
    entity_id: binary_sensor.garage_door_open
    state: 'on'
action:
  - [whatever you need to do to close the door]

This is what I currently have (should have pasted it earlier). Action is something I have no issue with - it closes if I manually run the automation. But the condition never gets executed
Also still dont understand how strings work in the code. Like in the From/To sections - are they strings with single quote or I can just use any way I like?

id: '1621584495658'
alias: Close garage door when nobody home by door is open
description: ''
trigger:
  - platform: state
    entity_id: group.family
    from: home
    to: away
    for: '00:00:03'
condition:
  - condition: state
    entity_id: cover.mygarage
    state: open
    attribute: door_state
action:
  - service: cover.close_cover
    target:
      entity_id: cover.mygarage
mode: single

And if you just remove the condition? Like I said, no hard in closing it when it’s closed.

And check the states in dev tools to see if group.family indeed goes to away. Maybe it needs to read "away" and "home" (with quotes).

yeah, dont understand how the lowercase/uppercase, quote/unquote works in HA yet.
How do I know if I should put double quotes around the value? Not quotes in the state section.
But found that instead of Home/Away that it displays in the Lovalace, it is actually home/not_home

Ahh, yeah, it’s indeed not_home :). And most places do like the quotes, even it you don’t need them. I make most automations in the UI which will place the quotes for me :angel:

sorry, my bad. I pasted the output from the trace config. But just looked at the yaml file and it did indeed put the single quotes

Than you don’t need them :smiley: So just using the correct states should fix it

id: '1621584495658'
alias: Close garage door when nobody home by door is open
description: ''
trigger:
  - platform: state
    entity_id: group.family
    from: home
    to: not_home
    for: '00:00:03'
condition: []
action:
  - service: cover.close_cover
    target:
      entity_id: cover.mygarage
mode: single

thank you. Will give it a go tomorrow

Ok. It works! =) But I have to work on the presence detection…