ESPHome Garage Traffic Light for parking and integrated with Home Assistant

ESPHome Garage Traffic Light – Components

ESPHome Garage Traffic Light – Wiring

ESPHome Arduino Wiring

ESPHome Garage Traffic Light – Code

esphome:
name: vio_traffic_light
platform: ESP8266
board: d1_mini
on_boot:
priority: -10
then:
– switch.turn_on: green
– delay: 1s
– switch.turn_off: green
– switch.turn_on: yellow
– delay: 1s
– switch.turn_off: yellow
– switch.turn_on: red
– delay: 1s
– switch.turn_off: red
– switch.turn_on: green
– delay: 1s
– switch.turn_off: green
– switch.turn_on: yellow
– delay: 1s
– switch.turn_off: yellow
– switch.turn_on: red
– delay: 1s
– switch.turn_off: red
– switch.turn_on: green
– delay: 1s
– switch.turn_off: green
– switch.turn_on: yellow
– delay: 1s
– switch.turn_off: yellow
– switch.turn_on: red
– delay: 1s
– switch.turn_off: red
wifi:
ssid: “yourSSID”
password: “yourPASSWORD”
manual_ip:
static_ip: 192.168.x.x
gateway: 192.168.x.x
subnet: 255.255.255.0
dns1: 192.168.x.x
dns2: 8.8.8.8
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
switch:
– platform: gpio
pin: D5
id: red
– platform: gpio
pin: D6
id: yellow
– platform: gpio
pin: D7
id: green
globals:
– id: my_flag
type: int
restore_value: no
initial_value: ‘0’
– id: red_flag
type: int
restore_value: no
initial_value: ‘0’
– id: yellow_flag
type: int
restore_value: no
initial_value: ‘0’
– id: green_flag
type: int
restore_value: no
initial_value: ‘0’
sensor:
– platform: ultrasonic
id: vio_car_sensor
trigger_pin: D1
echo_pin: D2
name: “Vio Traffic Light”
timeout: 3m
update_interval: 0.5s
accuracy_decimals: 1
filters:
– filter_out: nan
on_value:
then:
– lambda: |-
if ((id(vio_car_sensor).state >= 1.2) & (id(my_flag) != 1)){
id(red).turn_off();
id(yellow).turn_off();
id(green).turn_off();
id(my_flag) = 1;
id(red_flag) = 0;
id(yellow_flag) = 0;
id(green_flag) = 0;
}
else if ((id(vio_car_sensor).state >= 1.0) & (id(vio_car_sensor).state < 1.2) & (id(my_flag) != 2) & (id(green_flag) < 60)){ id(red).turn_off(); id(yellow).turn_off(); id(green).turn_on(); id(my_flag) = 2; id(red_flag) = 0; id(yellow_flag) = 0; } else if ((id(vio_car_sensor).state >= 0.7) & (id(vio_car_sensor).state < 1.0) & (id(my_flag) != 3) & (id(yellow_flag) < 60)){ id(red).turn_off(); id(yellow).turn_on(); id(green).turn_off(); id(my_flag) = 3; id(red_flag) = 0; id(green_flag) = 0; } else if ((id(vio_car_sensor).state >= 0.5) & (id(vio_car_sensor).state < 0.7) & (id(my_flag) != 4) & (id(red_flag) < 60)){
id(red).turn_on();
id(yellow).turn_off();
id(green).turn_off();
id(my_flag) = 4;
id(yellow_flag) = 0;
id(green_flag) = 0;
}
else if ((id(vio_car_sensor).state < 0.5) & (id(my_flag) != 5)) {
id(red).turn_off();
id(yellow).turn_off();
id(green).turn_off();
id(my_flag) = 5;
id(red_flag) = 0;
id(yellow_flag) = 0;
id(green_flag) = 0;
}
else if ((id(green_flag) == 60) & (id(green).state != 0)){
id(red).turn_off();
id(yellow).turn_off();
id(green).turn_off();
id(yellow_flag) = 0;
id(red_flag) = 0;
}
else if ((id(yellow_flag) == 60) & (id(yellow).state != 0)){
id(red).turn_off();
id(yellow).turn_off();
id(green).turn_off();
id(green_flag) = 0;
id(red_flag) = 0;
}
else if ((id(red_flag) == 60) & (id(red).state != 0)){
id(red).turn_off();
id(yellow).turn_off();
id(green).turn_off();
id(green_flag) = 0;
id(yellow_flag) = 0;
}
id(green_flag) += 1;
id(yellow_flag) += 1;
id(red_flag) += 1;

Home Assistant Connection

Hassio ESPHome integration

ESPHome instance within Home Assistant configuration-integration

Gauge Card Configuration Home Assistant

Home Assistant Gauge card configuration

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.