- service: notify.persistent_notification
data:
message: >
Window OPEN Bad 30 minutes ago at {{ (now() - timedelta(minutes=30)).strftime('%H:%M') }}
title: Window OPEN Bad
hello @parautenbach ,
the solution of @123 works, so i tried yours, in expectation to reuse the trigger for value for the message?
but all i tried, fails with syntax error by saving the automation or with logging errors… see below…
message: >
Window OPEN Bad ...blabla {{ (now() - timedelta(minutes=trigger.for.seconds // 60).strftime('%H:%M') }}
message: >
Window OPEN Bad ...blabla {{ (now() - timedelta(minutes=trigger.for.seconds // 60)).strftime('%H:%M') }}
message: >
Window OPEN Bad ...blabla {{ timedelta(minutes=trigger.for.seconds // 60).strftime('%H:%M') }}
message: >
Window OPEN Bad ...blabla {{ timedelta(minutes=trigger.for.seconds // 60) }}
message: Window OPEN Wozi {{ timedelta(minutes=trigger.for.seconds // 60) }} minutes ago
2023-03-12 19:03:33.633 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'for' when rendering 'Window OPEN Wozi {{ timedelta(minutes=trigger.for.seconds // 60) }} minutes ago'
2023-03-12 19:03:33.635 ERROR (MainThread) [homeassistant.components.automation.notify_window_open_wozi] Notify_Window_OPEN_Wozi: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'for'
2023-03-12 19:03:33.640 ERROR (MainThread) [homeassistant.components.automation.notify_window_open_wozi] Error while executing automation automation.notify_window_open_wozi: Error rendering data template: UndefinedError: 'dict object' has no attribute 'for'
The Run command only executes an automation’s actions and it cannot be used for testing the actions if they refer to the trigger variable or any other variables that may be defined by triggers.
That’s why you got an error when you used the Run command to test an automation containing trigger.for.seconds.
To test the automation, leave the window open for 30 minutes. To accelerate the test, temporarily change the value from 30 to 1 (so you don’t have to wait so long).
hi @123 thanx, i´m so stupid, i had tried , just before your last post the same way as you described, but i had the wrong sensor in automation for testing
after a couple of tries with wrong syntaxes and brackets now it works as i expected!
service: notify.persistent_notification
data:
message: >-
Window OPEN Wozi since {{ ((now() - timedelta(minutes=(trigger.for.seconds //
60))).strftime('%H:%M')) }}
title: Window OPEN Wozi
Please be advised that you marked your own post as the Solution but that’s not the custom of this community forum (unless you actually thought of how to solve the problem). In this case, you were provided with information.
The custom is to mark the first post that provides the correct answer to the original question. Only one post in the entire topic can have the Solution tag. It helps other users find answers to similar questions.