Dear all, I am building an esphome-driven chicken door and have the following problem:
Apart from manual operation, the door’s opening or closing will be driven by the amount of daylight measured. The following code works without problems.
However, this might be a bit jumpy when the light scenario changes quickly (clouds moving in front of sun late at day), so you want the condition to be true for, say, at least 15 min.
There seems to be the FOR condition where you can achieve this, but I cannot get the syntax (and the logic) right in the context of on_value_range.
Something like:
on_value_range:
- below: 300
then:
if:
condition:
sensor.in_range:
id: lux_sensor_huhn
below: 300
for:
time: 90s # short just for testing
then:
cover.close: chicken_door
Is there a simpler way to achieve my goal? Any help appreciated
Could you please give me an example? I was trying to “debounce” temporary, sudden spikes of power, so the intended light does not come on and off constantly. The relevant snippet is as follows:
sensor:
- platform: hlw8012
<<: !include common/devices/plugs/moesrgb/hlw8012_base.yaml
power:
name: $friendly_name power
unit_of_measurement: W
id: power
on_value_range:
- below: 7.5
then:
- if:
condition:
- for:
time: 2s
condition:
sensor.in_range:
id: power
below: 7.5
- light.is_on: rgb_light
then:
light.turn_off: rgb_light
This means that I’m trying to turn off the light only as long the power is under 7.5W for a total duration of 2 seconds (not immediately). But as stated above this does not work with on_value_range in combination with for: and sensor.in_range.
Edit: I’m just looking at delayed_on and indeed seems promising…
Ok, I see where that’s going and thank you. Just to be clear the on_press trigger for a template binary sensor is fired when the sensor is true and the on_release when it’s false? The documentation for this kind of sensor is minimum.
I feel that ESPHome’s documentation with regard to automations/conditions/triggers is a little bit lacking, at least in relation to HA’s one.