substitutions:
  devicename: og-te-us-weather

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.';

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
    - service: play_rtttl
      variables:
        song_str: string
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'

ota:
  password: "85149b960ad66890af767aef382e81d3"

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

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

captive_portal:

# analog: humana

# HC-SR04
# GPIO → Trigger: D7	
# GPIO ← Echo, 5V: D8

# Pumpe Relais D4 Garage

# Wasserverbrauch D5 Pulse

# SDS011
# GPIO ← TX:	D3 BLUE
# GPIO → RX(optional): D2 GREEN/WHITE 
uart:
  rx_pin: D2
  tx_pin: D3
  baud_rate: 9600

# D1 dallas
# Temp_Sonne
# Temp_Schatten
dallas:
  - pin: D1

sensor:
  - platform: sds011
    pm_2_5:
      name: "${devicename} PM <2.5µm Concentration"
    pm_10_0:
      name: "${devicename} PM <10.0µm Concentration"
    update_interval: 5min

  - platform: dallas
    address: 0x640516a331ceff28
    name: "${devicename} Sun"

  - platform: dallas
    address: 0x160416a2c85bff28
    name: "${devicename} Shade"
#Logs auslesen

#  DHT11/12/22 SONOFF2301/7021
# temp_hum
# D0 / DHT22
  - platform: dht
    pin: D0
    temperature:
      name: "${devicename} Temperature"
    humidity:
      name: "${devicename} Humidity"
    update_interval: 60s
    
  - platform: wifi_signal
    name: "${devicename} Wi-Fi Signal"
    update_interval: 60s

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

  - platform: adc
    pin: A0
    name: "${devicename} Soil Moisture"
    update_interval: 10s
    unit_of_measurement: "%"
    filters:
    - median:
        window_size: 7
        send_every: 4
        send_first_at: 1
    - calibrate_linear:
        - 1.25 -> 100.00
        - 2.8 -> 0.00
    - lambda: if (x < 1) return 0; else return (x);
    accuracy_decimals: 0

switch:
  - platform: restart
    name: "${devicename} Neustart"
    
# Buzzer  D6
output:
  - platform: esp8266_pwm
    pin: D6
    frequency: 1000 Hz
    id: rtttl_out

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