this post was submitted on 26 Mar 2024
22 points (100.0% liked)

homeassistant

11394 readers
23 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 1 year ago
MODERATORS
 

Hi, all. My wife and I recently got new phones, and it got me thinking again about how notifications work.

Currently I have several automations (maybe 10) that send notifications to my phone, her phone, both, and possibly other devices.

But when we get a new phone, or replace a tablet, etc., I have to update every single one of those automations. And I inevitably forget some or introduce errors.

Is there a better way to do this? For example, it'd be nice if I could abstract the concept of "my phone" out in those automations, then I'd only have to change the device "my phone" in one place, rather than a bunch of places.

Any thoughts on this? Maybe I'm missing a way to do it. Thanks.

top 14 comments
sorted by: hot top controversial new old
[–] [email protected] 14 points 3 months ago (2 children)

I set up a notify group for each of us. I use notify.me and add/remove the devices as needed.

notify:
- name: me
  platform: group
  services:
   # - service: mobile_app_pixel_2_xl
    - service: mobile_app_pixel_6

- name: her
  platform: group
  services:
    - service: mobile_app_iphone

Then you can use it like any other service:

service: notify.me
data:
  message: Test
  title: Alert!
[–] [email protected] 2 points 3 months ago

This is how my partner and I do our notifications. We've got "him", "her", and "us", depending on who needs the notification. Whenever either of us gets a new device, I add it to either of our groups and then works.

[–] [email protected] 1 points 3 months ago

Ah, thank you! I will look into this further!

[–] ThePantser 8 points 3 months ago (1 children)

Yes notifications need an overhaul, we assign devices to people we should be able to choose notify.user as a service and choose the user to send the notification to. That way when we change devices we only have to associate the device with the user again.

[–] [email protected] 1 points 3 months ago

Well, I'm glad to hear I'm not missing something. Thanks.

[–] mojo17 5 points 3 months ago* (last edited 3 months ago) (1 children)

I use the notify service with a group platform. This way you add and remove devices in one place only. Here's how I set it up in configuration.yaml:

notify:
  - name: notify_all_devices
    platform: group
    services:
      - service: mobile_app_pixel_6_pro
      - service: mobile_app_pixel_3_xl

In my automation triggers, I simply call my notify_all_devices service.

[–] [email protected] 1 points 3 months ago

Thank you! I will look into this!

[–] [email protected] 3 points 3 months ago* (last edited 3 months ago) (2 children)

I utilize scripts for all of my notification needs. It allows me to utilize logic based around certain criteria, like this on that will only notify family members at home. If no one is home it will wait and notify the first person to show up. This also allows me to be able to quickly toggle notifications for my wife when I'm testing automations with notifications.

alias: Notify People at Home
fields:
  title:
    description: The title of the notification
    example: Laundry
  message:
    description: The message content
    example: Washer Finished!
sequence:
  - if:
      - condition: state
        entity_id: zone.home
        state: "0"
    then:
      - wait_for_trigger:
          - platform: numeric_state
            entity_id: zone.home
            above: "0"
    else: []
  - parallel:
      - if:
          - condition: state
            entity_id: person.bob
            state: home
        then:
          - service: script.notify_bob
            data:
              title: "{{ title }}"
              message: "{{ message }}"
      - if:
          - condition: state
            entity_id: person.mary
            state: home
        then:
          - service: script.notify_mary
            data:
              title: "{{ title }}"
              message: "{{ message }}"
mode: queued
icon: mdi:exclamation-thick
max: 10
[–] [email protected] 2 points 3 months ago (1 children)

This is really cool. I've been out and about and have gotten notification the laundry is done, and it's like, welp, that's not very useful information right now. Thanks!

[–] [email protected] 1 points 3 months ago (1 children)

The only issue with doing it this way is that the UI to call the script isn't as nice as calling the notification service directly, but it isn't too bad to switch to yaml mode and populate the parameters once you get used to it.

[–] [email protected] 2 points 3 months ago

Yeah, I'm okay with the YAML mode, so that's not a major problem for me.

[–] [email protected] 2 points 3 months ago* (last edited 3 months ago)

I have something similar, but added user names to the mix. “names_iphone” works for “alert name” and similar.

[–] yesterdayshero 1 points 3 months ago (1 children)

Recently did this and yes it's a pain. I don't know if it's going to help until next time we change phones, but what I did this time was name the device after the person, rather than the phone model.

The idea being that I can delete the old device in the future and replace it with the new device, named the same. That way I don't have to change the device name in each automation every time. Hopefully that made sense. But I still haven't tested it in reality.

[–] [email protected] 1 points 3 months ago

I could see that working in theory, but in reality we both still have our old phones - in fact I had to find my wife's old phone this morning and shut off the alarm she'd left on.