when creating an automation, is it possible to compare an entity to an input number instead of a fixed value?
what i want to do is keep track of the closest lightning strikes from blitzortung to set an alert level, but how do i compare the current distance to the previous minimum?
yes, i know i have to reset after some time, but i think i can get that part sorted.
trigger:
- platform: numeric_state
entity_id: sensor.blitzortung_lightning_distance
below: input_number.minimum_lightning_distance
action:
- service: input_number.set_value # set the new minimum
target:
entity_id: input_number.minimum_lightning_distance
data:
value: "{{ trigger.to_state.state |float(100) }}"
- # your alert or whatever here
To reset it you have a number of options, probably the best would be triggering on the input_number not changing for an hour or more.
trigger:
platform: state # triggers on changing to any state for 1 hour
entity_id: input_number.minimum_lightning_distance
to:
for:
hours: 1
action:
- service: input_number.set_value
target:
entity_id: input_number.minimum_lightning_distance
data:
value: 100
The trouble with using a statistics sensor is that there is no way to set a default if there are no lightning strikes for your sample time, and no way to reset it back to a large value.
it doesn’t work all that well. the minimun distance is set but when lightning further away is detected, the value i get back is reset to a higher number, sometimes after a few seconds instead of 15 min.
unfortunately that doesn’t work either. the automation doesn’t get triggered, and i can’t find out why. and that crappy new UI in 2022.9 isn’t exactly making it easier
Thinking aloud… if you can turn the template into a device-tracker, you could use the proximity option and even see if it is getting closer, or travels away
And proximity’s state is the distance from the zone, which you can monitor in the history graph.