BeardedTinker / Home-Assistant_Config

BeardedTinker Home Assistant configuration. Feel free to browse, edit, tweak, improve, criticize and suggest.
MIT License
383 stars 48 forks source link

Notify Engine update and documentation #67

Closed BeardedTinker closed 2 years ago

BeardedTinker commented 2 years ago

As Notify Engine is subject of one of my future videos, you can read here more documentation.

I have first started using this script by @CCOSTAN year ago and one of the first things I did was to adapt it to support some specifics of the Android Companion App options.

This script will work with most notification platforms that Home Assistant has integration with (TBH - all I've tested so far work, but potentially there could be some that are not supported at the moment).

Script only requires MINIMAL configuration, and that is for you to customise part with available notification platforms in your system.

    - service: >
          {% if who == 'person1' %}
            notify.mobile_app_eml_l29
          {% elif who == 'person2' %}
            notify.mobile_app_ele_l29
          {% elif who == 'kid1' %}
            notify.mobile_app_iphone
          {% elif who == 'kid2' %}
            notify.mobile_app_fig_lx1
          {% elif who == 'parents' %}
            notify.parents
          {% elif who == 'family' %}
            notify.family
          {% elif who == 'discord' %}
            notify.andrej_discord
            {% else %}
            notify.telegram_bot
          {% endif %}

You can add as many integration here as you wish and also by using groups you can group multiple notification platforms into new group (in this example parents, family and discord are multiple devices and services under single name).

And if you want to use it, you just have to call this script from any automation where you need to call it, and provide variables that would customise notifications.

For example, this is what I call from automation if front door is open:

- service: script.notify_engine
  data:
    who: 'family'
    title: '🚪*Front door*'
    value1: 'Front door is open! Outside temperature is {{ states("sensor.balcony_temperature") }}°C'
    tag_id: 'warning'
    group: home
    color: '#ff0000'
    target_id: !secret telegram_bot_chat_id

And you do have a lot of variables you can play with.

Main ones are: who: List of available platforms and variable that is used to select where to push notification title: Title of the message - not all notification platforms support this value1: value2: value3: Value variables are used as messge body. Up to 3 lines can be used target_id: Some platforms require you to specify target ID of the channel for message in ex. Discord, Telegram etc

As minimum, for basic notification platform, you need value1: That is just single line of message. And if you do not specify who: , default platform will be used.

Additional variables that can customise for your notifications look or behave are these: subtitle: Subtitle can be used for text under the title (subtitle in iOS, subject in Android) clickAction: Used toprovide URL that can be called after clisking notification (url in iOS, clickAction in Android) tag_id: Used to tag notifications, useful for mobile app notifications group: Used to group notificatrions, useful for mobile app notifications sticky: Android specific - true will make notification stick even when you press on it, default is false color: Android specific - change notification color. can use hex code or color name (#ff0000 or 'orange') channel_id: Android specific - create or use channel for notification. Default is 'general' importance_id: Android specific - in combination with channel used to define importance: high, low, max, min and default vibrationPattern: Android specific - NOT YET USED ledColor: Android specific - you can use hex code or color name (#ff0000 or 'orange') timeout_sec: Android specific - allows you to atumaticly expire notification after nnn secons - numeric value, in ex. 900 camera_entity: Disply image ios_category: iOS specific - iso_sound: iOS specific - DISABLED ios_badge: iOS specific - DISABLED

Some variables are platform specific, and whenever possible, I've tried to combine platform specific commands with one single variable. So even if you have Android and iOS devices in your household, they should receive similar notifications.

CCOSTAN commented 2 years ago

I think my notify engine will be broken sooner rather than later with the new updates to the IOS Companion.

https://github.com/CCOSTAN/Home-AssistantConfig/issues/1072

Because of the dynamic actions now, I think passing variables to a script will become a lot harder.. (I think)

BeardedTinker commented 2 years ago

I see what you mean. Not using actions here, was thinking to implement it without much thought on what huge complexity this really would add in terms of variables. It would be really to hard to manage.

BeardedTinker commented 2 years ago

Update all my automation that use Notfiy Script to use same set of variables (most of the time).

Now every call to notify_script: has following format and variables:

- service: script.notify_engine
  data:
    who: 'family'
    title: '*Front door*'
    value1: "Motion in apartment! No family member is home"
    target_id: !secret telegram_bot_chat_id
    group: security
    tag_id: 'emergency'
    importance_id: default
    color: 'red'
    sticky: 'true'
#    timeout: 

Also, created Excel file with all notifications and how they are use, to whom they send message etc. I'm still not using importance_id: so it's currently at default setting for everything, and not all automation have, use or need timeout:.

carltonwb commented 2 years ago

"Also, created Excel file with all notifications and how they are use, to whom they send message etc." Very interesting, I keep a spreadsheet for all my devices, with mac, id, software version, etc. What is your format for the notifications?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.