How to run Automation for Aqara Blind Motor based on occupancy - only once

Hi - I’ve successfully installed and configured an automation that opens the blinds in my master bathroom when it detects occupancy after 8am (i.e. someone enters the master bathroom after that time). There’s then another (separate) automation that closes the blinds at sunset. All works perfectly except if someone manually closes the blinds after 8am, the automation triggers again to open the blinds when it detects occupancy.

I’d like to have the automation run one upon occupancy, then implement a condition that checks to see if it’s already been run that day (and if it has, doesn’t run again).

I’m not super skilled in YAML but here’s the current automation in use:

alias: Open Master Bathroom Blinds in AM with Occupancy
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 8b33b17d7a996143d5ae797d50a0d256
    entity_id: binary_sensor.0x54ef441000491083_occupancy
    domain: binary_sensor
condition:
  - condition: time
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "07:00:00"
    before: "17:00:00" 
action:
  - device_id: c6e723e7aecf948defa633d57797f0a1
    domain: cover
    entity_id: cover.0x54ef4410004d2a47
    type: set_position
    position: 100
mode: single

Doing some research on here I found a condition that may be applicable but I’m not sure how to implement it without borking the YAML code.

"{{ this.last_triggered.date() != now().date() }}" 

Would this work?

alias: Open Master Bathroom Blinds in AM with Occupancy
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 8b33b17d7a996143d5ae797d50a0d256
    entity_id: binary_sensor.0x54ef441000491083_occupancy
    domain: binary_sensor
condition:
  - condition: time
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "07:00:00"
    before: "17:00:00"
  - condition: "{{ this.last_triggered.date() != now().date() }}"    
action:
  - device_id: c6e723e7aecf948defa633d57797f0a1
    domain: cover
    entity_id: cover.0x54ef4410004d2a47
    type: set_position
    position: 100
mode: single

Thanks in advance for the help!

Template Condition in shorthand notation.

condition:
  - condition: time
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "07:00:00"
    before: "17:00:00"
  - "{{ this.attributes.last_triggered.date() != now().date() }}"    

Many thanks! I’ll give this a go.

Any progress to report?

Apologies - I should have circled back to confirm and tie off here. Yes, this worked perfectly. My adjusted YAML now looks like this:

alias: Open Master Bathroom Blinds in AM with Occupancy
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 8b33b17d7a996143d5ae797d50a0d256
    entity_id: binary_sensor.0x54ef441000491083_occupancy
    domain: binary_sensor
condition:
  - condition: time
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "08:00:00"
    before: "17:00:00"
  - "{{ this.attributes.last_triggered.date() != now().date() }}"
action:
  - device_id: c6e723e7aecf948defa633d57797f0a1
    domain: cover
    entity_id: cover.0x54ef4410004d2a47
    type: set_position
    position: 100
mode: single

Thanks again!

1 Like

I thought the code was suppose to be in the condition template? Like this:

condition:
  - condition: template
    value_template: "{{ now().date() > this.attributes.last_triggered.date() }}"

Or can both work?

It’s in shorthand notation.

1 Like