I have an automation that makes me mad. It’s very simple. I don’t want the automation executes more than once in a period of 15 seconds. But it does not work. To undestand what is happening, i have written a ‘system_log.write’ with a copy paste of the condition, like this :
- id: '1562516212611'
alias: Llaman al portero
description: Notifica por telegram las llamadas al portero
trigger:
- entity_id: binary_sensor.portero
platform: state
from: 'off'
to: 'on'
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(state_attr("automation.llaman_al_portero", "last_triggered")) |int(20) ) > 15 }}'
action:
- data:
message: "\U0001F4DE Han llamado al portero"
service: notify.telegram_casa
- data_template:
user: !secret user_telegram_sergio
message: Hola_Sergio,_han_llamado_al_portero
service: shell_command.telegram_call
- service: system_log.write
data_template:
level: warning
logger: homeassistant.components.mylogger
message: 'Condition of automation.llaman_al_portero is {{ (as_timestamp(now()) - as_timestamp(state_attr("automation.llaman_al_portero", "last_triggered")) |int(20) ) > 15 }}'
This morning has happened again, the automation executed twice in less than 15 seconds. When i have seen the log, i have found this:
2020-01-31 17:04:58 WARNING (MainThread) [homeassistant.components.mylogger] Condition of automation.llaman_al_portero is True
2020-01-31 17:05:03 WARNING (MainThread) [homeassistant.components.mylogger] Condition of automation.llaman_al_portero is False
The firt log is OK, but the second log tells me that the condition is False. So, why the automation is being executed??
but it is a doorbell. Guessing the ESP one. Just wondering if I can set the automation up at my house and test. I’d be willing to bet it has to do with when last_triggered gets populated. I also suspect that your system_log.write is always off and that it doesn’t truly reflect the condition because last_triggered may be updated by the time it’s reached.
I remember another post by a guy whose daughter stands at the door …
Ring … Ring … Ring … Ring … Ring … Ring …
and as you’re not allowed to beat your child sensless anymore …
It could be off. It really depends on when last_triggered is populated. From what I always understood: It’s populated when actions start. But it’s been a year or so since I examined the code and my memory is not always correct.