Reset attribute value of entity in event handler
-
Hi all,
I have successfully created an event handler for the interactive notifications of HA, see: https://smarthome.community/post/15414
However, I'm not able to reset the value that the event has set.
This is my event handler:
event_targets: interactive_notification_responses: name: "Handle notification responses" capabilities: - string_sensor events: - event: event_type: mobile_app_notification_action data: action: "LAUNDRY_INSIDE" response: "string_sensor.value": expr: "event.data.action"
I have only 1 button in the notification, so the value is the same every time.
Because of this my rule does not trigger a second time, because the value is the same.
My solution was to use an entity action and do a set_attribute to reset the value of the entity. But this does not seem to work.
Shouldn't this be working? And maybe there is a smarter way?
-
Additional question:
- The entity value is not changing, because the value doesn't change, right? Or is the event not even triggered? (I don't see the entity flashing in the entities section, when I try to trigger the event)
- Can I add attribute metadata to the rule trigger to see if there was an update?
-
There are other capabilities that are more useful for things like this. You could use either
button
orscene_activation
, for example, both of which provide a timestamp attribute that your event can modify:event_targets: interactive_notification_responses: name: "Handle notification responses" capabilities: - scene_activation events: - event: event_type: mobile_app_notification_action data: action: "LAUNDRY_INSIDE" response: "scene_activation.scene_id": expr: "event.data.action" "scene_activation.since": expr: "time()"
The entity value is not changing, because the value doesn't change, right? Or is the event not even triggered? (I don't see the entity flashing in the entities section, when I try to trigger the event)
That's right. Adding a check to see if
since
changes will address this.Can I add attribute metadata to the rule trigger to see if there was an update?
You could do that as well, but it's more complicated because right now, the metadata is only accessible in expressions, so you'd need to make a local variable in your rule to grab that metadata.
-
There are other capabilities that are more useful for things like this. You could use either
button
orscene_activation
, for example, both of which provide a timestamp attribute that your event can modify:event_targets: interactive_notification_responses: name: "Handle notification responses" capabilities: - scene_activation events: - event: event_type: mobile_app_notification_action data: action: "LAUNDRY_INSIDE" response: "scene_activation.scene_id": expr: "event.data.action" "scene_activation.since": expr: "time()"
The entity value is not changing, because the value doesn't change, right? Or is the event not even triggered? (I don't see the entity flashing in the entities section, when I try to trigger the event)
That's right. Adding a check to see if
since
changes will address this.Can I add attribute metadata to the rule trigger to see if there was an update?
You could do that as well, but it's more complicated because right now, the metadata is only accessible in expressions, so you'd need to make a local variable in your rule to grab that metadata.
@toggledbits Thanks, this is great. I will try it out!