Template Sensor More Frequent Update

I have a triple gang of Inovelli switches and wanted to do something fun, like trigger a specific thing if the middle switch is double clicked up, double clicked down, then the left switch, and the right switch. Right now I’m just trying to focus on the case of someone double clicks the up, then double clicks the down within 2 seconds. I built a helper input_datetime.deck_switch_double_up and a simple automation to set that helper:

action: input_datetime.set_datetime
metadata: {}
data:
  timestamp: "{{ now().timestamp() }}"
target:
  entity_id: input_datetime.deck_switch_double_up

Then I build another helper binary_sensor.deck_switch_double_up_with_2_seconds that is a template type and the template is: {{ now().timestamp() - as_timestamp(states('input_datetime.deck_switch_double_up')) <= 2 }}

This works, but it’s clearing the binary_sensor at the minute, not within 2 seconds, so it might stay active for 59 seconds. I read that template sensors with now() update once per minute, is there some other solution to get what I want?

You could just create a time based trigger to fire every second and evaluate your template as a condition. However, thats alot of processing overhead just to catch some button presses.

I guess I’m over complicating it by making the template binary_sensor. I could just use this template in an automation, which means it will be evaluated at that point.

You can use a timer to avoid a trigger every second.

Ah, that makes sense. So in my automation for double_up, start a 2 second timer, and in the conditions for double_down, check if that timer is active? That’s more simplistic than what I was doing.

The traditional way of detecting a specific sequence of button events is to use wait_for_trigger with its timeout set for however long you want to wait for the next button event.

The technique is commonly used for remote-control devices to detect specific sequences such as a double-press (detect first press then wait a maximum of 2 seconds for second press). No timer entities are involved.

Assuming this is the z-wave version of Inovelli switch, the first Event Trigger detects the “double-press up” event then the second Event Trigger detects the “double-press down” event (waiting a maximum of 2 seconds before timing out).

I’ve never used the wait_for_trigger, but that makes a lot of sense. I will dive into this. Thanks!

Edit: This might cause a problem if I want to use the double down for something else though. If I trigger a timer, I can check in the double down automation, is the timer idle, do X, if active, do Y

I suggest browsing the Blueprints Exchange section for blueprints designed for your switches. For example:

Not necessarily. It all depends on how you design the automation to detect events.