Fighting with using a template for a trigger “states is equal to XXX for YYY minutes”.
Here is a working automation:
- alias: test0
description: ''
trigger:
- platform: state
entity_id: input_boolean.test_boolean
to: 'off'
for:
minutes: '{{states(''input_number.wait_period_before_alarm'') | int}}'
condition: []
action:
- service: notify.telegram_chat_XXXXXXX
data:
message: OFF for {{states('input_number.wait_period_before_alarm')|int}} minutes
mode: single
It triggers if:
-
"input_boolean.test_boolean"
changed to OFF - after period of time specified by
"input_number.wait_period_before_alarm"
.
The output (message in Telegram) is:
OFF for 3 minutes
Now I am trying to create a blueprint:
blueprint:
name: "common: Entity - problem or OK (long period)"
description: ''
domain: automation
input:
input_ENTITY_NAME:
name: "Entity's name"
input_ENTITY_STATUS:
name: "Entity's sensor"
input_LONG_PERIOD:
name: "Long period"
selector:
entity:
domain: input_number
variables:
ENTITY_NAME: !input input_ENTITY_NAME
LONG_PERIOD: !input input_LONG_PERIOD
LONG_PERIOD_VALUE: "{{ states(LONG_PERIOD) | int }}"
trigger:
- platform: state
entity_id: !input input_ENTITY_STATUS
to: 'off'
for:
hours: 0
minutes: "{{ 3 | int }}" #just for testing
seconds: 0
action:
- service: notify.telegram_chat_XXXXXXXXXX
data:
message: "{{ENTITY_NAME}}: OFF for {{LONG_PERIOD_VALUE}} minutes"
mode: single
Here is an automation:
- alias: testXXX
description: ''
use_blueprint:
path: common_entity_problem_long.yaml
input:
input_ENTITY_NAME: FLAG
input_ENTITY_STATUS: input_boolean.test_boolean
input_LONG_PERIOD: input_number.wait_period_before_alarm
The automation works, here is an output:
FLAG: OFF for 3 minutes
Note that the blueprint has a “hardcoded” value “3” for the period.
But none of these variants does not work:
for:
minutes: "{{ LONG_PERIOD_VALUE }}"
minutes: "{{ states(LONG_PERIOD) | int }}"
minutes: "{{ states(!input input_LONG_PERIOD) | int }}"
These variants work:
for:
minutes: "{{ 3 | int }}"
minutes: "{{ states('input_number.wait_period_before_alarm') | int }}"
Why at least 2 first variants do not work?