Hi
My summer project that I have wired up and got going is a Ultrasonic car parking aid with led light feedback. I starting as a building block Drzzs code found here
I then found this post:
Garage parking aid to park in exact spot
And the original question had the same issue as I have found.
Everything works properly, but the led lights remain on all the time (on green) after I park the car. My objective is to turn off the led light 20 seconds after the car is parked. Any suggestions?
The solution he came up with was to create an HA automation which you can see at the end of his thread.
mode: restart
trigger:
- platform: state
entity_id: sensor.parking_distance_from_optimal
condition:
- condition: template
value_template: "{{ (trigger.to_state.state | float(0) - trigger.from_state.state | float(0)) | abs > 0.2 }}"
- condition: state
entity_id: cover.garage_door_bay
state: "open"
action:
- service: light.turn_on
entity_id: light.parking_light
data:
brightness: 100
color_name: >-
{% set distance = states('sensor.parking_bay_distance_from_optimal') | float(0) %}
{% if distance > 3 %} blue
{% elif 1.6 < distance <= 1.7 %} yellow
{% elif 1.5 < distance <= 1.6 %} green
{% elif 1.4 < distance <= 1.5 %} orange
{% elif distance <= 1.4 %} red
{% else %} aqua
{% endif %}
- delay: 00:00:30
- service: light.turn_off
entity_id: light.parking_light
I would like to get this all into esphome, an esphome guru said to me on discord…
Basically, create a restarting script that does a delay then turns off the light trigger it when a car is there and moving (save and compare the previous ultrasonic value)
But, I am more of a follow in other peoples footsteps guy and at 55 years old I can blunder my way though, but it will take me weeks to figure this out.
Can anyone help me with how to make these scripts in esphome please?
Here is my code (i have commented out a lot of the light change section as the light just remains on):
binary_sensor:
- platform: template
name: "Prado"
device_class: presence
lambda: |-
if (id(distance).state < 1.5) {
// car is in the garage
return true;
} else {
// no car
return false;
}
- platform: homeassistant
entity_id: binary_sensor.garage_door_contact_sensor
id: doorsensor2
sensor:
- platform: ultrasonic
trigger_pin: GPIO12
echo_pin: GPIO14
name: $device_name Distance
id: distance
pulse_time: 20us
timeout: 3.0m
update_interval: 0.25s
# update_interval: $distance_update_interval
# unit_of_measurement: cm
# pulse_time: $distance_pulse_time
# timeout: 3m
filters:
# Sets the value to the max if the sensor times out
- lambda: 'return isnan(x) ? 3 : x;'
# Take median of the last 5 values
- median:
window_size: $distance_median_window_size
send_first_at: $distance_median_send_first_at
# # Convert m to cm
# # - multiply: 100
# - delta: 1
########### From here I need to reactivate ########
# on_value:
# then:
# - if:
# condition:
# binary_sensor.is_on: doorsensor2
# then:
# - if:
# # Show Red when too far into garage
# condition:
# sensor.in_range:
# id: distance
# above: 0.10
# below: 0.24
# then:
# light.turn_on:
# id: parkingled1
# brightness: 100%
# red: 100%
# green: 0%
# blue: 0%
# - if:
# # Show Green when in right spot
# condition:
# sensor.in_range:
# id: distance
# above: 0.25
# below: 0.50
# then:
# light.turn_on:
# id: parkingled1
# brightness: 90%
# red: 0%
# green: 100%
# blue: 0%
# - if:
# # show yellow if getting close to correct spot
# condition:
# sensor.in_range:
# id: distance
# above: 0.51
# below: 0.1
# then:
# light.turn_on:
# id: parkingled1
# brightness: 80%
# # yellow
# red: 100%
# green: 100%
# blue: 0%
# - if:
# condition:
# binary_sensor.is_off: doorsensor2
# then:
# - lambda: |-
# id(parkingled1).turn_off();
light:
- platform: neopixelbus
variant: WS2812X
pin: GPIO13
num_leds: 30
name: "Garage Stop Light"
restore_mode: ALWAYS OFF
default_transition_length: 0s
id: parkingled1
# script:
# id: parking_light_script
# mode: restart