Hi, is it possible to expand this template code so that the status change is executed only if the value is below or above the defined voltage for a specific time (f.e. 30 secondes)?
ok.
But I could make a sceond sensor and update that one with an automation, where I use a condition that the state is only changed if the changed state of the first template sensor is for a specific time
I don’t want to store voltage value, I wan’t a “state-machine” who changes the state depending on the voltage value, but only if the voltage value is over the level for a specific time.
the states are:
very heavy (rain)
heavy
moderate
light
drip/dropping
dry
To meet your requirement of maintaining a voltage value for 30 seconds before triggering, you could try this (untested) automation:
- alias: test example
trigger:
- platform: state
entity_id: sensor.esp_regensensor_analog
for : '00:00:30'
action:
- service: input_select.select_option
data:
entity: input_select.rain_sensor
option: >
{% set v = trigger.to_state.state | float %}
{% if v < 1.7 %} sehr stark
{% elif v < 2.2 %} stark
{% elif v < 2.6 %} mässig
{% elif v < 2.9 %} leicht
{% elif v < 3.1 %} tröpfeln
{% else %} trocken
{% endif %}
FWIW, it isn’t entirely necessary to use an input_select and an input_text would work as well.