Prevent automation to run again if last time it ran because of a specific trigger

I want to have an automation that will sync the completion of tasks between HA shopping list and Habitica (a task manager), but I would like to make sure to prevent any useless loop.

When I complete a task in HA, it should complete it in Habitica, and when I complete a task in Habitica it should complete it in HA. Same thing if for some reason I “uncomplete” some task.

I have an automation that catches the events coming from one, in order to perform the completion in the other.

But let’s say I complete a task in HA shopping list, it will go and complete that task in Habitica. That same automation will then be triggered again and will try to complete that task in HA shopping list.

What is the strategy of choice to prevent such potentially annoying loops to happen?

If it was possible to retrieve which trigger triggered an automation last time, I could filter it out in the automation condition.

Any advice on this, anyone?

Here is an example of the triggers I have, if that may help:

alias: Routine liste mise à jour
description: ""
trigger:
  - alias: tâche routine score up
    platform: event
    event_type: shopping_list_updated
    event_data:
      action: update
      item:
        complete: true
    id: tâche routine score up
  - alias: tâche routine score down
    platform: event
    event_type: shopping_list_updated
    event_data:
      action: update
      item:
        complete: false
    id: tâche routine score down
  - platform: event
    event_type: habitica
    event_data:
      payload:
        type: scored
        direction: up
        task:
          type: daily
    alias: habitica quotidienne score up
    id: habitica quotidienne score up
  - platform: event
    event_type: habitica
    event_data:
      payload:
        type: scored
        direction: down
        task:
          type: daily
    alias: habitica quotidienne score down
    id: habitica quotidienne score down 

A simple way to solve this is to create an input_text helper and just set it to whichever trigger fired off the automation. Then you can check that helper and know which trigger fired last time.

1 Like