I have two sensors (ToF VL53L0X) and I’m incrementing a counter based on which sensor triggers first, and then waiting to see if the second one triggers within a short time period. Is this the best way to do this, or is there a better way using lambda? Thank you!
binary_sensor:
- platform: template
name: "Breakbeam Sensor"
id: breakbeam_sensor
device_class: motion
publish_initial_state: True
on_state:
- if:
condition:
- lambda: return (id(breakbeam_sensor).state == true && id(breakbeam_sensor2).state == false);
then:
- wait_until:
condition:
- lambda: return id(breakbeam_sensor2).state == true;
timeout: 1s
- if:
condition:
- lambda: return id(breakbeam_sensor2).state == true;
then:
- number.decrement:
id: people_counter
cycle: false
- platform: template
name: "Breakbeam Sensor2"
id: breakbeam_sensor2
device_class: motion
publish_initial_state: True
on_state:
- if:
condition:
- lambda: return (id(breakbeam_sensor2).state == true && id(breakbeam_sensor).state == false);
then:
- wait_until:
condition:
- lambda: return id(breakbeam_sensor).state == true;
timeout: 1s
- if:
condition:
- lambda: return id(breakbeam_sensor).state == true;
then:
- number.increment:
id: people_counter
cycle: false