Entryway Traffic Light

I steal so much code from this site that I need to contribute something back.

I have a special needs boy that can watch youtube videos of traffic lights for hours. I looked for some traffic lights online, but couldn’t find anything with four sides and actually timed. The ones I did find were hundreds of dollars.

I also wanted to:

  • Convert my entry way light to DC so it can run off of my solar system
  • Automate it
  • Put a temperature and humidity sensor in my entryway

After much thought, I had a brilliant idea of building all of it. The result is so fun!! The kids and I have had hours of fun making it do different things. I wish I had taken videos or even pictures of the process.

Traffic Light Video

Here is the ESPHOME YAML

esphome:
  name: traffic-light

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "pass"

ota:
  password: "pass"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Traffic-Light Fallback Hotspot"
    password: "pass"

captive_portal:
    
sensor:
  - platform: dht
    pin: D1
    temperature:
      name: "TL Temp"
      id: tl_temp
      filters:
        - lambda: return x * (9.0/5.0) + 32.0;
      unit_of_measurement: "°F"
      accuracy_decimals: 1
    humidity:
      name: "TL Humidity"
      id: tl_humidity
      filters:
      accuracy_decimals: 1
    model: DHT11
    update_interval: 3s

light:
  - platform: neopixelbus
    type: RGB
    variant: WS2811
    pin: D3
    num_leds: 4
    name: "TL Greens"
    id: tl_greens
    effects:
      - addressable_flicker:
      - addressable_random_twinkle:
      - addressable_scan:
      - addressable_color_wipe:
      - addressable_rainbow:
      - flicker:
      - random:
  - platform: partition
    name: "TL Greens1"
    id: tl_gr_one
    segments:
      - id: tl_greens
        from: 0
        to: 0
  - platform: partition
    name: "TL Greens2"
    id: tl_gr_two
    segments:
      - id: tl_greens
        from: 1
        to: 1
  - platform: partition
    name: "TL Greens3"
    id: tl_gr_three
    segments:
      - id: tl_greens
        from: 2
        to: 2
  - platform: partition
    name: "TL Greens4"
    id: tl_gr_four
    segments:
      - id: tl_greens
        from: 3
        to: 3

  - platform: neopixelbus
    type: RGB
    variant: WS2811
    pin: D4
    num_leds: 4
    name: "TL Yellows"
    id: tl_yellows
    effects:
      - addressable_flicker:
      - addressable_random_twinkle:
      - addressable_scan:
      - addressable_color_wipe:
      - addressable_rainbow:
      - flicker:
      - random:
  - platform: partition
    name: "TL Yellows1"
    id: tl_yl_one
    segments:
      - id: tl_yellows
        from: 0
        to: 0
  - platform: partition
    name: "TL Yellows2"
    id: tl_yl_two
    segments:
      - id: tl_yellows
        from: 1
        to: 1
  - platform: partition
    name: "TL Yellows3"
    id: tl_yl_three
    segments:
      - id: tl_yellows
        from: 2
        to: 2
  - platform: partition
    name: "TL Yellows4"
    id: tl_yl_four
    segments:
      - id: tl_yellows
        from: 3
        to: 3

  - platform: neopixelbus
    type: RGB
    variant: WS2811
    pin: D2
    num_leds: 4
    name: "TL Reds"
    id: tl_reds
    effects:
      - addressable_flicker:
      - addressable_random_twinkle:
      - addressable_scan:
      - addressable_color_wipe:
      - addressable_rainbow:
      - flicker:
      - random:
  - platform: partition
    name: "TL Reds1"
    id: tl_rd_one
    segments:
      - id: tl_reds
        from: 0
        to: 0
  - platform: partition
    name: "TL Reds2"
    id: tl_rd_two
    segments:
      - id: tl_reds
        from: 1
        to: 1
  - platform: partition
    name: "TL Reds3"
    id: tl_rd_three
    segments:
      - id: tl_reds
        from: 2
        to: 2
  - platform: partition
    name: "TL Reds4"
    id: tl_rd_four
    segments:
      - id: tl_reds
        from: 3
        to: 3

switch:
  - platform: gpio
    name: "TL Cans"
    id: tl_cans
    pin: D7

I defined four different scenes for the traffic pattern to go North (and South), slow North, go East, slow East. I also defined a few fun scenes with the effects. I’ll just post the Go North one here, I’m happy to show the others if anyone wants.

Here is the automation:

alias: TrafCrEnd
sequence:
  - repeat:
      count: "4"
      sequence:
        - service: scene.turn_on
          target:
            entity_id: scene.gon
          metadata: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
        - service: scene.turn_on
          target:
            entity_id: scene.slown
          metadata: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 500
        - service: scene.turn_on
          target:
            entity_id: scene.goe
          metadata: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
        - service: scene.turn_on
          target:
            entity_id: scene.slowe
          metadata: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 500
  - service: scene.turn_on
    target:
      entity_id: scene.traffic_effects
    metadata: {}
mode: single
icon: mdi:alarm-light

I’m happy to answer any questions. It is lot’s of fun!

1 Like

Hi,

Found your post because I was looking for a dynamic energy prices traffic light.

8 leds

First this hour green orange or red
2~8 next hours each in green orange or red.