substitutions:
  devicename: og-wz-us-bulli

esphome:
  name: ${devicename}
  platform: ESP8266
  board: nodemcuv2

  on_boot:
    then:
#      - rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
#      - rtttl.play: 'mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6'
#      - rtttl.play: 'back:d=4,o=6,b=200:4g4,4a#5,4d#5,4a#4,4a#5,4g4,4a#5,4d#5,4a#5,4d#6,4a#4,32g4,4g6,1a#.6,2d7,2g.6,2f.6,4g6,1a#.6,2d7,2g6,4c7,2a#.6,4g6,1a#.6,2d7,2g.6,1f.6,2g.6,2a#.6,2d7,2c.7,2a#.6,4g6,1a#.6,2d7,2g.6,2f.6,4g6,1a#.6,2d7,'
      - rtttl.play: 'BackToTheFuture:d=4,o=5,b=160:p,8c.,16p,g,16p,16c.6,16p,a#.,16p,16a,16p,16g,16p,8a,16p,8g,16p,8f,16p,1g.,1p,g.,16p,c.,16p,2f#.,16p,32g.,32p,32a.,32p,8g,32p,8e,32p,8c,32p,f#,16p,32g.,32p,32a.,32p,8g.,32p,8d.,32p,8g.,32p,8d.6,32p,d6,16p,c#6,16p,32b.,32p,32c#.6,32p,2d6'
#      - rtttl.play: 'PlayedAl:d=4,o=5,b=355:8g#,p,g#,8p,8f,2g#,8p,8g#,p,g#,8p,8f,g#.,f,8g#,g,g,8p,8d#,2g,8p,8g,p,g,8p,8d#,g.,d#,8g,d#,d#,8p,8c,2d#,8p,8d#,p,d#,8p,8c,d#.,c,8d#,f,c#6,8p,8f,2c#6,8p,8f,p,c#6,8p,8f,c6,8p,a#,8g#,g#,g#,8p,8f,2g#,8p,8g#,p,g#,8p,8f,g#.'
#      - rtttl.play: 'Ghostbus:d=16,o=5,b=112:g,g,8b,8g,8a,4f.,g,g,g,g,8f,4g.,g,g,8b,8g,8a,4f.,g,g,g,g,8f,8a,8g,4d.,g,g,8b,8g,8a,4f.,g,g,g,g,8f,4g.';

      - light.turn_off: bulli_left_blinker
      - light.turn_off: bulli_right_blinker
      - light.turn_off: bulli_left_headlight
      - light.turn_off: bulli_right_headlight
      - light.turn_off: bulli_left_backlight
      - light.turn_off: bulli_right_backlight
      - light.turn_off: bulli_interior_lighting
      - delay: 2s
      - light.turn_on: bulli_left_blinker
      - delay: 2s
      - light.turn_off: bulli_left_blinker
      - light.turn_on: bulli_right_blinker
      - delay: 2s
      - light.turn_off: bulli_right_blinker
      - light.turn_on: bulli_left_headlight
      - delay: 2s
      - light.turn_off: bulli_left_headlight
      - light.turn_on: bulli_right_headlight
      - delay: 2s
      - light.turn_off: bulli_right_headlight
      - light.turn_on: bulli_left_backlight
      - delay: 2s
      - light.turn_off: bulli_left_backlight
      - light.turn_on: bulli_right_backlight
      - delay: 2s
      - light.turn_off: bulli_right_backlight
      - light.turn_on: bulli_interior_lighting
      - delay: 2s
      - light.turn_off: bulli_interior_lighting

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
    - service: play_rtttl
      variables:
        song_str: string
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'
    - service: blink
      then:
      - light.turn_off: bulli_left_blinker
      - light.turn_off: bulli_right_blinker
      - light.turn_off: bulli_left_headlight
      - light.turn_off: bulli_right_headlight
      - light.turn_off: bulli_left_backlight
      - light.turn_off: bulli_right_backlight
      - light.turn_off: bulli_interior_lighting
      - delay: 2s
      - light.turn_on: bulli_left_blinker
      - delay: 2s
      - light.turn_off: bulli_left_blinker
      - light.turn_on: bulli_right_blinker
      - delay: 2s
      - light.turn_off: bulli_right_blinker
      - light.turn_on: bulli_left_headlight
      - delay: 2s
      - light.turn_off: bulli_left_headlight
      - light.turn_on: bulli_right_headlight
      - delay: 2s
      - light.turn_off: bulli_right_headlight
      - light.turn_on: bulli_left_backlight
      - delay: 2s
      - light.turn_off: bulli_left_backlight
      - light.turn_on: bulli_right_backlight
      - delay: 2s
      - light.turn_off: bulli_right_backlight
      - light.turn_on: bulli_interior_lighting
      - delay: 2s
      - light.turn_off: bulli_interior_lighting

ota:
  password: "3d5584e2ee6a8adda315ae545bdf117c"

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

  manual_ip:
    static_ip: 192.168.1.96
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${devicename}"
    password: "FkyRO7G4neIE"

captive_portal:

light:
  - platform: binary
    output: output_bulli_left_blinker
    id: bulli_left_blinker
    name: "Bulli left blinker"
    restore_mode: ALWAYS_OFF
    
  - platform: binary
    output: output_bulli_right_blinker
    id: bulli_right_blinker
    name: "Bulli right blinker"
    restore_mode: ALWAYS_OFF

  - platform: binary
    output: output_bulli_left_headlight
    id: bulli_left_headlight
    name: "Bulli left headlight"
    restore_mode: ALWAYS_OFF

  - platform: binary
    output: output_bulli_right_headlight
    id: bulli_right_headlight
    name: "Bulli right headlight"
    restore_mode: ALWAYS_OFF

  - platform: binary
    output: output_bulli_left_backlight
    id: bulli_left_backlight
    name: "Bulli left backlight"
    restore_mode: ALWAYS_OFF

  - platform: binary
    output: output_bulli_right_backlight
    id: bulli_right_backlight
    name: "Bulli right backlight"
    restore_mode: ALWAYS_OFF

  - platform: binary
    output: output_bulli_interior_lighting
    id: bulli_interior_lighting
    name: "Bulli interior lighting"
    restore_mode: ALWAYS_OFF

output:
  - platform: gpio
    pin: D1
    id: output_bulli_left_blinker

  - platform: gpio
    pin: D2
    id: output_bulli_right_blinker

  - platform: gpio
    pin: D3
    id: output_bulli_left_headlight

  - platform: gpio
    pin: D4
    id: output_bulli_right_headlight

  - platform: gpio
    pin: D5
    id: output_bulli_left_backlight

  - platform: gpio
    pin: D6
    id: output_bulli_right_backlight

  - platform: gpio
    pin: D7
    id: output_bulli_interior_lighting

# Buzzer  D6
  - platform: esp8266_pwm
    pin: D8
    frequency: 1000 Hz
    id: rtttl_out

switch:
  - platform: restart
    name: "${devicename} Neustart"

sensor:
  - platform: wifi_signal
    name: "${devicename} Wi-Fi Signal"
    update_interval: 60s

  - platform: uptime
    name: "${devicename} Uptime"
    update_interval: 60s

rtttl:
  output: rtttl_out
  on_finished_playback:
    - logger.log: 'Song ended!'
