Hey Folks,
I have a few “Clickers” for my smart Lamps from IKEA (Tradfri) and managed to get them to work with “zigbee2mqtt” in Home-Assistant… I can use them as a trigger for automations already.
I would like to make a template-sensor or template-automation-trigger (or whatever is best) to check for multiple clicks within 1 Second… to trigger different things when it is clicked twice…
The clicker populates as Binary-Sensor and does briefly show the state “on”, when pressed.
After releasing, the state is blank (null).
It has no persistent “clicked” state. So every click is only seen as a short state change in the sensor.
My first Thought was to make a Template-Sensor which shows (and temporary saves) the amount of clicks within 1 second. (milliseconds would be even better)
An Automation then triggers if the template-value is “1”, and another automation if value is “2”.
This was my first attempt to a template-sensor like this:
platform: template
sensors:
ikea_clicker1_on_count:
friendly_name: Clicker1 Count
value_template: >-
{% set clicks = 0 %}
{% set lastclicktime = 0 %}
{% if is_state_attr('sensor.ikea_clicker_click', 'click', 'on') %}
{% set clicks = 1 %}
{% set currentclicktime=now().seconds %}
{% if currentclicktime > (lastclicktime) %}
{% if currentclicktime < (lastclicktime + 1) %}
{% set clicks = 2 %}
{% else %}
{% set clicks = 1 %}
{% endif %}
{% endif %}
{% set lastclicktime = currentclicktime %}
{% endif %}
{{ clicks }}
I think I need a little help on that… because I hardly doubt that this will work…
Does anyone have better ideas on solving this?
How could you check, if an automation trigger (event) has come twice in a given time?
And would it even be accurate enough to notice two clicks within 1 second or less?
Kind Rergards from Germany!
o/