Hi. I’m building a parking aid for my garage which consists of a nodemcuv2, hc-sr04 ultrasonic sensor, and a strip of ws2812b LEDs.
I’ve managed to get it working but I have 2 remaining issues.
I currently have a lambda which contains multiple “if” statements to trigger the led strip to light up different colors depending on the ultrasonic reading. However, I only want this block of code to be triggered if the garage door is open. In other words nothing should happen if the garage door is closed. I believe the best way to accomplish this would be nested if statements but I’m having a hard time trying to figure out the proper way to code it. I’m beginning to question if this is even the best way to handle this task altogether. The garage door sensor is a Smartthings multipurpose sensor and is a binary “opening” type sensor that appears to be “off” when closed and “on” when open. My code compiles just fine but it doesn’t seem to respond to the garage door opening or closing.
The 2nd issue I’m having is with the strobe effect. Whenever I try implementing the effect the LED strip gets stuck on flashing red at all distance levels. I kept the effect info at the bottom of my code but removed the command to call it due to the issues. Does the effect code look fine?
Thanks
binary_sensor:
- platform: status
name: "Car Sensor 1 Status"
- platform: homeassistant
entity_id: binary_sensor.sheree_garage_door_sensor_contact
id: doorsensor1
- platform: template
name: "Vehicle1"
device_class: presence
lambda: |-
if ((id(car_sensor1).state < 1.2)){
// vehichle is in the garage
return true;
} else {
//no vehicle
return false;
}
sensor:
- platform: ultrasonic
id: car_sensor1
trigger_pin: D4
echo_pin: D3
update_interval: 0.5s
timeout: 4.0m
accuracy_decimals: 1
name: "Car Sensor 1"
filters:
filter_out: nan
on_value:
then:
- if:
condition:
binary_sensor.is_off: doorsensor1
then:
- lambda: |-
if ((id(car_sensor1).state >= 4.0)) {
id(parkingled1).turn_off();
}
else if ((id(car_sensor1).state >= 1.7) & (id(car_sensor1).state < 4.0)) {
auto call = id(parkingled1).turn_on();
call.set_rgb(0,1.0,0);
call.perform();
}
else if ((id(car_sensor1).state >= 1.0) & (id(car_sensor1).state < 1.7)) {
auto call = id(parkingled1).turn_on();
call.set_rgb(1.0,0.75,0);
call.perform();
}
else if ((id(car_sensor1).state >= 0.7) & (id(car_sensor1).state < 1.0)) {
auto call = id(parkingled1).turn_on();
call.set_rgb(0,0,1.0);
call.perform();
}
else if ((id(car_sensor1).state < 0.7)) {
auto call = id(parkingled1).turn_on();
call.set_rgb(1.0,0,0);
call.perform();
}
- platform: wifi_signal
name: "Garage Vehicle Sensor 1 WiFi"
update_interval: 60s
light:
- platform: fastled_clockless
chipset: WS2812B
pin: GPIO12
num_leds: 8
rgb_order: GRB
name: "Car Sensor 1 LED"
restore_mode: ALWAYS OFF
default_transition_length: 0s
id: parkingled1
effects:
- strobe:
- strobe:
name: Red Strobe
colors:
- state: True
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 100ms
- state: False
duration: 100ms