Master button for pausing/stopping alerts

All,

I have some templates setup with binary sensors for certian conditions…

template:
  - binary_sensor:
      - name: "Garage Temp Low"
        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 }}"

That then trigger a notificaiton

garage_temp_sensor:
    name: Garage Low Temperature
    entity_id: binary_sensor.garage_temp_low
    state: "on"
    repeat: 5
    skip_first: False
    message: The garage temperature is low
    done_message: The garage temperature has returned to normal
    notifiers:
     - mobile_app_RK_12
     - gmail

How would one make some code based on a boolean button to pause/stop the notifications ?

This will do it but will change your Temp Low binary sensor to off when paused.

template:
  - binary_sensor:
      - name: "Garage Temp Low"
        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 and is_state('input_boolean.pause_aterts', 'off') }}"

If that is confusing you could change it to a sensor rather than a binary sensor, so you can have the states on/off/paused:

template:
  - sensor:
      - name: "Garage Temp Low"
        state: >
          {% if is_state('input_boolean.pause_aterts', 'off') %}
            {{ 'on' if states('sensor.garage_temp_sensor') | float(0) <= 10.0 else 'off' }}"
          {% else %}
            paused
          {% endif %}

No need to change your alert.

Thank you for the reply, I couldn’t get the second option to work for some reason?, below in my input boolean, the original alert was left alone as you mentioned. Note that the alarm doesn’t work either without the pause?.

input_boolean:
  pause_alerts:
    name: pause alerts
    icon: mdi:toggle-switch

You’re kind of reinventing the wheel here. One of the nice things about the alert entity is it actually supports 3 states. idle, on, off.

Why don’t you just display the alert in the front end instead of the input boolean you have created? Turning off the alert boolean will stop the notifications with the added advantage that the “off” state of the alert entity still indicates that the alert is active.

Here is a card in my config that displays all active alerts. As you can see you can toggle them on or off which will stop the notifications, but they remain visible on the card even though the alert has been turned “off” so you can turn them back on if necessary.

You would need the custom auto-entities card to implement this exactly as is. You could also probably achieve the same effect using the built in entities filter card but you would need to manually list your alert entities.

image

  - type: custom:auto-entities
    show_empty: true
    filter:
      include:
        - domain: alert
      exclude:
        - state: "idle"
    sort:
      method: name
      ignore_case: true
    card:
      type: entities
      title: "Active Alerts"
      show_header_toggle: false
      state_color: true
1 Like

Share your config as written for the sensor and alert. Also any relevant errors in the log.

I assume they want to pause all of them at once.

Ah. Well in that case I’d probably do exactly what the post title asks for so you don’t have to edit the trigger sensor for every alert, plus you’re not disabling the alerts when you really only want to stop the notifications. Also, with the boolean solution you’ll have to remember to turn the boolean back on at some point if you want the alert to work again.

template:
  - button:
      - name: "Pause Alerts"
        unique_id: pause_alerts
        icon: mdi:alert
        press:
          - service: alert.turn_off
            entity_id: >
              {{ states.alert
                  |selectattr('state','eq','on')
                  |map(attribute='entity_id')|list }}

Just another way to skin the cat! :slight_smile:

1 Like

Sorry for the delay…

Sensor

    - name: "Garage Temp Sensor"
      state_topic: "garage/sensor/temperature"
      unit_of_measurement: "°C"
      device_class: "temperature"

Alert

garage_temp_sensor:
    name: Garage Low Temperature
    entity_id: binary_sensor.garage_temp_low
    state: "on"
    repeat: 5
    skip_first: False
    message: The garage temperature is low
    done_message: The garage temperature has returned to normal
    notifiers:
     - mobile_app_RK_12
     - gmail

Below as per your suggestion above

  - sensor:
      - name: "Garage Temp Low"
        state: >
          {% if is_state('input_boolean.pause_alerts', 'off') %}
            {{ 'on' if states('sensor.garage_temp_sensor') | float(0) <= 18.0 else 'off' }}"
          {% else %}
            paused
          {% endif %}

Where did you put that last sensor?

It is under…

template:

And where is that?

Here, sorry I commented it out so please ignore the #.

#  - button:
#      - name: "Pause Alerts"
#        unique_id: pause_alerts
#        icon: mdi:alert
#        press:
#          - service: alert.turn_off
#            entity_id: >
#              {{ states.alert
#                  |selectattr('state', 'eq', 'on')
#                  |map(attribute='entity_id')|list }}

No the template sensor. Where is the template sensor?

In which file?

This is everything under template, maybe I don’t have it, sorry I am still a noob at this :frowning:

template:
#  - binary_sensor:
#      - name: "Garage Temp Low"
#        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 }}"
      
  - binary_sensor:
      - name: "Garage Temp Low"
        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 and is_state('input_boolean.pause_alerts', 'off') }}"




#  - sensor:
#      - name: "Garage Temp Low"
#        state: >
#          {% if is_state('input_boolean.pause_alerts', 'off') %}
#            {{ 'on' if states('sensor.garage_temp_sensor') | float(0) <= 18.0 else 'off' }}"
#          {% else %}
#            paused
#          {% endif %}



  - binary_sensor:     
      - name: "Sump Level High"
        state: "{{ states('sensor.sump_level_sensor') | float(0) >= 75.1 }}"

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= 35.0 }}"

input_boolean:
  pause_alerts:
    name: pause alerts
    icon: mdi:toggle-switch

#  - button:
#      - name: "Pause Alerts"
#        unique_id: pause_alerts
#        icon: mdi:alert
#        press:
#          - service: alert.turn_off
#            entity_id: >
#              {{ states.alert
#                  |selectattr('state', 'eq', 'on')
#                  |map(attribute='entity_id')|list }}

Yes but…

and did you restart home assistant after creating it?

Sorry, config.yaml and I did re-start. I am going to try again from scratch as I had a lot of stuff going on at the same time.

Update:

Got it thank you for the help and more importantly the patience :slight_smile: