Advertisement
Dieton

esphome simple onboard led test yaml

May 14th, 2024 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.42 KB | None | 0 0
  1. #       !!!WARNING!!!       !!!WARNING!!!      !!!WARNING!!!        !!!WARNING!!!       #
  2. #    Take what you need from this example. do not try and run the whole thing.          #
  3. #    This code has a lot of examples you can use to learn and understand esphome yaml.  #
  4. #    running this whole example wont work. This is for people who are new               #
  5. #       !!!WARNING!!!        !!!WARNING!!!      !!!WARNING!!!        !!!WARNING!!!      #
  6.  
  7. esphome:
  8.   name: device-01
  9.   friendly_name: device_01
  10.   comment: Living room ESP32 controller
  11.   area: Living Room
  12.   on_boot:
  13.     then:
  14.       - script.execute: blink_led
  15.  
  16. esp32:
  17.   board: esp32dev
  18.   framework:
  19.     type: esp-idf
  20.  
  21. # Enable logging
  22. logger:
  23. # Enable Home Assistant API
  24. api:
  25.   encryption:
  26.     key: "yourKey"
  27.  
  28. ota:
  29.   password: "yourPassword"
  30.  
  31. wifi:
  32.   ssid: !secret wifi_ssid
  33.   password: !secret wifi_password
  34.  
  35.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  36.   ap:
  37.     ssid: "Device-01 Fallback Hotspot"
  38.     password: "yourPassword"
  39.  
  40.   manual_ip:
  41.  # Set this to the IP of the ESP
  42.     static_ip: 15.10.0.5
  43.     # Set this to the IP address of the router. Often ends with .1
  44.     gateway: 15.10.0.1
  45.     # The subnet of the network. 255.255.255.0 works for most home networks.
  46.     subnet: 255.255.255.0
  47.  
  48. captive_portal:
  49. #custom font for your display - there are web url .ttf's you can use
  50. font:
  51.   - file: "Monocraft.ttf"
  52.     id: my_font
  53.     size: 20
  54.  
  55. # Example configuration entry
  56. i2c:
  57.   sda: 21 #GPIO 21
  58.   scl: 22 #GPIO 22
  59.  
  60. switch:
  61.   - platform: template
  62.     name: "LED Toggle"
  63.     id: toggle_led
  64.     optimistic: true
  65.  
  66.   - platform: template
  67.     name: "Display Message Switch"
  68.     id: display_switch
  69.     optimistic: true
  70.     #restore_mode: RESTORE_DEFAULT_ON #start in the on position
  71.  
  72. light:
  73.   - platform: monochromatic
  74.     id: my_light
  75.     name: "My Light"
  76.     output: my_light_out
  77.  
  78. output:
  79.     #light out
  80.   - platform: slow_pwm
  81.     id: my_light_out
  82.     period: 100ms
  83.  
  84.     #this simple example lets you turn the led on and off through HA
  85.   - platform: gpio
  86.     pin: GPIO2
  87.     id: onboard_led
  88.  
  89. display:
  90.   - platform: ssd1306_i2c
  91.     model: "SH1106 128x64"
  92.     reset_pin: 0
  93.     address: 0x3C
  94.     lambda: |-
  95.       if (id(display_switch).state) {
  96.       it.printf(0, 0, id(my_font), TextAlign::LEFT, "LED is ON");
  97.       } else {
  98.       it.printf(0, 0, id(my_font), TextAlign::LEFT, "LED is OFF");
  99.       }
  100.  
  101.       it.print(0,0, id(my_font), "Test 123");
  102.       it.print(0,17, id(my_font), "more text");
  103.       char buffer[10]; // Buffer to hold the converted string
  104.       sprintf(buffer, "%.2f", 1.745); // Format the floating-point number with 2 decimal places
  105.       it.print(0, 34, id(my_font), buffer);
  106.  
  107.       it.printf(0, 0, id(my_font), "light: %.2f", id(my_light).current_values.get_brightness());//or remote_values
  108.  
  109.  
  110.  
  111. #More lighing information here:
  112. #https://esphome.io/components/light/index.html#
  113. #The Effects are activated in home assistant by clicking on the light bulb and turning effects on
  114. #light - Internal Led
  115. light:
  116.   - platform: binary
  117.     name: "ESP32 Onboard LED"
  118.     output: onboard_led
  119.     effects:
  120.       - strobe:
  121.           name: strobe
  122.           colors:
  123.             - state: true
  124.               brightness: 100%
  125.               duration: 500ms
  126.             - state: False
  127.               brightness: 0%
  128.               duration: 500ms
  129.  
  130. # Define a script to blink the LED
  131. script:
  132.  # Blink the onboard LED
  133.   id: blink_led
  134.   then:
  135.     - while:
  136.         condition:
  137.           lambda: 'return true;'
  138.         then:
  139.           - output.turn_on: onboard_led
  140.           - delay: 500ms  # Adjust the delay time as needed
  141.           - output.turn_off: onboard_led
  142.           - delay: 500ms  # Adjust the delay time as needed
  143.  
  144. switch:
  145.   - platform: template
  146.     name: "LED Toggle"
  147.     id: toggle_led
  148.     optimistic: true
  149.     #restore_mode: RESTORE_DEFAULT_ON #start in the on position
  150.     on_turn_on:
  151.       then:
  152.         - script.execute: toggle_led_script
  153.  
  154. # Define a script to toggle the LED based on the switch state
  155. script:
  156.  # Toggle the onboard LED based on the state of the switch
  157.   id: toggle_led_script
  158.   then:
  159.     - while:
  160.         condition:
  161.           switch.is_on: toggle_led
  162.         then:
  163.           - output.turn_on: onboard_led
  164.           - delay: 500ms
  165.           - output.turn_off: onboard_led
  166.           - delay: 500ms
  167.  
  168.  
  169. #VERY IMPORTANT!!!!!!!
  170. #if you get a big error message like this look for the option to run "CLEAN BUILD FILES"
  171.  
  172. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._ZNSt17_Function_handlerIFvRN7esphome7display7DisplayEEZ5setupvEUlS3_E_E9_M_invokeERKSt9_Any_dataS3_+0x8): undefined reference to `esphome::display::Display::print(int, int, esphome::display::BaseFont*, char const*)'
  173. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._Z5setupv+0x84): undefined reference to `vtable for esphome::i2c::IDFI2CBus'
  174. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._Z5setupv+0x88): undefined reference to `vtable for esphome::i2c::IDFI2CBus'
  175. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._Z5setupv+0xac): undefined reference to `vtable for esphome::ssd1306_i2c::I2CSSD1306'
  176. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._Z5setupv+0x114): undefined reference to `esphome::font::Font::Font(esphome::font::GlyphData const*, int, int, int, unsigned char)'
  177. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o:(.literal._Z5setupv+0x11c): undefined reference to `esphome::display::Display::set_writer(std::function<void (esphome::display::Display&)>&&)'
  178. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o: in function `std::_Function_handler<void (esphome::display::Display&), setup()::{lambda(esphome::display::Display&)#1}>::_M_invoke(std::_Any_data const&, esphome::display::Display&)':
  179. /config/device-01.yaml:58: undefined reference to `esphome::display::Display::print(int, int, esphome::display::BaseFont*, char const*)'
  180. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/device-01/src/main.o: in function `setup()':
  181. /config/.esphome/build/device-01/src/main.cpp:162: undefined reference to `esphome::font::Font::Font(esphome::font::GlyphData const*, int, int, int, unsigned char)'
  182. /config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /config/.esphome/build/device-01/src/main.cpp:836: undefined reference to `esphome::display::Display::set_writer(std::function<void (esphome::display::Display&)>&&)'
  183. collect2: error: ld returned 1 exit status
  184. *** [.pioenvs/device-01/firmware.elf] Error 1
Tags: ESPhome
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement