💬 Entity State Notification

Could you explain what you’ve tried to configure? I have no problems with a minimal setup like an entity, the state and a notify device.

Hello Panhans,

thanks for the blueprint.
I use your blueprint to notify my Android phone about my open windows.
I also have the notification display the time for how long the window has been open.
But I have noticed that the automation behaves strangely when the window is briefly closed and then reopened.
I get the notification on my phone after the set time.
After the set repeat time, the repeat notification also comes and the window open time is also updated.
If the window is now briefly closed and then reopened (e.g. to put it in the tilt position), the Android notification is also removed when it is closed.
But the old repeat message still comes in the set repeat time.
In addition, the new message about the reopening also comes in the set period.
I suspect that the old repeat event is not canceled and then after the set time it is checked whether the state is still open. The status is also opened by closing and reopening.
The old repeat event should actually have been canceled.
As if I trigger the stop function for the Android message, the active waiting event should also be canceled when the window is closed.

Is this behavior working as designed?
Or do I have to configure something special?

I test the current Github version 2.3.0, but the older one have the same result.

1 Like

I’d just pushed an updated. The bug should be fixed. But there is one breaking change depending on the time options. I switched them to duration selectors. So maybe you have to delete the period duration and for duration in yaml and reset them or just delete your old automations and create them new.

Version: 2.4.0

Great blueprint, works well. Thank you!

I use it for sauna current temperature while it is heating.
All the functionality is there but i was wondering if there is an option to make periodic notifications less promiment - I need periodic updates for updating current temperature state in notification message. Currently it triggers new notification, would be nice to be able to just update the message of existing notification so my phone does not light up every time it’s updated. First world problems.

1 Like

You can set a custom channel for the notifications in the blueprint settings. After at least one notification got fired you can navigate in your companion app to companion app settings → notifications / notification channels → select the configured channel and mute it in the settings menu.

Don’t know if this is also possible on iOS. But I know that on iOS I can push a custom sound or no sound with the notification service call. But I have no device to test this here. If you are on iOS just let me know.

@panhans I’m not sure if its mentioned but beyond the breaking changes for duration this requires Home Assistant Core 2024.6 or greater due to the collapsible section features. Just noting for others trying to upgrade. I’m going to give the custom trigger and custom actions a test (I had a custom TTS component in fork but it wasn’t very extensible)

1 Like

after upgrading to 2024.7 I had to log out of the browser and back in to force the update (which changed the behavior of collapsed sections in blueprints)

Yes, had the same issue but reloading with renew the cache did it. (Win: SHIFT+F5) (Mac: cmd+shift+R)

1 Like

Example use case with this blueprint and Custom component (TTS/Alexa)

I did have an issue with the custom component not executing immediately but seemed to execute after the timeout period passed. I created a PR with the working code i’m using. Issue

When any door/window is left open for 5 minutes do the following

  1. Send Notification to Phone
  2. Send message to script to speak on alexa device
    Alexa script uses scenes to capture the current state, set volume to some level, then return to previous state after executing.

Automation YAML

alias: "Door/Window left open Notification "
description: ""
use_blueprint:
  path: panhans/persistent-binary-open-notification.yaml
  input:
    sensor_entity:
      - binary_sensor.alarm_panel_1_zone_7
      - binary_sensor.alarm_panel_1_zone_5
      - binary_sensor.alarm_panel_1_zone_4
      - binary_sensor.alarm_panel_1_zone_6
      - binary_sensor.alarm_panel_1_zone_1
      - binary_sensor.alarm_panel_1_zone_12
      - binary_sensor.alarm_panel_1_zone_8
      - binary_sensor.alarm_panel_1_zone_9
      - binary_sensor.alarm_panel_1_zone_10
      - binary_sensor.alarm_panel_2_zone_6
      - binary_sensor.alarm_panel_1_zone_11
    notify_device: 4ba8cc67d62b8fe0e7975932c497431d
    group: Door-Window-left-open
    active_state: "on"
    title: "{{ entity_name }} {{ state_attr(sensor,'device_class') }} is open"
    message: "{{ entity_name }} {{ state_attr(sensor,'device_class') }} is open"
    ha_notification: true
    notification_color:
      - 255
      - 0
      - 0
    custom_condition:
      - condition: time
        after: "08:00:00"
        before: "23:30:00"
    custom_action_on:
      - service: script.alexa_tts
        data:
          message: >-
            {{ entity_name }} {{ state_attr(sensor,'device_class') }} has been
            left open
    period:
      hours: 0
      minutes: 10
      seconds: 0
    for_time_m:
      hours: 0
      minutes: 5
      seconds: 0

Script Yaml

alias: Alexa TTS
sequence:
  - service: scene.create
    data:
      scene_id: before_alexa_tts
      snapshot_entities:
        - media_player.ecobee_mainfloor
    enabled: true
  - service: media_player.volume_set
    data:
      volume_level: 0.75
    enabled: true
    target:
      device_id: cb9425897ba3ed9541837a62f0d5e5e1
  - service: notify.alexa_media
    data:
      data:
        type: tts
      target: media_player.ecobee_mainfloor
      message: >-
        <audio
        src="soundbank://soundlibrary/sports/golf/golf_07"/><amazon:emotion
        name="disappointed" intensity="high"><amazon:effect name="drc">{{
        message }}</amazon:effect></amazon:emotion>
  - service: scene.turn_on
    data:
      entity_id: scene.before_alexa_tts
    enabled: true
mode: single

2 Likes

Hi panhams,
the periodic bug is still exists.
I updatet the bluprint to version 2.4.0 and created a new automatition.
(HA core is 2024.7.2)

alias: Test2 Fenster offen
description: ""
use_blueprint:
  path: panhans/entity_state_persistent_notification.yaml
  input:
    sensor_entity:
      - input_boolean.test_fenster
    for_time_m:
      hours: 0
      minutes: 2
      seconds: 0
    notify_group: BachiAppsNotity
    title: "{{ entity_name }} ist offen"
    message: >-
      Achtung: {{ entity_name }} ist schon {{ ((now() - [sensor] | expand |
      map(attribute='last_changed') | first).total_seconds() / 60) | int }}
      Minuten lang geöffnet
    stop_button_text: Benachrichtigung deaktivieren
    period:
      hours: 0
      minutes: 2
      seconds: 0
    status_bar_icon: mdi:window-open-variant
    notification_color:
      - 255
      - 255
      - 0
    channel: Fenster/Türen
    group: offene Fenster

Here is my tested situation:
17:14:30 turn sensor on
17:16:31 notification received
17:17:10 turn sensor off
17:17:15 turn sensor on
17:18:31 notification received << this should not happend (from first sensor on?)
17:19:11 notification received << this should not happend (from first sensor off?)
17:19:15 notification received
17:20:00 turn sensor off

If i turn off the sensor after the first mobile notify was received and turn on the sensor in a short time, then i get three periodic notifications on my phone.

17:18:31 and 17:19:11 are both pntc_event.

1 Like

Sry, for that inconvenience. I did some changes to the latest version. My tests look promising. I wait for your feedback. :slight_smile:

Hi panhans,

here is my feedback.
I updatet the blueprint to version 2.4.1.
I testet again my tests.
Sorry, the problem is still exists.
Remember, duration and periodic are 2 minutes in my tests.

14:46:00 turn sensor on
14:48:00 notification received >> correct from 1st on
14:49:10 turn sensor off
14:49:15 turn sensor on again
14:50:01 notification received << this should not happend
14:51:15 notification received >> correct from 2nd on
14:52:01 notification received << this should not happend
14:52:14 turn sensor off

After sensor is switch to 1st OFF and then to 2nd ON, periodic notifications from the 1st ON should not be happened.

Do you need the traces from this test?

Hi panhans,

i found a solution for the periodic problem.
I will send you a pull request on github.

1 Like

Atm I am a little busy but I am looking forward to review your request theses days. Thank you for your effort!!!

After update the blueprint to lasts version I get a problem with my notifications:

Error: UndefinedError: 'dict object' has no attribute 'from_state'

alias: Buzón de correo. Notificar ha llegado correo
description: ""
use_blueprint:
  path: panhans/entity_state_persistent_notification.yaml
  input:
    sensor_entity:
      - binary_sensor.estado_de_buzon_de_correo
    for_time_m: 0
    notify_group: all_mobile_devices
    message: Tienes nuevo correo en el buzón
    title: Tienes correo
    period: 10
    notification_color:
      - 1
      - 102
      - 142
    channel: BuzonCorreo
    group: BuzonCorreo
    status_bar_icon: mdi:mailbox-up

You manually triggered the automation, didn’t you? For testing purpose you have to set the entity to its state you’re aiming for or set the state in the developer options for your entity manually. Simply triggering the automation will result in this error.

Also check the State Duration and the Periodical Notification selectors. The type changes and so they need to get reconfigured.

1 Like

You are right. Sorry for the lack of knowledge! Thank you!

I’m having an issue where there is a significant delay, about 10 minutes in triggering my notifications after the initial trigger.

  active_state: 'on'
  sensor_entity:
    - binary_sensor.refrigerator_sensor_contact
  group_target: all_ios_phones
  ha_notification: true
  notify_device: null
  period:
    hours: 0
    minutes: 0
    seconds: 0
  action_prefix: STOP_{{this.entity_id}}
  notification_color:
    - 100
    - 200
    - 240
  notification_color_hex: >-
    #{{ '%02x%02x%02x' | format(notification_color[0], notification_color[1],
    notification_color[2]) }}
  led_color:
    - 100
    - 200
    - 240
  led_color_hex: '#{{ ''%02x%02x%02x'' | format(led_color[0], led_color[1], led_color[2]) }}'
trigger:
  - platform: state
    entity_id:
      - binary_sensor.refrigerator_sensor_contact
    to: 'on'
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: 'on'
  - platform: state
    entity_id:
      - binary_sensor.refrigerator_sensor_contact
    from: 'on'
    id: 'off'
  - platform: event
    event_type: pntc_event
    id: period
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: template
            value_template: '{{ trigger.id == ''on'' }}'
          - condition: and
            conditions: []
      - condition: template
        value_template: '{{ trigger.id == ''off'' }}'
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              {{ trigger.id == 'period' and trigger.event.data.automation ==
              this.entity_id }}
          - condition: and
            conditions: []
action:
  - variables:
      is_period_trigger: '{{ trigger.id == ''period'' }}'
      sensor: |
        {% if is_period_trigger %}
          {{ trigger.event.data.s_entity }}
        {% else %}
          {{ trigger.from_state.entity_id }}
        {% endif %}
      entity_name: '{{ state_attr(sensor,''friendly_name'') }}'
      tag: '{{ this.entity_id.split(''.'')[1] + sensor.split(''.'')[1] }}'
      action_tag: '{{ action_prefix }}_{{ sensor }}'
      st_last_changed: |
        {% if is_period_trigger %}
          {{ trigger.event.data.st_last_changed }}
        {% else %}
          {{ as_timestamp([sensor] | expand | map(attribute='last_changed') | first) }}
        {% endif %}
  - if:
      - condition: template
        value_template: '{{ is_period_trigger or trigger.to_state.state == active_state }}'
    then:
      - if:
          - condition: template
            value_template: '{{ notify_device != none }}'
        then:
          - if:
              - condition: template
                value_template: '{{ now() != now() + timedelta(**period) }}'
            then:
              - data:
                  title: '{{ entity_name }} is open'
                  message: >-
                    Close the refrigerator door. It’s been open for over 5
                    minutes
                  data:
                    ttl: 0
                    priority: high
                    notification_icon: mdi:home-assistant
                    tag: '{{ tag }}'
                    persistent: true
                    sticky: true
                    channel: General
                    group: refrigeratoropen
                    color: '{{ notification_color_hex }}'
                    vibrationPattern: 100, 100
                    ledColor: '{{led_color_hex}}'
                    actions:
                      - action: '{{ action_tag }}'
                        title: Stop notifying
                action: >-
                  notify.mobile_app_{{ device_attr(notify_device, "name") |
                  slugify }}
            else:
              - data:
                  title: '{{ entity_name }} is open'
                  message: >-
                    Close the refrigerator door. It’s been open for over 5
                    minutes
                  data:
                    ttl: 0
                    priority: high
                    notification_icon: mdi:home-assistant
                    tag: '{{ tag }}'
                    persistent: true
                    sticky: true
                    channel: General
                    group: refrigeratoropen
                    color: '{{ notification_color_hex }}'
                    vibrationPattern: 100, 100
                    ledColor: '{{led_color_hex}}'
                action: >-
                  notify.mobile_app_{{ device_attr(notify_device, "name") |
                  slugify }}
      - if:
          - condition: template
            value_template: '{{ group_target is defined and group_target != '''' }}'
        then:
          - if:
              - condition: template
                value_template: '{{ now() != now() + timedelta(**period) }}'
            then:
              - data:
                  title: '{{ entity_name }} is open'
                  message: >-
                    Close the refrigerator door. It’s been open for over 5
                    minutes
                  data:
                    ttl: 0
                    priority: high
                    notification_icon: mdi:home-assistant
                    tag: '{{ tag }}'
                    persistent: true
                    sticky: true
                    channel: General
                    group: refrigeratoropen
                    color: '{{ notification_color_hex }}'
                    vibrationPattern: 100, 100
                    ledColor: '{{led_color_hex}}'
                    actions:
                      - action: '{{ action_tag }}'
                        title: Stop notifying
                action: notify.{{ group_target }}
            else:
              - data:
                  title: '{{ entity_name }} is open'
                  message: >-
                    Close the refrigerator door. It’s been open for over 5
                    minutes
                  data:
                    ttl: 0
                    priority: high
                    notification_icon: mdi:home-assistant
                    tag: '{{ tag }}'
                    persistent: true
                    sticky: true
                    channel: General
                    group: refrigeratoropen
                    color: '{{ notification_color_hex }}'
                    vibrationPattern: 100, 100
                    ledColor: '{{led_color_hex}}'
                action: notify.{{ group_target }}
      - if:
          - condition: template
            value_template: '{{ ha_notification }}'
        then:
          - data:
              title: '{{ entity_name }} is open'
              message: Close the refrigerator door. It’s been open for over 5 minutes
              notification_id: '{{ tag }}'
            action: persistent_notification.create
    else:
      - data:
          data:
            tag: '{{ tag }}'
            ttl: 0
            priority: high
          message: clear_notification
        action: notify.notify
      - data:
          notification_id: '{{ tag }}'
        action: persistent_notification.dismiss
  - if:
      - condition: template
        value_template: '{{ timedelta(hours=0,minutes=0,seconds=0) != timedelta(**period) }}'
      - condition: template
        value_template: '{{ now() != now() + timedelta(**period) }}'
      - condition: template
        value_template: '{{ trigger.id != ''off'' }}'
    then:
      - wait_for_trigger:
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: '{{ action_tag }}'
        timeout:
          hours: 0
          minutes: 0
          seconds: 0
      - variables:
          s_last_changed: >
            {{ as_timestamp([sensor] | expand | map(attribute='last_changed') |
            first) }}
      - data:
          level: debug
          message: >
            Last Changed {{ s_last_changed }} Last Change Trigger {{
            st_last_changed }}
        action: system_log.write
      - if:
          - condition: template
            value_template: '{{ states(sensor) == active_state }}'
          - condition: template
            value_template: '{{ wait.trigger == none }}'
          - condition: template
            value_template: '{{ st_last_changed == s_last_changed }}'
        then:
          - event: pntc_event
            event_data:
              s_entity: '{{ sensor }}'
              automation: '{{ this.entity_id }}'
              st_last_changed: '{{ s_last_changed }}'
  - if:
      - condition: template
        value_template: '{{ is_period_trigger or trigger.to_state.state == active_state }}'
    then:
      - variables:
          custom_action_on:
            - action: tts.cloud_say
              metadata: {}
              data:
                cache: false
                message: Close the refrigerator door. It’s been open for over 5 minutes
                entity_id: media_player.sonos_first_floor
      - if:
          - condition: template
            value_template: '{{ custom_action_on != none }}'
        then:
          - choose: []
            default:
              - action: tts.cloud_say
                metadata: {}
                data:
                  cache: false
                  message: >-
                    Close the refrigerator door. It’s been open for over 5
                    minutes
                  entity_id: media_player.sonos_first_floor
    else:
      - variables:
          custom_action_off: []
      - if:
          - condition: template
            value_template: '{{ custom_action_off != none }}'
        then:
          - choose: []
            default: []
mode: parallel
id: '1722567758433'
alias: 'Appliance: Refrigerator Door Open'
description: ''

Hey, could you trigger your automation and post a trace log of this run? If you need any help just let me know.

I just tried it today again and it looks like it is working now. Thanks!