rootiest

ESPHome D1-Mini-ESP32 Template

Jan 12th, 2022 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.86 KB | None | 0 0
  1. ##################################################################
  2. ###                                                            ###
  3. ###                         NOTICE:                            ###
  4. ###          This is an older version. See the new             ###
  5. ###        Github page for a newer version of this file        ###
  6. ###        https://github.com/rootiest/D1Mini32-Template       ###
  7. ###                                                            ###
  8. ##################################################################
  9.  
  10. ##################################################################
  11. ### Change the Substitution Keys below to customize this board ###
  12. ##################################################################
  13.  
  14. substitutions:
  15.     device_name: template-board                               # Device name with hyphens substituted for spaces.
  16.     device_entity: template_board                             # Device name with underscores substituted for spaces.
  17.     device_description: Template for D1Mini-32 sensor boards  # Device description, shown on ESPHome Dashboard
  18.     friendly_name: Template Board                             # Device name, human-readable with spaces allowed.
  19.     ipaddress: 192.168.1.2                                 # Static IP address for this device. Comment out the manual_ip section to use DHCP
  20.  
  21.  
  22. ###############################################################################
  23. ###  Note: Entries beginning with !secret reference keys from secrets.yaml  ###
  24. ###        Place the following in /config/esphome/secrets.yaml to use       ###
  25. ###            the /config/secrets.yaml file in your ESPHome code:          ###
  26. ###                  <<: !include ../secrets.yaml                           ###
  27. ###############################################################################
  28.  
  29. # ESPHome Core config https://esphome.io/components/esphome.html
  30. esphome:
  31.   name: ${device_name}
  32.   comment: ${device_description}
  33.   platform: ESP32
  34.   board: wemos_d1_mini32
  35.  
  36. # Enable Home Assistant API https://esphome.io/components/api.html
  37. # There is a web-based random api-key generator at the link above.
  38. api:
  39.   encryption:
  40.     key: !secret template_crypt_key
  41.  
  42. # Enable logging https://esphome.io/components/logger.html
  43. logger:
  44.   level: 'INFO'
  45.  
  46. # Enable OTA updates https://esphome.io/components/ota.html
  47. ota:
  48.   password: !secret ota_password
  49.  
  50. # Enable web server https://esphome.io/components/web_server.html
  51. web_server:
  52.   port: 80
  53.   auth:
  54.     username: !secret web_serv_user
  55.     password: !secret web_serv_pass
  56.  
  57. # Enable WiFi Preconfiguration https://esphome.io/components/wifi.html
  58. wifi:
  59.   ssid: !secret wifi_ssid
  60.   password: !secret wifi_pass
  61.   # Comment out below to use DHCP instead of manual IP Address
  62.   use_address: ${ipaddress}
  63.   manual_ip:
  64.     static_ip: ${ipaddress}
  65.     gateway: !secret gateway_ip
  66.     subnet: !secret local_subnet
  67.     dns1: !secret haos_ip
  68.     dns2: !secret gateway_ip
  69.  
  70.   # Captive Portal Config
  71.   ap:
  72.     ssid: ${friendly_name}_AP
  73.     password: !secret fallbackpass
  74.  
  75. # Fallback Hotspot https://esphome.io/components/captive_portal.html
  76. captive_portal:
  77. # Use Local Time Server https://esphome.io/components/time.html
  78. # Honestly you don't need both of these, just pick one.
  79. time:
  80.   - platform: sntp
  81.     servers: !secret local_time_server
  82.     id: sntp_time
  83.   - platform: homeassistant
  84.     id: ha_time
  85.  
  86. # Align Sun Position To Lat/Long https://esphome.io/components/sun.html
  87. sun:
  88.   latitude: !secret home_lat
  89.   longitude: !secret home_lon
  90.  
  91. # Set SPI Pins https://esphome.io/components/spi.html
  92. spi:
  93.   clk_pin: 18
  94.   mosi_pin: 19
  95.  
  96. # Set I2C Pins https://esphome.io/components/i2c.html
  97. i2c:
  98.   - id: bus_a
  99.     sda: 21
  100.     scl: 22
  101.     scan: true
  102.  
  103. # Virtual Button https://esphome.io/components/button/index.html
  104. button:
  105.   # Restart Button https://esphome.io/components/button/restart.html
  106.   - platform: restart
  107.     id: restart_button
  108.     name: ${friendly_name} Restart
  109.  
  110. # Sensor Components https://esphome.io/components/sensor/index.html
  111. sensor:
  112.   # Built-in Magnetic Hall Sensor https://esphome.io/components/sensor/esp32_hall.html
  113.   - platform: esp32_hall
  114.     name: ${friendly_name} Hall Sensor
  115.     update_interval: 10s
  116.  
  117.   # WiFi Signal Sensor https://esphome.io/components/sensor/wifi_signal.html
  118.   - platform: wifi_signal
  119.     name: ${friendly_name} WiFi Signal
  120.     update_interval: 60s
  121.  
  122.   # Sun Sensors https://esphome.io/components/sun.html#sun-sensor
  123.   #
  124.   # These are internal sensors that can be used in automations on-device
  125.   # but don't create duplicate entities in Home Assistant
  126.   - platform: sun
  127.     name: Sun Elevation
  128.     id: sun_elevation
  129.     type: elevation
  130.     internal: true
  131.   - platform: sun
  132.     name: Sun Azimuth
  133.     id: sun_azimuth
  134.     type: azimuth
  135.     internal: true
  136.  
  137.   # Uptime Sensor https://esphome.io/components/sensor/uptime.html
  138.   - platform: uptime
  139.     name: ${friendly_name} Uptime Sensor
  140.     id: uptime_sensor
  141.     update_interval: 60s
  142.     on_raw_value:
  143.       then:
  144.        # Update the Human-Readable Uptime Text Sensor
  145.         - text_sensor.template.publish:
  146.             id: uptime_human
  147.             state: !lambda |-
  148.               int seconds = round(id(uptime_sensor).raw_state);
  149.               int days = seconds / (24 * 3600);
  150.               seconds = seconds % (24 * 3600);
  151.               int hours = seconds / 3600;
  152.               seconds = seconds % 3600;
  153.               int minutes = seconds /  60;
  154.               seconds = seconds % 60;
  155.               return (
  156.                 (days ? String(days) + "d " : "") +
  157.                 (hours ? String(hours) + "h " : "") +
  158.                 (minutes ? String(minutes) + "m " : "") +
  159.                 (String(seconds) + "s")
  160.               ).c_str();
  161.  
  162. # Text Sensor Components https://esphome.io/components/text_sensor/index.html
  163. text_sensor:
  164.   # ESPHome Firmware Version
  165.   - platform: version
  166.     name: ${friendly_name} ESPHome Version
  167.  
  168.   # Wifi Info https://esphome.io/components/text_sensor/wifi_info.html
  169.   - platform: wifi_info
  170.     ip_address:
  171.       name: ${friendly_name} IP Address
  172.     ssid:
  173.       name: ${friendly_name} Connected SSID
  174.     bssid:
  175.       name: ${friendly_name} Connected BSSID
  176.     mac_address:
  177.       name: ${friendly_name} Mac Wifi Address
  178.     scan_results:
  179.       name: ${friendly_name} Latest Scan Results
  180.  
  181.   # Time of Next Sunrise and Sunset
  182.   #
  183.   # These are internal sensors that can be used in automations on-device
  184.   # but don't create duplicate entities in Home Assistant
  185.   - platform: sun
  186.     name: Sun Next Sunrise
  187.     id: next_sunrise
  188.     internal: true
  189.     type: sunrise
  190.     format: "%I:%M %p"
  191.   - platform: sun
  192.     name: Sun Next Sunset
  193.     id: next_sunset
  194.     internal: true
  195.     type: sunset
  196.     format: "%I:%M %p"
  197.  
  198.   # Human-Readable Uptime https://esphome.io/components/text_sensor/template.html
  199.   #
  200.   # This is a bit of an unusual "template" as the actual templating is done
  201.   # entirely within the automation action of the uptime sensor
  202.   - platform: template
  203.     name: ${friendly_name} Uptime Human Readable
  204.     id: uptime_human
  205.     icon: mdi:clock-start
  206.  
  207. # Switch Components https://esphome.io/components/switch/index.html
  208. switch:
  209.   # Safe Mode Switch https://esphome.io/components/switch/safe_mode.html
  210.   - platform: safe_mode
  211.     name: ${friendly_name} Safe Mode
  212.  
  213.   # Shut Down Switch https://esphome.io/components/switch/shutdown.html
  214.   - platform: shutdown
  215.     name: ${friendly_name} Shutdown
  216.  
  217. # Output Components https://esphome.io/components/output/index.html
  218. output:
  219.   # Onboard LED Output Pin https://esphome.io/components/output/ledc.html
  220.   - platform: ledc
  221.     pin: 2
  222.     id: onboard_led
  223.  
  224. # Light Components https://esphome.io/components/light/index.html
  225. light:
  226.   # Onboard LED https://esphome.io/components/light/monochromatic.html
  227.   - platform: monochromatic
  228.     output: onboard_led
  229.     name: ${friendly_name} Onboard LED
Add Comment
Please, Sign In to add comment