#Home Assistant: No notification when smart plug is physically unplugged

1 messages · Page 1 of 1 (latest)

dense furnace
#

Goal: Notify when a Milan smart plug loses power.
Issue: Physically unplugging the plug doesn’t fire the automation; manual run works.

What I’m using (triggers & logic): unavailable/unknown on the switch, or cloud connection off, plus a guard to ignore prior unavailable/unknown.

Questions:

  1. Do some integrations not flip to unavailable/unknown on power loss (cache last state instead)?
  2. Better pattern: availability_template, ping/device_tracker, or a device “no response” trigger?
  3. Could my condition block the first transition into unavailable/unknown?

Notes: Mobile push works; manual test of the automation works—only physical unplug fails to trigger. Thanks!

#
alias: MilanZi  Dose abgezogen (robust)
description: >
  Benachrichtigt, wenn eine der Milan-Steckdosen physisch abgezogen ist bzw.
  nicht mehr erreichbar wird.
triggers:
  - trigger: state
    entity_id:
      - switch.milan_laptop
      - switch.milan_bett
    to: unavailable
    for:
      hours: 0
      minutes: 0
      seconds: 5
  - trigger: state
    entity_id:
      - switch.milan_laptop
      - switch.milan_bett
    to: unknown
    for:
      hours: 0
      minutes: 0
      seconds: 5
  - trigger: state
    entity_id:
      - binary_sensor.milan_laptop_cloud_verbindung
      - binary_sensor.milan_bett_cloud_verbindung
    to: "off"
    for:
      minutes: 1
conditions:
  - condition: template
    value_template: |
      {{ trigger is defined and trigger.from_state is not none
         and trigger.from_state.state not in ['unknown','unavailable'] }}
actions:
  - variables:
      trig_id: "{{ trigger.entity_id if trigger is defined else '' }}"
      nice_name: >-
        {{ (state_attr(trig_id,'friendly_name') if trig_id else 'Manueller Test')
           or trig_id or 'Manueller Test' }}
  - action: notify.mobile_app_pixel_8_pro
    data:
      title: "Kinderzimmer: Steckdose offline"
      message: >-
        {{ nice_name }} ist nicht mehr erreichbar (vermutlich abgezogen/ohne Strom).
      data:
        tag: milan-strom
        ttl: 0
        priority: high
        clickAction: /config/entities/{{ trig_id if trig_id else 'automation' }}
  - action: persistent_notification.create
    data:
      title: Milan  Steckdose offline
      message: "{{ nice_name }} ist nicht mehr erreichbar."
      notification_id: milan_strom_offline
mode: single
#

Questions for the group:

  1. Do some integrations not flip to unavailable/unknown on power loss, and instead silently cache the last state?
  2. Would you recommend using a different signal (e.g., device_tracker/ping, availability_template, or a device trigger for “no response”) to catch power loss reliably?
  3. Any pitfalls with my condition that might block the first transition into unavailable/unknown?

Extra info:
Mobile push works in general; manual test of the automation also works. It only fails to trigger on physical unplug.

Thanks in advance!