Action not launched if last_notification has the same text

I am using a Samsung Smart tag to open my garage door. The tag sends a notification to the phone with the message “Open Sesame” and I get this with sensor.phone_last_notification.

First time when the notification is received everything works fine, but next time automation is not launched. If I change the text of the notification (sent by the smart tag and checked by the automation) than it works again but only the first time.

Is there a way to do some kind of “reset” state for last notification or any other way to solve this issue?

My code is this one.

alias: Open garage
description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.sm_s918b
      - sensor.sm_s918b_last_notification
    to: Open Sesame
condition: []
action:
  - service: shell_command.open_garage
    metadata: {}
    data: {}
mode: single

I checked the sensor last_notification state and this is not updated if the text of the notification received is the same. Is this the normal behavior or a bug?

I even tried to send another notification to “reset” the last one text. This second notification (with the text “Reset”) is received by the phone but is not received by the last_notification sensor. (“Disable allow list” is enabled for last_notification sensor). So, no fix yet.

  alias: Open garage
  description: ''
  trigger:
  - platform: state
    entity_id:
    - device_tracker.sm_s918b
    - sensor.sm_s918b_last_notification
    to: Open Sesame
  condition: []
  action:
  - service: shell_command.open_garage
    metadata: {}
    data: {}
  - service: notify.mobile_app_sm_s918b
    data:
      message: Reset
  mode: single

A trigger set to act on state will only trigger when the entity is changing its state to the value you specify.
If the value stays the same, then the sensor is not updated and no triggering will happen.

You might be able to use other trigger methods, like event maybe.
Or you could make a “reply” to your " Open Sesame", like “Yes master” or whatever. This would change the state and prepare it for another run.

You need to check the sensor in the State tool to see if other attributes or the last_updated property change with repeated scans. If there is any update you can use an open state trigger and add a condition to check the state.

  alias: Open garage
  description: ''
  trigger:
    - platform: state
      entity_id:
      - device_tracker.sm_s918b
      - sensor.sm_s918b_last_notification
  condition:
    - condition: template
      value_template: "{{ trigger.to_state.state is search('Open Sesame') }}"
  action:
    - service: shell_command.open_garage
      metadata: {}
      data: {}
  mode: single

@WallyR: Yes, I tried with a reply (please check above the notification with the text “Reset”) but this is not received by last_notification which remains unchanged like nothing happened.

I don’t know how to use the “event” for such a situation… since the problem is that last_notification is not modified.

I guess that one would be fired right after the first one.
It might be too close, so try to put in a few seconds of delay.

I tried with a delay (5 seconds). No joy.

  alias: Open garage
  description: ''
  trigger:
  - platform: state
    entity_id:
    - device_tracker.sm_s918b
    - sensor.sm_s918b_last_notification
    to: Open Sesame one
  condition: []
  action:
  - delay:
      seconds: '5'
  - service: notify.mobile_app_sm_s918b
    data:
      message: Reset
  mode: single

I checked on the use of another trigger (event). The description of the 'Notification received" states that:

“You can receive an event when a notification is received on the device. In order to receive this event you will need to set confirmation: true as a parameter in your notification service call. All notification data will be present in the event data for the event type mobile_app_notification_received . If you do not set this parameter then no event will be sent from the device when the notification is received.”

As far as I understand the parameter ‘confirmation’ must be ‘true’ when the notification is sent otherwise the notification will not fire an event. I use Samsung Smart tag to send the notification (when clicked) and there is no way that I can change the parameters of the notification sent.

HA captures all kinds of events and this might enable you to catch an event that will not trigger a change in a sensor, so if you open up the HA Developer Tools and click on the Events tab, then you can click the listeners in the right side and click on Start Listening.
If you choose * then you will get all events coming to the HA bus and it might be a lot, so start listening and then activate the event somewhat quickly and stop the listening again.
Some actions might fire multiple events, like a button, that might have a button_press, then a button_hold and later a button_release, so look through some extra events when you find the first one related to your project.

Edit I can see the clicking of the Listeners in the right side does not work correctly, so write or copy the blue text into the field for Listen To Events to start the listening.

Great! It’s moving! :slight_smile: I can see the events with the Listener. Thank you!

I will continue from here and see what can I catch to do the job…

Good and good luck :slight_smile:

I got this working. :slight_smile: Thank you WallyR for your suppport. Now the action will be triggered on every notification even if the text of the notification is not changed. I will leave the final code here maybe somebody else encountered the same problem.

  alias: Open garage
  description: ''
  trigger:
    - platform: event 
      event_type: state_changed
      event_data:
        entity_id: sensor.sm_s918b_last_notification
  condition:
    - condition: template
      value_template: "{{ trigger.event.data.new_state.state == 'Open Sesame' }}"
  action:
  - service: shell_command.open_garage
    metadata: {}
    data: {}
  mode: single