Automation "Wait" Help

Hi

I have an automation that uses my wife and I’s phone device trackers to switch on the outdoor light when we arrive in the pre-configured home zone and then switch it back off again after 10 mins. There are a couple of conditions, one for sun/sunset and the other that the light isn’t already on.

alias: Front Door Light (Home Zone)
description: >-
  Turn on front door light when Jo or Ryan arrives in home zone and switch off
  after 10 mins.
trigger:
  - platform: device
    device_id: 8f0df0742263f7a7cd9be9ded9af9d3f
    domain: device_tracker
    entity_id: device_tracker.jo
    type: enters
    zone: zone.home
  - platform: device
    device_id: 130ce7df6b2b9ba08500bb9d47086ee5
    domain: device_tracker
    entity_id: device_tracker.ryan
    type: enters
    zone: zone.home
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
  - condition: state
    state: 'off'
    entity_id: light.front_door
action:
  - type: turn_on
    device_id: fe4692e03625aa556aed9df5e1b93fff
    entity_id: light.front_door
    domain: light
    brightness_pct: 100
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: fe4692e03625aa556aed9df5e1b93fff
    entity_id: light.front_door
    domain: light
mode: single

This works perfectly unless we take longer than 10 mins between entering the home zone and getting to the house, i.e. stopped for a chat etc

I would like to exchange the wait time for a wi-fi connection time where either of us have been connected to the home network (SSID: “ASUS”) for 10 mins, therefore ensuring we’ve made it to the house.

The sensors for the SSID are:
sensor.ryan_wifi_connection
sensor.jo_wifi_connection

I’m sure this should be easy, but for the life of me I cannot work out how to do it.

My presumption is that it’s a wait template but those seem to be set to pause an automation rather than shut it off.

Any help would be appreciated. Thanks

Can you create a new automation that contains the off cycle logic by using your WiFi connection?

Hmmm

I guess if I could set up a couple of boolean helpers and then write automations for both of us.

i.e.
input_boolean.wi_fi_connected_ryan
input_boolean.wi_fi_connected_jo

and then automations:

alias: Connected to ASUS for 10 mins (jo)
description: ''
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.jo_wifi_state
    to: ASUS
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.wi_fi_connected_jo	  
	  
alias: Connected to ASUS for 10 mins (ryan)
description: ''
mode: single
trigger:	  
  - platform: state
    entity_id: binary_sensor.ryan_wifi_state
    to: ASUS
	for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.wi_fi_connected_ryan```

Then use the output of the boolean connector as a trigger to turn off the light.

However I’m then stuck on the logic thinking that’s not going to work if one of us is already in the house.

I’m new to HA, so this is probably the worst way to do this…

Helper(s)

  1. input_select.occupancy
  2. input_datetime.light_Off_Time – Optional to deal with time resets –

One automation using the Choose function for setting input_select.occupancy (Jo Home ; Ryan Home, All Home)

Another automation based on the status of input_select.occupancy for controlling the light ON function and it’s time off basis.

And then a final based on the status of input_select.occupancy and input_datetime.light_Off_Time for controlling the light OFF function.

Here is an example of something slightly similar I do for setting the player status of my 4 CCA’s.

alias: Audio Speaker Status
description: ''
trigger:
  - platform: state
    entity_id: >-
      media_player.office_cca_speaker , media_player.living_room_cca_speaker ,
      media_player.kitchen_cca_speaker , media_player.master_bedroom_cca_speaker
    to:
      - playing
      - paused
      - idle
      - 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: |-
              {{ 'playing' in states('media_player.office_cca_speaker') or 
              'playing' in states('media_player.living_room_cca_speaker') or
              'playing' in states('media_player.kitchen_cca_speaker') or
              'playing' in states('media_player.master_bedroom_cca_speaker') }}
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.cca_speaker_status
            data:
              option: Playing
      - conditions:
          - condition: template
            value_template: |-
              {{'paused' in states('media_player.office_cca_speaker') or 
              'paused' in states('media_player.living_room_cca_speaker') or
              'paused' in states('media_player.kitchen_cca_speaker') or
              'paused' in states('media_player.master_bedroom_cca_speaker') }}
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.cca_speaker_status
            data:
              option: Paused
      - conditions:
          - condition: template
            value_template: |-
              {{'idle' in states('media_player.office_cca_speaker') and 
              'idle' in states('media_player.living_room_cca_speaker') and
              'idle' in states('media_player.kitchen_cca_speaker') and
              'idle' in states('media_player.master_bedroom_cca_speaker') }}
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.cca_speaker_status
            data:
              option: Idle
      - conditions:
          - condition: template
            value_template: |-
              {{'off' in states('media_player.office_cca_speaker') and 
              'off' in states('media_player.living_room_cca_speaker') and
              'off' in states('media_player.kitchen_cca_speaker') and
              'off' in states('media_player.master_bedroom_cca_speaker') }}
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.cca_speaker_status
            data:
              option: Idle
    default: []
mode: restart

I have something similar using a template in my config yaml

binary_sensor:

  - platform: template
    sensors:
      home_occupancy:
        friendly_name: Someone home?
        icon_template: >-
          {% if is_state('binary_sensor.home_occupancy','on') %}
            mdi:home-account
          {% else %}
            mdi:home-outline
          {% endif %}
        value_template: "{{ is_state('person.ryan','home') or is_state('person.jo','home') or is_state('input_boolean.guest_mode','on')}}"
                
  - platform: template
    sensors:
      away_mode:
        friendly_name: Away Mode
        icon_template: >-
          {% if is_state('binary_sensor.away_mode','on') %}
            mdi:shield-lock
          {% else %}
            mdi:shield-lock-outline
          {% endif %}
        value_template: "{{ states('person.ryan') != 'home' and states('person.jo') != 'home' and is_state('input_boolean.guest_mode','off')}}"

I’ll need to have a think about it (i,e, remember what the loguc does!) when I’ve had a little less christmas “spirit”!

Cheers