TL;DR: I have an automation I’d like to trigger at a specific value of a history_stats
sensor. The precision seems to be 0.01, but if I use constraints like (above=0.99, below=1.01
), sometimes the automation triggers twice in that interval.
Details:
I have a history_stats
sensor set up to track how long a binary_sensor
has been on today.
I’d like to trigger an automation at each incremental hour the binary_sensor
has been on for a given day. e.g. on for one hour; on for two hours, on for 3 hours, etc.
I’ve tried the following:
- id: HourlyUsageAutomation
trigger:
- platform: state
entity_id: sensor.history_stats_example
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.history_stats_example
above: '0.99'
below: '1.01'
- condition: numeric_state
entity_id: sensor.history_stats_example
above: '1.99'
below: '2.01'
- condition: numeric_state
entity_id: sensor.history_stats_example
above: '2.99'
below: '3.01'
action:
- service: [do stuff]
The problem I’m seeing is that sometimes the automation triggers once on the hour (as expected) and sometimes it triggers twice on a given hour.
When I read the sensor value, the precision seems to be to two decimal places (0.01), so I’d think the above should work.
I’ve tried something like:
- condition: numeric_state
entity_id: sensor.history_stats_example
above: '0.99'
below: '1.00'
but that doesn’t end up triggering at all.
Anyone have something like this working correctly?