Actionable Notifications in Home Assistant

Actionable Notifications in Home Assistant

In this post I want to break down actionable notifications. As the name implies, these are notifications you can receive that you can click to perform an action within home assistant. These are immensely powerful and I am going to show you how I use the in my smart home.

Here is the breakdown:

  • Create automation trigger to track whatever you need tracked.
  • Set your conditions to prevent false triggers
  • Create your Action to send notification to your phone/tablets etc
  • Create buttons in your notifications and tie them to an automation, script etc.

Example 1: Cat Feeder Missed Notification:

This automaton is pretty simple but the secret sauce is in the condition. If you don't know what conditions are, see my blog post about it here.

alias: Notify if Cat Feeder Schedule Missed
description: Notify if the Cat Feeder Schedule has not run in 8 hours
triggers:
  - trigger: time_pattern
    hours: /1
  - trigger: state
    entity_id:
      - automation.cat_feeder_schedule
    from: "off"
    id: Cat_food_dispensed
conditions:
  - condition: template
    value_template: >-
      {{ now() - states.automation.cat_feeder_schedule.attributes.last_triggered
      > timedelta(hours=7) }}
actions:
  - action: notify.mobile_app_pixel_8
    metadata: {}
    data:
      title: Cat Feeder Schedule hasn't run in 7 hours!
      message: Do you want to dispense food?
      data:
        tag: cat_food_missed
  - action: notify.mobile_app_hannah_iphone
    metadata: {}
    data:
      title: Cat Feeder Schedule hasn't run in 7 hours!
      message: Do you want to dispense food?
      data: 
        tag:cat_food_missed
mode: single

This code is what is responsible to for checking if the feeder automation has ran in the last x hours. If not then it performs the rest of the automation. Just replace the entity with whatever you are tracking.

conditions:
  - condition: template
    value_template: >-
      {{ now() - states.automation.<your_automation_entity>.attributes.last_triggered
      > timedelta(hours=<threshold_hours>) }}

Example 2: Turn off light notification:

My condo has a pretty open area in the Kitchen/Living Room area. This combined with having two cats who like to climb, makes placing motion sensors to turn on/off lights tricky.

My issue has been the motion sensors get triggered by my cats and the lights turning on when we don't want them to in the kitchen and living room area. Also my cats tend to just sit in front of the sensors, thus the lights never shut off! Jerks! Presence sensors also don't work since well... Cats are alive and put out heat.

So what do you do?

Instead of turning the lights off when you leave the room, you'll get a notification on your phone instead to turn off the lights!

alias: Notification - Master Bath Lights
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.master_bathroom_motion_sensor_motion
    to: "off"
    for:
      hours: 0
      minutes: 20
      seconds: 0
conditions:
  - condition: state
    entity_id: light.master_bath_lights_group
    state: "on"
actions:
  - action: notify.mobile_app_pixel_8
    metadata: {}
    data:
      data:
        actions:
          - action: TURN_OFF
            title: Turn off
          - action: "NO"
            title: "No"
      message: >-
        No motion detected in the Master Bathroom for 20 minutes. Do you want to
        turn   off the lights?
  - action: notify.mobile_app_hannah_iphone
    data:
      data:
        actions:
          - action: TURN_OFF
            title: Turn off
          - action: "NO"
            title: "No"
      message: >-
        No motion detected in the Master Bathroom for 20 minutes. Do you want to turn off the lights?
mode: single

Conclusion:

I hope you fond this useful and please let me know what actionable notifications you come up with! I am always learning myself and am interested in what people come up with for their smart home!

Great! Next, complete checkout for full access to Automate It!.
Welcome back! You've successfully signed in.
You've successfully subscribed to Automate It!.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.