How can I stop alert based on time and day

I have several alerts set up and find them very useful and effective. However, a couple of them do not need to alert during weekdays work hours.

How can I automate this? On the alert card there is a switch to turn it off and I’d like to be able to automate that switch based on time.

Here is an example of an alert that I am using:

  garage_door:
    name: Garage is open
    done_message: Garage door has now closed
    entity_id: binary_sensor.garage_door
    state: 'on'
    repeat: 10
    can_acknowledge: True
    skip_first: True
    notifiers:
      - Prowl

I think what I need to do is automate state: ‘on’ to become off at certain times, but my experience so far has not yet come across a way to do this.

Can state: be set to a variable that I can change?

Thank you for any forthcoming help.

I haven’ tried this but assume alerts can be enabled or disabled the same way as automations:

Enable alert:

action: 
  service: homeassistant.turn_on
  entity_id: alert.garage_door

Disable alert:

action:
  service: homeassistant.turn_off
  entity_id: alert.garage_door

See complex alert criteria in the docs. Even says, “Maybe you want to disable the alert on certain days.” :wink:

Thank you.

I had read that but wasn’t altogether sure that it would/could do what I need. I’ll have a play with it, once I’ve learned templates.

@ashscott did you ever figure it out?

From the docs:

Possibly, when a battery percentage falls below a threshold. Maybe you want to disable the alert on certain days.

The example below that quote is only for battery percentage. I’m still unclear on a solution to this, short of checking another state in the binary sensor.

For example, I want binary_sensor.garage_door to display the correct state of the garage door always (checks just one values) however I only want the alert to fire at night. How to achieve this?

Create a template binary_sensor called binary_sensor.garage_door_alert with a value_template that indicates on only when binary_sensor.garage_door is on AND the current time is “at night”.

Create an alert that is activated when the state of binary_sensor.garage_door_alert is on.

How you go about defining “at night” is up to you. For example, you could create a Time of the Day Binary Sensor called binary_sensor.is_night.

binary_sensor:
  - platform: tod
    name: Is Night
    after: sunset
    before: sunrise

Putting it all together results in something like this:

binary_sensor:
  - platform: template
    sensors:
      garage_door_alert:
        value_template: >
          {{ is_state('binary_sensor.garage_door', 'on') and is_state('binary_sensor.is_night', 'on') }}

Thanks for you reply, but as mentioned that’s the solution I wanted to avoid:

I’m still unclear on a solution to this, short of checking another state in the binary sensor.

I want binary_sensor.garage_door to display the correct state of the garage door always (checks just one values)

There doesn’t seem to be another solution to this though, so as-per your example I’ll have to set up a dedicated “alert binary sensor”.

OK, I didn’t interpret ‘short of checking another binary sensor’ as meaning a desire to avoid doing it. My mistake.

The fact is the alert component is limited to monitoring another entity’s state. Period. It doesn’t support a value_template. Therefore you have no ability to create complex criteria within it, only within whatever other entity it is monitoring.

Your existing binary_sensor.garage_door reports the door’s state at all times (not just night) so some other sensor is needed to monitor the garage door AND the desired time period.

1 Like

Note that is feature “tod” has been broken since it was introduced. It does not set correctly when you restart HA and the start time is the day before. Typically sunset to sunrise fails when you restart HA after midnight. There is a work around I just added while we wait for the bug to be fixed

1 Like

In lieu of the tod sensor, one could check “if night” other ways such as this:

{{ is_state('binary_sensor.garage_door', 'on') and states('sun.sun') == 'below_horizon' }}