- alias: Motion Detected Notification
trigger:
- entity_id: binary_sensor.carport_motion
platform: state
to: 'on'
condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.motion_detected_notification.attributes.last_triggered) | int > 1800 }}'
action:
- service: notify.pushbullet
data:
message: 'Motion Detected in front of Carport {{now().strftime("%H:%M:%S on %m/%d/%y")}}'
I get Error
Error loading /config/configuration.yaml: mapping values are not allowed here
in â/config/Automation/Motion Sensors.yamlâ, line 37, column 19
I am somwhat new to this and not sure what I am doing wrong, from everything I can find, it seems to be right.
Another question based on my question. Do I have it correct, for what I am wanting it to do?
I want the automation to run when motion is detected then notify me, but if motion is detected within a certain time, like this example 30 minutes it will not notify me. Only notify me again after the time frame elapsed.
I assume the 1800 is in seconds.
Tested it in the template editor and I believe it to be working, however, if I trigger it manually twice within a 1 minute I get the notification twice.
I honestly donât know about that. I donât know if the manual trigger ignores the conditions or not. But if I would guess I would be surprised if it ignored them. But Iâve been surprised before.
Manually triggering an automation effectively bypasses its triggers and conditions and just unconditionally runs its actions. Thatâs why youâre seeing that.
The condition youâre using is basically ok. In fact, I do something very similar in one of my automations (which also involves motion detection.) However, before the first time an automation is triggered its last_triggered attribute will be None, which will cause an error in the template as youâve written it. This is what Iâd suggest (based on what works for me):
condition:
condition: template
value_template: >
{% set last_triggered = as_timestamp(
state_attr('automation.motion_detected_notification', 'last_triggered')) %}
{{ last_triggered is none or (as_timestamp(now()) - last_triggered) > 30*60 }}