Automation template trigger ever firing

I’ve an automation:

alias: test2
description: ""
triggers:
  - trigger: template
    value_template: >-
      {{state_attr('climate.trv', 'current_temperature') <
      state_attr('climate.trv', 'temperature')}}
conditions: []
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: heat on
mode: single

The problem is that the notification is create even when the template value is false.
What I’m doing wrong? Thanks

Can you share the automation trace for one of these occurrences?

The template value is “false” but the notification is fired.

{
  "trace": {
    "last_step": "action/0",
    "run_id": "542ff884bedad516748948d4dbb6a220",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-10-14T07:10:01.616830+00:00",
      "finish": "2024-10-14T07:10:01.625945+00:00"
    },
    "domain": "automation",
    "item_id": "1728856272802",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2024-10-14T07:10:01.618305+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.prova2",
              "state": "on",
              "attributes": {
                "id": "1728856272802",
                "last_triggered": "2024-10-13T22:03:07.274784+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "test2"
              },
              "last_changed": "2024-10-13T22:11:51.669588+00:00",
              "last_reported": "2024-10-13T22:11:51.669588+00:00",
              "last_updated": "2024-10-13T22:11:51.669588+00:00",
              "context": {
                "id": "01JA3Z05QNCYVE5KR4DQ3M5N4F",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-10-14T07:10:01.624246+00:00",
          "changed_variables": {
            "context": {
              "id": "01JA4XSJWGMJSTXBN8DGWT4Z3C",
              "parent_id": "01JA4XSJWBS9WQ0VDH8BD7EGPF",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "persistent_notification",
              "service": "create",
              "service_data": {
                "message": "accendi"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1728856272802",
      "alias": "prova2",
      "description": "",
      "triggers": [
        {
          "trigger": "template",
          "value_template": "{{state_attr('climate.trv', 'current_temperature') > state_attr('climate.trv', 'temperature')}}"
        }
      ],
      "conditions": [],
      "actions": [
        {
          "action": "persistent_notification.create",
          "metadata": {},
          "data": {
            "message": "heat on"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01JA4XSJWGMJSTXBN8DGWT4Z3C",
      "parent_id": "01JA4XSJWBS9WQ0VDH8BD7EGPF",
      "user_id": null
    }
  },
  "logbookEntries": []
}

It wasn’t the template that triggered your automation. It was triggered manually or by some other automation or script using action: automation.trigger

I created this automation:

- id: 09b1ca94-430f-4e9a-a301-1948fa869382
  alias: 'Trigger test'
  triggers:
  - trigger: template
    value_template: "{{ is_state('input_boolean.test','on') }}"
  actions:
  - action: notify.telegram_system_log
    data:
      title: "⚠️<b>Test Trigger</b>"
      message: "Test trigger fired at UTC: {{ utcnow() }}"

When turning on the test input boolean I get this trace:

             "trigger": {
              "platform": "template",
              "entity_id": "input_boolean.test",
              "from_state": {
                "entity_id": "input_boolean.test",
                "state": "off",
                "attributes": {
                  "editable": false,
                  "icon": "mdi:test-tube",
                  "friendly_name": "Test"
                },
..etc

When triggering it manually I get:

   "trigger": null,

Thank you!
So the whole automation concept is broken! Incredible…
What is for the run command if it’s useless???

Hang on. Are you running this automation manually expecting to test if the trigger stops the automation?

A) That’s not what triggers do. That’s what conditions do.

B) Manually triggering an automation skips the triggers and conditions and test the actions. You can get it to test conditions and actions by using Developer Tools → Services. But you cant test triggers by manually triggering an automation.

No, just your understanding of it. It works fine for me.

It’s not useless, but it does have documented limitations.

As Petro Tom (Monday morning brain fade) says, a better configuration would be to trigger off changes to climate.trv, and have the template in a condition. Then the Run button would test your notification, and you can test the condition via the UI like this.

Ahem. :face_with_raised_eyebrow:

1 Like

you could take it one step beyond that, and add the conditions under the action block. That way triggering a manual trigger would also test the conditions.

And it sets the last_triggered, which can be very useful.

And the template needs float

    value_template: >-
      {{state_attr('climate.trv', 'current_temperature') | float <
      state_attr('climate.trv', 'temperature') | float }}

Don’t like that strategy: the condition block is there for a reason. Too much logic in the action block gets messy. You could trigger off any state change and do it all in the action block, but that doesn’t mean you should.

Not this time: attributes can be (and are, in this case) numbers.

1 Like

That’s why I said ‘could’ and not ‘should’ :wink:

1 Like

Yeah petro

1 Like

That’ll teach me to read multiple topics at once after only one coffee.

lol, I don’t think I’ve replied to anyone this morning. Just lurking. I need more coffee myself

1 Like