Automation to unlock my door when I come home

Unfortunately, now that I think about this more, this won’t work under all scenarios. :frowning: Let me think about this some more…

1 Like

No problem, and don’t use too much time on this. I can live without this function :slight_smile:

1 Like

Ok, one more try:

input_boolean:
  away_long_enough:
    initial: off
automation:
  - alias: Record if away long enough
    trigger:
      platform: state
      entity_id: group.tracker_group_borge
      to: 'not_home'
      for:
        minutes: 1
    action:
      service: input_boolean.turn_on
      entity_id: input_boolean.away_long_enough

and:

  - alias: Unlock bluetooth
    trigger:
      platform: state
      entity_id: device_tracker.iphone_x
      to: 'home'
    condition:
      condition: state
      entity_id: input_boolean.away_long_enough
      state: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.away_long_enough
      - service: switch.toggle
        entity_id: switch.yale_lock
      - service: notify.pushover
        data:
          title: "Casa de Olsen:"
          message: "Dør låst opp!"

EDIT: Fixed trigger in first automation. Originally written as from: 'home'.

1 Like

I am getting one validation error, not sure what is causing that.

Here is the code I am now using.

###################################################################
# Lås opp dør ved BT connected   #del 1 
###################################################################

- id: rec_time
  alias: Record if away long enough
  trigger:
    - platform: state
      entity_id: group.tracker_group_borge
      from: 'home'
      for:
        minutes: 1
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.away_long_enough

####### Lås opp dør ved BT  # del 2 ##########

- id: unlc_bt
  alias: Unlock bluetooth
  trigger:
    - platform: state
      entity_id: device_tracker.iphone_x
      to: 'home'
  condition:
    - condition: state
      entity_id: input_boolean.away_long_enough
      state: 'on'
  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.away_long_enough
    - service: switch.toggle
      entity_id: switch.yale_lock
    - service: notify.pushover
      data:
        title: "Casa de Olsen:"
        message: "Dør låst opp!"

Validation error:
Invalid config for [automation]: dependency violation - key “for” requires key “to” to exist @ data[‘trigger’][0]. Got None

1 Like

Yep, already thought of that but I’ve been away from my keyboard for a bit. :slight_smile:

In a state trigger, for: can only be used with to:, so in the trigger in the first automation, change: from: 'home' to to: 'not_home'.

2 Likes

That did the trick! :slight_smile:

Door unlocked just like intended when I came home. Also did another test to see if the door would unlock when “not_home” state was under 1 minute. Did not open door. So everything works just fine!

Thank you so much!

1 Like

Glad to hear! I’ll go back and edit my previous post with the latest change for future reference.

1 Like

wouldn’t this be the perfect place for a wait_template? wait for a certain time to have passed, and then action?

I do something similar with several lighting scenarios and they work really nicely. Instead of creating an extra automation with the input_boolean, one makes a binary_sensor like this:

  master_bedroom_motion_sensor_timed:
    friendly_name: 'Master bedroom motion sensor timed'
    value_template: >
      {{ is_state('sensor.master_bedroom_motion_sensor','on')}}
    delay_off:
      minutes: 1
    device_class: motion

and use that in the main automation?

  - alias: 'Switch Masterbed outlet when movement'
    id: 'Switch Masterbed outlet when movement'
#    initial_state: 'on'
    trigger:
      platform: state
      entity_id: sensor.master_bedroom_motion_sensor
      to: 'on'
    condition:
      - condition: template
        value_template: >
          {{ is_state ('sensor.activity_selection', 'Naar bed')}}
      - condition: template
        value_template: >
          {{is_state('switch.master_bed_outlet', 'off')}}
    action:
      - service: switch.turn_on
        entity_id: switch.master_bed_outlet
#      - wait_template: >
#          {{as_timestamp(now()) | int - 
#            as_timestamp(states.sensor.master_bedroom_motion_sensor.last_changed) | default(0) | int > 120 }}
      - wait_template: >
          {{ is_state('binary_sensor.master_bedroom_motion_sensor_timed','off')}}
#          {{ is_state('sensor.master_bedroom_motion_sensor', 'off') }}
#      - delay:
#          minutes: 1
      - service: switch.turn_off
        entity_id: switch.master_bed_outlet
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_system', 'on')}}
      - service: notify.notify
        data_template:
          message: >
            {{as_timestamp(now()) | timestamp_custom("%X") }}: You've walked safely lift. Signing off.

replace light with lock, and motion_sensor with group.tracker_x and your set :wink:

This is awesome. I am not that great at all of this I just have a couple questions if that’s ok. Do you just cut and paste all of this into the configuration yaml then make the necessary changes or do you need to create the input Boolean somewhere by itself then create the automation. this is where I do not understand everything yet I have the same problem but I just use my phone and when home assistant sees my phone is connected to my WIFI it will unlock my door but I could be siting in the house and my door will just unlock. I have another automation setup to just lock my door if unlocked for more then a few min just incase it thinks I left my house but I didn’t. Maybe there is a way easier way now as I know this is over 4 years old. Thank you from a very new user. lol