Skip to content

Examples Automation

caiosweet edited this page Jul 10, 2023 · 6 revisions

Index

 

Blueprints

  1. 📱 Centro Notifiche - Mobile, Telegram and Alexa Actionable Notifications 📣
  2. 📱 Centro Notifiche and not only - Network Notification 📣

Index

Login attempts failed

Click to expand
---
automation:
  - alias: Centro Notifiche - Accesso Fallito
    description: >
      Tentativo di accesso o richiesta con autenticazione non valida.
      IP bloccato per troppi tentativi di accesso.

      Login attempt or request with invalid authentication.
      Banned IP for too many login attempts.
    mode: queued
    initial_state: true
    trigger:
      - platform: persistent_notification
        update_type:
          - added
        notification_id: ip-ban
      - platform: persistent_notification
        update_type:
          - added
        notification_id: http-login
    condition: "{{ trigger.notification.message is defined }}"
    action:
      - variables:
          message: "{{ trigger.notification.message }}"
          ban: "{{ trigger.notification.notification_id == 'ip-ban' }}"
          ipv4: >
            {{ (message | regex_findall(find='(?:\d{1,3}\.){3}\d{1,3}'))[0] }}
          icon: "{{ iif(ban, '⛔️', '🚫') }}"
          access: "{{ iif(ban, 'Negato', 'Fallito') }}"
      - service: persistent_notification.dismiss
        data:
          notification_id: http-login
      - service: script.my_notify
        data:
          title: "{{ icon }} Home Assistant Accesso {{ access }}."
          message_tts: &tts_access_msg "Attenzione. Accesso {{ access }}"
          message: |
            {{ icon }} Accesso {{ access }}: {{ ipv4 }}
            {{ as_timestamp(trigger.notification.created_at) | timestamp_custom('%X', true, now()) }}
          link: &link_tracker >-
            http://www.ip-tracker.org/locator/ip-lookup.php?ip={{ ipv4 }}
          notify: mobile app pixel 7, pushover, telegram
          priority: 1
          alexa:
            message: *tts_access_msg
          google:
            message: *tts_access_msg
          pushover:
            priority: 1
            url: *link_tracker
            url_title: IP Tracker
          mobile:
            url: *link_tracker
            clickAction: *link_tracker

Index

Welcome message

Click to expand
---
automation:
  - alias: Centro Notifiche - Benvenuto
    description: >
      Questa automazione invia un messaggio di benvenuto, ed è un puro esempio, 
      di come poter utilizzare il sensore di presenza in casa insieme al gruppo di persone. 
      In questo esempio, invia messaggi diversi a seconda del numero di persone che entrano in casa.
      La variabile utilizzata è "Benvenuto" ed è contenuta nel nostro file hub_build_message.yml di esempio.
   
      This automation sends a welcome message and is a pure example, 
      to be able to use the presence sensor in the house together with the group of people.
      In this example, it sends different messages depending on the number of persons entering the house.
      The variable used is "benvenuto" (welcome) and is contained in our example hub_build_message.yml file.
    mode: restart
    # initial_state: true
    trigger:
      - platform: state
        entity_id: binary_sensor.notifier_people_home
        attribute: entity
        for: "00:02:00"
    variables:
      current_people: "{{ trigger.to_state.attributes.entity | default([], true) }}"
      previous_people: "{{ trigger.from_state.attributes.entity | default(current_people, true) }}"
      people: "{{ current_people | reject('in', previous_people) | map('state_attr', 'friendly_name') | list }}"
      total_people: "{{ state_attr('group.notifier_location_tracker', 'entity_id') | count }}"
    condition: 
      - "{{ is_state('binary_sensor.notifier_people_home', 'on') }}"
      - "{{ not not people }}"
    action:
      - service: script.my_notify
        data:
          call_no_annuncio: 1
          google: true
          alexa:
            type: announce
          title: Welcome to Home
          benvenuto: >-
            {%- macro single(person) -%}
            {{ [
              "Welcome home " ~person~ "! It's nice to see you again! ",
              "Well it looks like " ~person~ "'s finally home! I'll get the house ready for you. ",
              "Awesome, " ~person~ "'s back! "
            ] | random }}
            {%- endmacro -%}

            {%- macro multiple(persons) -%}
            {{ [
              "Well, looks like " ~persons~ " are finally home! I'm going to the front door. ",
              "Finally! " ~persons~ ", you're back here with me again. ",
              "Guess who's back home? It's " ~persons~ " ",
            ] | random }}
            {%- endmacro -%}

            {%- macro all(persons) -%}
            {{ [
              "Our house is now complete. ",
              "We're all here, no one is missing anymore. I'm calling roll call: " ~persons~ " ",
              "Good good. The family is complete. ",
            ] | random }}
            {%- endmacro -%}

            {% if people | count == 1 -%}
              {{ single(people[0]) }}
            {% elif people | count == total_people -%}
              {{ all(people) }}
            {% else -%}
              {{ multiple([people[:-1] | join(', '), 'e', people[-1]] | join(' ')) }}
            {% endif -%}
          message: >-
            it's {{ now().strftime('%I:%M %p') }}, and all is well!

Index

Clone this wiki locally