Hello,
I want to adjust the interval update of my HC-SR04 ultrasonic sensor as soon as my garage door opens.
My two limit switches should serve as triggers.
As soon as both have the status “on” the update interval should be 125ms, otherwise only 60s.
I created the following script in ESPHome.
However, the “update_interval_slow” always remains active.
I would be very happy to receive suggestions and help
substitutions:
update_interval_fast: 125ms
update_interval_slow: 60s
sensor:
- platform: ultrasonic
id: distance_sensor
trigger_pin: GPIO5
echo_pin: GPIO4
name: "Ultrasonic_Sensor"
update_interval: ${update_interval_slow}
internal: true
timeout: 2.5m
accuracy_decimals: 2
unit_of_measurement: 'm'
# filters:
filters:
- lambda: return x;
- filter_out: nan
- median:
window_size: 5
send_every: 5
send_first_at: 1
- calibrate_linear:
- 0.0 -> 2.0
- 2.0 -> 0.0
# zeigt im Dashboard den Status des Garagentor Öffnungsgrads in %
- platform: template
id: level
name: Status_Garagentor
update_interval: ${update_interval_slow}
unit_of_measurement: '%'
lambda: |-
auto r = (id(distance_sensor).state) * 50 ;
if (r > 99) return 100;
if (r < 0.3) return 0;
return r;
binary_sensor:
- platform: homeassistant
name: "Tor auf"
id: sensor_oben
entity_id: input_sensor.garagentor_sensor_auf_window
internal: true
- platform: homeassistant
name: "Tor ZU"
id: sensor_unten
entity_id: input_sensor.shelly_garage_magnetschalter_switch_100_input
internal: true
interval:
- interval: ${update_interval_fast}
then:
- if:
condition:
- lambda: 'return id(sensor_oben).state;'
- lambda: 'return id(sensor_unten).state;'
then:
- component.update: distance_sensor
- component.update: level