Hi everyone,
I would like to inhibit the following automation to start if it already started in the last 10 seconds or something like that. How could I achieve this? In home assistant I can simply inhibit the automation to run multiple times, but in ESPHome can i do something similar?
Thank you!
binary_sensor:
- platform: gpio
pin:
number: 16
name: "Intercom ringing"
id: intercom_ringing
on_press:
if:
condition:
api.connected:
then:
- logger.log: API is connected!
else:
- switch.turn_on: intercom_1
- delay: 500ms
- switch.turn_off: intercom_1
- delay: 1s
- switch.turn_on: intercom_2
- delay: 500ms
- switch.turn_off: intercom_2
- logger.log: Opened the door because intercom rang while offline.
Many thanks!
Wouldn’t you know a way also to trigger the script only if the sensor is activated - let’s say - three times within 60 seconds?
I came up with something like this but obviously it doesn’t work… maybe adding a sensor that counts…
binary_sensor:
- platform: gpio
pin:
number: 16
name: "Intercom ringing"
id: intercom_ringing
on_press:
then:
- lambda: |-
static int ring_count = 0;
static uint32_t last_activation = 0;
if (last_activation == 0 || xTaskGetTickCount() - last_activation > 60000) {
ring_count = 0;
}
last_activation = xTaskGetTickCount();
ring_count++;
if (ring_count >= 3) {
id(intercom_script).execute();
}
script:
- id: intercom_script
mode: single
then:
if:
condition:
api.connected:
then:
- logger.log: API is connected!
else:
- switch.turn_on: intercom_1
- delay: 500ms
- switch.turn_off: intercom_1
- delay: 1s
- switch.turn_on: intercom_2
- delay: 500ms
- switch.turn_off: intercom_2
- logger.log: Opened the door because intercom rang while offline.