Advertisement
Dieton

esphome simple onboard led test yaml

May 14th, 2024 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.90 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. ##==== Turn Onboard LED ON / Off ====##
  50.  
  51. # Define the output for the onboard LED
  52. output:
  53.   - platform: gpio
  54.     pin: GPIO2
  55.     id: onboard_led
  56.  
  57. # Define a switch to control the onboard LED
  58. switch:
  59.   - platform: output
  60.     name: "Onboard LED"
  61.     output: onboard_led
  62.  
  63. ##==== End ====##
  64.  
  65. ##==== Read Raw Remote IR Data ====#
  66.  
  67. remote_receiver:
  68.   pin:
  69.     number: GPIO23
  70.     inverted: True
  71.   dump: all
  72.  
  73. # Optional status LED
  74. status_led:
  75.   pin: GPIO2
  76.  
  77. ##==== End ====#
  78. #custom font for your display - there are web url .ttf's you can use
  79. font:
  80.   - file: "Monocraft.ttf"
  81.     id: my_font
  82.     size: 20
  83.  
  84. # Example configuration entry
  85. i2c:
  86.   sda: 21 #GPIO 21
  87.   scl: 22 #GPIO 22
  88.  
  89. switch:
  90.   - platform: template
  91.     name: "LED Toggle"
  92.     id: toggle_led
  93.     optimistic: true
  94.  
  95.   - platform: template
  96.     name: "Display Message Switch"
  97.     id: display_switch
  98.     optimistic: true
  99.     #restore_mode: RESTORE_DEFAULT_ON #start in the on position
  100.  
  101. light:
  102.   - platform: monochromatic
  103.     id: my_light
  104.     name: "My Light"
  105.     output: my_light_out
  106.  
  107. output:
  108.     #light out
  109.   - platform: slow_pwm
  110.     id: my_light_out
  111.     period: 100ms
  112.  
  113.     #this simple example lets you turn the led on and off through HA
  114.   - platform: gpio
  115.     pin: GPIO2
  116.     id: onboard_led
  117.  
  118. display:
  119.   - platform: ssd1306_i2c
  120.     model: "SH1106 128x64"
  121.     reset_pin: 0
  122.     address: 0x3C
  123.     lambda: |-
  124.       if (id(display_switch).state) {
  125.       it.printf(0, 0, id(my_font), TextAlign::LEFT, "LED is ON");
  126.       } else {
  127.       it.printf(0, 0, id(my_font), TextAlign::LEFT, "LED is OFF");
  128.       }
  129.  
  130.       it.print(0,0, id(my_font), "Test 123");
  131.       it.print(0,17, id(my_font), "more text");
  132.       char buffer[10]; // Buffer to hold the converted string
  133.       sprintf(buffer, "%.2f", 1.745); // Format the floating-point number with 2 decimal places
  134.       it.print(0, 34, id(my_font), buffer);
  135.  
  136.       it.printf(0, 0, id(my_font), "light: %.2f", id(my_light).current_values.get_brightness());//or remote_values
  137.  
  138.  
  139.  
  140. #More lighing information here:
  141. #https://esphome.io/components/light/index.html#
  142. #The Effects are activated in home assistant by clicking on the light bulb and turning effects on
  143. #light - Internal Led
  144. light:
  145.   - platform: binary
  146.     name: "ESP32 Onboard LED"
  147.     output: onboard_led
  148.     effects:
  149.       - strobe:
  150.           name: strobe
  151.           colors:
  152.             - state: true
  153.               brightness: 100%
  154.               duration: 500ms
  155.             - state: False
  156.               brightness: 0%
  157.               duration: 500ms
  158.  
  159. # Define a script to blink the LED
  160. script:
  161.  # Blink the onboard LED
  162.   id: blink_led
  163.   then:
  164.     - while:
  165.         condition:
  166.           lambda: 'return true;'
  167.         then:
  168.           - output.turn_on: onboard_led
  169.           - delay: 500ms  # Adjust the delay time as needed
  170.           - output.turn_off: onboard_led
  171.           - delay: 500ms  # Adjust the delay time as needed
  172.  
  173. switch:
  174.   - platform: template
  175.     name: "LED Toggle"
  176.     id: toggle_led
  177.     optimistic: true
  178.     #restore_mode: RESTORE_DEFAULT_ON #start in the on position
  179.     on_turn_on:
  180.       then:
  181.         - script.execute: toggle_led_script
  182.  
  183. # Define a script to toggle the LED based on the switch state
  184. script:
  185.  # Toggle the onboard LED based on the state of the switch
  186.   id: toggle_led_script
  187.   then:
  188.     - while:
  189.         condition:
  190.           switch.is_on: toggle_led
  191.         then:
  192.           - output.turn_on: onboard_led
  193.           - delay: 500ms
  194.           - output.turn_off: onboard_led
  195.           - delay: 500ms
  196.  
  197.  
  198. #VERY IMPORTANT!!!!!!!
  199. #if you get a big error message like this look for the option to run "CLEAN BUILD FILES"
  200.  
  201. /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*)'
  202. /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'
  203. /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'
  204. /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'
  205. /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)'
  206. /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&)>&&)'
  207. /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&)':
  208. /config/device-01.yaml:58: undefined reference to `esphome::display::Display::print(int, int, esphome::display::BaseFont*, char const*)'
  209. /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()':
  210. /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)'
  211. /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&)>&&)'
  212. collect2: error: ld returned 1 exit status
  213. *** [.pioenvs/device-01/firmware.elf] Error 1
Tags: ESPhome
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement