Automation: Notification ๐Ÿ”” if any one of the different temperature is out of range

I want to create a notification with the sensor name and temperature value if the temperature is out of range in any one of the temperature sensors.
I found one example but it works with one fixed numeric state only i.e. above a specific temperature not below it.

I am trying to use the device id as a trigger instead.

Donโ€™t, you are only making things difficult for yourself in future. See: Why and how to avoid device_ids in automations and scripts

You can use above and below to define a range in the numeric state trigger. Heck you can even use input numbers if you want to easily change the range. See: https://www.home-assistant.io/docs/automation/trigger/#numeric-state-trigger

currently, tried this code how should I modify it to use above and below in a single trigger?

alias: Pump temperature trial
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    above: 24
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    above: 24
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 15
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 15
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: Pump room temperature Alert!!
      message: "{{ trigger.entity_id }} is above 24C"
mode: single

``

Look at the examples in the numeric state trigger link I posted above.

this is error it reported

Message malformed: A value can never be above 24.0 and below 17.0 at the same time. You probably want two different triggers.

copied the example

alias: Pump temperature trial
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    value_template: "{{ state.attributes.value - 5 }}"
    above: 24
    below: 17
    for:
      hours: 0
      minutes: 0
      seconds: 59
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: Pump room temperature Alert!!
      message: "{{ trigger.entity_id }} is above 24C"
mode: single

I want it to trigger, if any one of the sensors is out of range from 17-24C and it should mention the sensor name in the notification.

The answer is in the error message.
The same trigger can not be above and below at the same time. Use one for above and one for below.

trigger:
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    value_template: "{{ state.attributes.value - 5 }}"
    above: 24
    for:
      hours: 0
      minutes: 0
      seconds: 59
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    value_template: "{{ state.attributes.value - 5 }}"
    below: 17
    for:
      hours: 0
      minutes: 0
      seconds: 59

went with it, but the issue is message is the same even if it is above or below

Pump room temperature Alert!!
Pump 1 Temperature is above 24C
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 1
    above: 24
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    above: 24
    for:
      hours: 0
      minutes: 0
      seconds: 1
  - platform: numeric_state
    entity_id: sensor.a4_c1_38_85_14_c4_14c4_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 1
    below: 15
  - platform: numeric_state
    entity_id: sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 1
    below: 15
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: Pump room temperature Alert!!
      message: "{{ trigger.to_state.name }} is above 24C"
mode: single

Hereโ€™s the package I use across all my temperature sensor. Just do a search and replace, or use shell scripts.

It allows setting the limits in input numbers and enabling / disabling the high and low alarm limits and has a filter on temperature so an errant reading doesnโ€™t cause alerts to go off.

####
#### Template
#### ts_living_room_thermostat_temperature_high
#### {{ states("sensor.living_room_thermostat_temperature_filter") }} limit {{ states("input_number.al_ts_living_room_thermostat_temperature_high_limit") }}
#### 120
#### 120
#### false
#### sms_notifiers_all

input_boolean:
  al_ts_living_room_thermostat_temperature_high_alert_enable:
    name: ts_living_room_thermostat_temperature_high alert enable
  al_ts_living_room_thermostat_temperature_low_alert_enable:
    name: ts_living_room_thermostat_temperature_low alert enable
binary_sensor:
  - platform: template
    sensors:
      al_ts_living_room_thermostat_temperature_high_alert:
        value_template: '{{ (states("sensor.living_room_thermostat_temperature_filter")|float(100) > states("input_number.al_ts_living_room_thermostat_temperature_high_limit")|float(100)) and is_state("input_boolean.al_ts_living_room_thermostat_temperature_high_alert_enable", "on") }}'
        delay_on: "00:30:00"
  - platform: template
    sensors:
      al_ts_living_room_thermostat_temperature_low_alert:
        value_template: '{{ (states("sensor.living_room_thermostat_temperature_filter")|float(100) < states("input_number.al_ts_living_room_thermostat_temperature_low_limit")|float(100)) and is_state("input_boolean.al_ts_living_room_thermostat_temperature_low_alert_enable", "on") }}'
        delay_on: "00:30:00"
alert:
  al_ts_living_room_thermostat_temperature_high:
    name: ts_living_room_thermostat_temperature_high
    message: 'ALERT {{state_attr("zone.home","friendly_name")}} ts_living_room_thermostat_temperature_high {{ states("sensor.living_room_thermostat_temperature_filter") }} limit {{ states("input_number.al_ts_living_room_thermostat_temperature_high_limit") }}'
    done_message: 'Cleared {{state_attr("zone.home","friendly_name")}} ts_living_room_thermostat_temperature_high {{ states("sensor.living_room_thermostat_temperature_filter") }} limit {{ states("input_number.al_ts_living_room_thermostat_temperature_high_limit") }}'
    entity_id: binary_sensor.al_ts_living_room_thermostat_temperature_high_alert
    state: "on"
    repeat:
      - 120
      - 120
    can_acknowledge: true
    skip_first: false
    notifiers:
      - sms_notifiers_all
      - sms_telegram_admin
  al_ts_living_room_thermostat_temperature_low:
    name: ts_living_room_thermostat_temperature_low
    message: 'ALERT {{state_attr("zone.home","friendly_name")}} ts_living_room_thermostat_temperature_low {{ states("sensor.living_room_thermostat_temperature_filter") }} limit {{ states("input_number.al_ts_living_room_thermostat_temperature_low_limit") }}'
    done_message: 'Cleared {{state_attr("zone.home","friendly_name")}} ts_living_room_thermostat_temperature_low {{ states("sensor.living_room_thermostat_temperature_filter") }} limit {{ states("input_number.al_ts_living_room_thermostat_temperature_low_limit") }}'
    entity_id: binary_sensor.al_ts_living_room_thermostat_temperature_low_alert
    state: "on"
    repeat:
      - 120
      - 120
    can_acknowledge: true
    skip_first: false
    notifiers:
      - sms_notifiers_all
      - sms_telegram_admin
recorder:
  include:
    entities:
      - binary_sensor.al_ts_living_room_thermostat_temperature_high_alert
      - alert.al_ts_living_room_thermostat_temperature_high
      - input_boolean.al_ts_living_room_thermostat_temperature_high_alert_enable
      - input_number.al_ts_living_room_thermostat_temperature_high_limit
      - binary_sensor.al_ts_living_room_thermostat_temperature_low_alert
      - alert.al_ts_living_room_thermostat_temperature_low
      - input_boolean.al_ts_living_room_thermostat_temperature_low_alert_enable
      - input_number.al_ts_living_room_thermostat_temperature_low_limit
      - sensor.living_room_thermostat_temperature_filter
      - sensor.living_room_thermostat_temperature
####
#### Template
#### ts_living_room_thermostat_temperature_low
#### MESSAGE_DATA
#### REPEAT_1
#### REPEAT_2
#### SKIP_FIRST
#### NOTIFIERS
input_number:
  al_ts_living_room_thermostat_temperature_high_limit:
    min: 50
    max: 100
    step: 1
    unit_of_measurement: "ยฐF"
    mode: box
  al_ts_living_room_thermostat_temperature_low_limit:
    min: 30
    max: 70
    step: 1
    unit_of_measurement: "ยฐF"
    mode: box
sensor:
  - platform: filter
    name: "living_room_thermostat_temperature_filter"
    entity_id: sensor.living_room_thermostat_temperature
    filters:
      - filter: range
        lower_bound: 0
        upper_bound: 100
      - filter: outlier
        window_size: 4
        radius: 20/
description: ""
trigger:
  - platform: numeric_state
    entity_id:  
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
      - sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 1
    above: 24
  - platform: numeric_state
    entity_id: 
      - sensor.a4_c1_38_85_14_c4_14c4_temperature
      - sensor.pump_room1_f7e5_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 1
    below: 15
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: Pump room temperature Alert!!
      message: |
        {{ trigger.to_state.name }} is {{  "above "~trigger.above|string if trigger.above
        is not none else "below "~trigger.below|string }}C
mode: single