Hello,
I come from iobroker, am still new to HA and am currently playing around with the automations.
For no particular reason, I have added a window contact to our pets’ running wheel to measure the revolutions (let’s see how sporty the little ones are).
Unfortunately, the measurement doesn’t yet work the way I want it to.
I have built the following automation:
alias: Degus_Laufrad_RPM
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.kontakt_degu_laufrad_contact
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- service: input_text.set_value
target:
entity_id: input_text.degus_laufrad_timediff
data:
value: "{{ trigger.to_state.last_changed - trigger.from_state.last_changed }}"
- alias: Kontakt entprellen
delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 250
mode: single
This automation should save the time difference of a revolution in seconds in a helper.
This helper is then used to calculate the RPM using a template:
- sensor:
- name: Degus_Laufrad_RPM
unique_id: "degus_laufrad_rpm"
unit_of_measurement: "rpm"
device_class: "speed"
state: >-
{% if is_state("input_text.degus_laufrad_timediff", "0") -%}
{{"0"}}
{%- else -%}
{{ (60 / as_timedelta(states('input_text.degus_laufrad_timediff')).total_seconds()) | round(0) }}
{%- endif %}
A further automation sets the value back to 0 after 10s of standstill.
This works fine, but unfortunately I get the wrong times saved in the first helper for the time difference, which is then used to calculate the wrong RPM.
This is most likely caused by bouncing of the window contact.
The little animals are definitely not that fast.
That’s why I’ve already built a debounce time of 250ms into the automation.
(tested it also with 1s - makes no difference. Nevertheless, very short times are saved again and again)
As I understand it, the automation should never trigger for less than 250ms, so the value in the helper should never be less than 0.25s.
This is not the case.
Why? What am I doing wrong?
Are the little ones too fast for HA?
With iobroker it actually worked quite well and plausibly, despite the fact that it is a Zigbee-Aqara contact