I am new to home assistant and I been trying to wrap my head around yaml and configurations for homeassistant but it is quickly becoming overwhelming because there is so much to do. I wanted to move my automatic door lock to home assistant and also add an automation that opens my door when my phone connects to the wifi. I already have presence dection with unifi in home assistant but I am struggling with the automations, here is the code I have written so far which does not work properly:
- alias: Automaticly lock door after 2 minutes if door is closed
trigger:
platform: state
entity_id: lock.ytterdorr
to: 'unlocked'
for:
seconds: 120
condition:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
action:
- service: lock.lock
entity_id: lock ytterdƶrr
- alias: Automaticly open door when owners arrives home
trigger:
platform: state
entity_id: person.me.lastname
from: not_home
for: 00:05:00
to: home
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
- condition: state
entity_id: lock.ytterdorr
state: 'locked'
action:
- service: lock.unlock
entity_id: lock.ytterdorr
- alias: Automaticly lock door after 2 minutes when owners leaves home
trigger:
platform: state
entity_id: person.me.lastname
from: home
for: 00:02:00
to: not_home
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
- condition: state
entity_id: lock.ytterdorr
state: 'unlocked'
action:
- service: lock.lock
entity_id: lock.ytterdorr
Anyone has any ideas on how to fix this? I am new so I need sample configs to be able to understand what to do.
For the first automation it not going to trigger if it base on lockā¦ its only trigger when you unlock the door not close. try this
- alias: Automaticly lock door after 2 minutes if door is closed
trigger:
platform: state
entity_id: binary_sensor.ytterdorr_open
to: 'off'
for:
seconds: 120
action:
- service: lock.lock
entity_id: lock.ytterdorr
and what is the purpose you try to achieve here?
from: not_home
for: 00:05:00
to: home
to: home
for:
minutes: 5
Donāt you want it unlock straight away when owners come home?
- alias: Automaticly open door when owners arrives home
trigger:
platform: state
entity_id: person.lastname
to: home
condition:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
- condition: state
entity_id: lock.ytterdorr
state: 'locked'
action:
- service: lock.unlock
entity_id: lock.ytterdorr
- alias: Automaticly lock door after 2 minutes when owners leaves home
trigger:
platform: state
entity_id: person.lastname
to: not_home
for:
minutes: 2
condition:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
- condition: state
entity_id: lock.ytterdorr
state: 'locked'
action:
- service: lock.lock
entity_id: lock.ytterdorr
Ok maybe I was not clear in the first post. This is what I want to achieve:
I want the door the automatically lock if the door is closed binary_sensor.ytterdorr_open = off and the the lock is unlocked after 2 minutes.
I want the door the unlock as soon as it senses that my phone or my spouses phone changes status from not_home to home and they have been away for more 5 minutes.
I want the doors the lock if the door is closed and unlocked if both me and my spouse phone statuses changed from home to not_home. I want this to happen 2 mintues after the status has changed
There is a lot of opposition. You cant have āandā in trigger. Also how can you be away for 5 min when you just got home. You can have an automation A to turn on an automation B after you ānot_homeā for 5m. and automation B will unlock when you come home and turn itself off.
Hey I am not sure I am following here I am really trying to but maybe it is better if we just focus on one thing. Lets take the most important one first that would be that it automatically opens when I arrive home and I will remove the other automations from now. Why would this one not work?
- alias: Automaticly open door when owners arrives home
trigger:
platform: state
entity_id: person.me.lastname
from: not_home
for: 00:05:00
to: home
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.ytterdorr_open
state: 'off'
- condition: state
entity_id: lock.ytterdorr
state: 'locked'
action:
- service: lock.unlock
entity_id: lock.ytterdorr
So logic in this one is:
Status changes from not_home to home after 5 minutes and the door is closed + locked. In this case it should open. Reason I have the 5 minute delay is that I donāt want to lock to spasm unlock and lock when I am just out of range of the wifi