I usually break these up if they are complicated. And in doing so with your template, i found your issue. You aren’t subtracting the second last_changed from now().
{%- set t = as_timestamp(now()) %}
{%- set sonoff63719 = t - as_timestamp(states.switch.sonoff63719.last_changed) %}
{%- set sonoff51083 = t - as_timestamp(states.switch.sonoff51083.last_changed) %}
{%- if sonoff63719 < 60 and sonoff51083 < 60 %}
Alarm disabled & Garage opened Verified
{%- else %}
Error occurred disarming
{%- endif %}
Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['action'][4]['data_template']['message']. Got None. (See /config/configuration.yaml, line 354). Please check the docs at https://home-assistant.io/components/automation/
Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['action'][2]['data_template']['message']. Got None. (See /config/configuration.yaml, line 354). Please check the docs at https://home-assistant.io/components/automation/
Solved with help from Petro on discord. Here’s what I ended up with:
- id: 'deactivatealarmopengarage'
alias: Deactivate Alarm and Open Garage
trigger:
- entity_id: input_boolean.alarmgaragedoor
from: 'on'
platform: state
to: 'off'
action:
- service: switch.turn_on
data:
entity_id: switch.sonoff63719
- service: switch.turn_on
data:
entity_id: switch.sonoff51083
- delay: "00:00:10"
- service: notify.notify
data_template:
message: >
{%- set t = as_timestamp(now()) %}
{%- set sonoff63719 = t - as_timestamp(states.switch.sonoff63719.last_changed) %}
{%- set sonoff51083 = t - as_timestamp(states.switch.sonoff51083.last_changed) %}
{%- if sonoff63719 < 60 and sonoff51083 < 60 %}
Alarm disabled & Garage opened Verified
{%- else %}
Error occurred disarming
{%- endif %}
- service: persistent_notification.create
data_template:
message: >
{%- set t = as_timestamp(now()) %}
{%- set sonoff63719 = t - as_timestamp(states.switch.sonoff63719.last_changed) %}
{%- set sonoff51083 = t - as_timestamp(states.switch.sonoff51083.last_changed) %}
{%- if sonoff63719 < 60 and sonoff51083 < 60 %}
Alarm disabled & Garage opened Verified
{%- else %}
Error occurred disarming
{%- endif %}
Similar for setting. I was getting conflicting notifications until I put the delay in there FWIW.