Automation for both devices at same time (Optimization)

Hello, is there a way to optimize this automation?

What I’m looking for is: when both devices are disconnected from the network/wifi an alert is generated (only when both are off for more than X time.

alias: PingPhonesTracker
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.192_168_68_50
      - binary_sensor.192_168_68_59
    to: "off"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.192_168_68_50
    state: "off"
  - condition: state
    entity_id: binary_sensor.192_168_68_59
    state: "off"
action:
  - service: notify.mobile_app_iphonealejo
    data:
      message: "No phones connected, proceed to turn off all system"
mode: single

nominally, but what you have seems fine to me too…

description: ""
mode: single
trigger:
  - platform: template
    value_template: "{{ states('binary_sensor.192_168_68_50') == 'off' and states(' binary_sensor.192_168_68_59') == 'off' }}"
  for:
    minutes: 5
condition: []
action:
  - service: notify.mobile_app_iphonealejo
    data:
      message: "No phones connected, proceed to turn off all system"
mode: single
1 Like

Tks so much!

1 Like