Disconnected device warning in HA

Can someone tell me how to make a device go offline (due to low link quality or low battery), notify me with a message or similar? Thank you!!

Here’s something to start with:

alias: 'Notify when unavailable '
description: ''
mode: single
trigger:
  - platform: state
    entity_id:
      - YOUR_ENTITY
    to: 'unavailable '
condition: []
action:
  - service: notify.mobile_YOUR_PHONE
    data:
      message: Your entity is unavailable due to whatever reason.

Easy to configure in visual editor.

Thanks a lot !!!