Notification when sensor is unavailable

Hi,

I am looking for help with two separate but related issues. I have a few battery-powered sensors that are programmed to go into a deep sleep for intervals of 1 hour, then wake up, measure and back to sleep. The battery lasts 1 to 2 months. I am trying to get a notification when they get unavailable. Here is the code that I am playing with;

- id: bath1-unavailable
  alias: "Notify bath1-unavailable"
  trigger:
  - platform: state
    entity_id: sensor.temp_bathroom_1
    to: unavailable
    for:
      hours: 2
  action:
    - service: notify.telegramnote
      data:
        title: 'HA warning!!!'
        message: "Sensor bath 1 is unavailable"

So first question, assuming that the code above works. Will HA be able to distinguish between a deep-sleep and unavailable\battery empty?

Second question, how to apply this code to all sensors, without having to copy-paste 10 times?

Thanks a million guys,

Is battery state being reported to HA as well?
What are the states reported to HA for those sensors?, check the history for the state changes.

- id: sensor-unavailable
  alias: "Notify Sensor Unavailable"
  trigger:
  - platform: state
    entity_id:
      - sensor.temp_01
      - sensor.temp_02
      - sensor.temp_03
    to: unavailable
    for:
      hours: 2
  action:
    - service: notify.telegramnote
      data:
        title: 'HA warning!!!'
        message:  >-
          "{{ trigger.to_state.attributes.friendly_name }} is unavailable"

Thanks @Coolie1101.

I have struugled to get battery voltage from my Mini d1. so I gave up. So no battery state on the device.

So, what are the states reported to HA for those sensors?

they keep reporting temperature. one went to state unknown and the temperature becomes constant. so an easy (?) solution would be to check if temperature remains constant for a certain period of time.

thanks for the help

FYI, Monitor your car battery in Home Assistant - #36 by laca75tn