technical:cyd
Differences
This shows you the differences between two versions of the page.
| technical:cyd [2024/10/12 21:59] – created wikiadmin | technical:cyd [2026/08/03 16:48] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== CYD Configuration ====== | ||
| - | < | ||
| - | # | ||
| - | # Basic yaml code to get the ESP32-2432S028R display to work in ESPHome. | ||
| - | # | ||
| - | # This yaml displays two rectangles acting as binary touch sensors inside of Home Assistant. | ||
| - | # | ||
| - | # Written by Jonny Bergdahl | ||
| - | # - [GitHub](https:// | ||
| - | # - [Twitter](https:// | ||
| - | # - [YouTube](https:// | ||
| - | # | ||
| - | # ============================================================ | ||
| - | # NOTE: | ||
| - | # In order for this to work you need to add the following settings in your secrets.yaml file: | ||
| - | # - api_key | ||
| - | # - ota_password | ||
| - | # - wifi_ssid | ||
| - | # - wifi_password | ||
| - | # - ap_password | ||
| - | # | ||
| - | # Create a folder named fonts in your ESPHome folder, and copy the file fonts/ | ||
| - | # | ||
| - | # ============================================================ | ||
| - | # Example file setup | ||
| - | # Change the naming below, they will be the names used in Home Assistant | ||
| - | # | ||
| - | # ============================================================ | ||
| - | # Standard ESPHome setup | ||
| - | # | ||
| - | # ESPHome naming | ||
| - | esphome: | ||
| - | name: cyd | ||
| - | friendly_name: | ||
| - | |||
| - | # The ESP32-2432S028R uses a standard ESP32-WROVER, | ||
| - | esp32: | ||
| - | board: esp32dev | ||
| - | framework: | ||
| - | type: arduino | ||
| - | |||
| - | # Enable logging | ||
| - | logger: | ||
| - | |||
| - | api: | ||
| - | encryption: | ||
| - | key: " | ||
| - | |||
| - | ota: | ||
| - | - platform: esphome | ||
| - | password: " | ||
| - | |||
| - | # Setup WiFi credentials | ||
| - | wifi: | ||
| - | ssid: !secret wifi_ssid | ||
| - | password: !secret wifi_password | ||
| - | fast_connect: | ||
| - | domain: .scottworld.net | ||
| - | |||
| - | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
| - | ap: | ||
| - | ssid: " | ||
| - | password: " | ||
| - | |||
| - | captive_portal: | ||
| - | |||
| - | # ============================================================ | ||
| - | # ESPHome Display related setup | ||
| - | # | ||
| - | # Create a font to use, add and remove glyphs as needed. | ||
| - | font: | ||
| - | - file: ' | ||
| - | id: arimo24 | ||
| - | size: 24 | ||
| - | glyphs: " | ||
| - | - file: ' | ||
| - | id: arimo96 | ||
| - | size: 96 | ||
| - | glyphs: " | ||
| - | |||
| - | # Create a Home Assistant blue color | ||
| - | color: | ||
| - | - id: ha_black | ||
| - | red_int: 0 | ||
| - | green_int: 0 | ||
| - | blue_int: 0 | ||
| - | white_int: 0 | ||
| - | |||
| - | # Create an ESPHome logo image | ||
| - | #image: | ||
| - | # - file: " | ||
| - | # id: esphome_image | ||
| - | # type: RGB24 | ||
| - | |||
| - | # ============================================================ | ||
| - | # Home Assistant related setup | ||
| - | # | ||
| - | light: | ||
| - | - platform: monochromatic | ||
| - | output: backlight_pwm | ||
| - | name: Display Backlight | ||
| - | id: backlight | ||
| - | restore_mode: | ||
| - | |||
| - | # Set up LED on the back and turn it off by default | ||
| - | - platform: rgb | ||
| - | name: RGB | ||
| - | id: led | ||
| - | red: led_red | ||
| - | green: led_green | ||
| - | blue: led_blue | ||
| - | restore_mode: | ||
| - | |||
| - | # get entity | ||
| - | sensor: | ||
| - | - platform: homeassistant | ||
| - | id: current_rate_E | ||
| - | entity_id: sensor.octopus_energy_electricity_17p7123488_2000016180455_current_rate | ||
| - | - platform: homeassistant | ||
| - | id: next_rate_E | ||
| - | entity_id: sensor.octopus_energy_electricity_17p7123488_2000016180455_next_rate | ||
| - | - platform: homeassistant | ||
| - | id: cheapest_electricity_cost | ||
| - | entity_id: binary_sensor.octopus_energy_target_cheapest_electricity | ||
| - | attribute: next_average_cost | ||
| - | - platform: homeassistant | ||
| - | id: current_electric_usage | ||
| - | entity_id: sensor.envoy_122041077530_current_power_consumption | ||
| - | |||
| - | text_sensor: | ||
| - | - platform: homeassistant | ||
| - | id: cheapest_electricity_time | ||
| - | entity_id: sensor.cheapest_elect_time | ||
| - | |||
| - | # ============================================================ | ||
| - | # Hardware related setup | ||
| - | # | ||
| - | # Setup SPI for the display. The ESP32-2432S028R uses separate SPI buses for display and touch | ||
| - | spi: | ||
| - | - id: tft | ||
| - | clk_pin: GPIO14 | ||
| - | mosi_pin: GPIO13 | ||
| - | miso_pin: GPIO12 | ||
| - | # - id: touch | ||
| - | # clk_pin: GPIO25 | ||
| - | # mosi_pin: GPIO32 | ||
| - | # miso_pin: GPIO39 | ||
| - | |||
| - | # Setup a pin to control the backlight | ||
| - | output: | ||
| - | - platform: ledc | ||
| - | pin: GPIO21 | ||
| - | id: backlight_pwm | ||
| - | |||
| - | # Setup channels for the red/ | ||
| - | - platform: ledc | ||
| - | pin: GPIO4 | ||
| - | id: led_red | ||
| - | inverted: true | ||
| - | - platform: ledc | ||
| - | pin: GPIO16 | ||
| - | id: led_green | ||
| - | inverted: true | ||
| - | - platform: ledc | ||
| - | pin: GPIO17 | ||
| - | id: led_blue | ||
| - | inverted: true | ||
| - | |||
| - | # Setup the ili9xxx platform | ||
| - | # | ||
| - | # Display is used as 240x320 by default so we rotate it to 90° | ||
| - | # | ||
| - | # We print date and time wth the strftime() function, see the ESPHome documentation to | ||
| - | # format date and atime to your locale. | ||
| - | # | ||
| - | display: | ||
| - | - platform: ili9xxx | ||
| - | model: ILI9341 | ||
| - | id: cyd | ||
| - | invert_colors: | ||
| - | update_interval: | ||
| - | spi_id: tft | ||
| - | cs_pin: GPIO15 | ||
| - | dc_pin: GPIO2 | ||
| - | dimensions: | ||
| - | height: 240 | ||
| - | width: 320 | ||
| - | color_order: | ||
| - | #rotation: 90 | ||
| - | |||
| - | |||
| - | pages: | ||
| - | - id: page1 | ||
| - | lambda: |- | ||
| - | float cre = id(current_rate_E).state * 100; | ||
| - | int rate_color = 65280; | ||
| - | if (cre > 20) { | ||
| - | rate_color = 16711680; | ||
| - | } | ||
| - | else if (cre > 10) { | ||
| - | rate_color = 16753920; | ||
| - | } | ||
| - | it.fill(id(ha_black)); | ||
| - | it.print(160, | ||
| - | it.printf(160, | ||
| - | - id: page2 | ||
| - | lambda: |- | ||
| - | float nre = id(next_rate_E).state * 100; | ||
| - | int rate_color = 65280; | ||
| - | if (nre > 20) { | ||
| - | rate_color = 16711680; | ||
| - | } | ||
| - | else if (nre > 10) { | ||
| - | rate_color = 16753920; | ||
| - | } | ||
| - | it.fill(id(ha_black)); | ||
| - | it.print(160, | ||
| - | it.printf(160, | ||
| - | - id: page3 | ||
| - | lambda: |- | ||
| - | it.fill(id(ha_black)); | ||
| - | it.print(160, | ||
| - | if (id(cheapest_electricity_time).state == " | ||
| - | it.print(160, | ||
| - | } | ||
| - | else { | ||
| - | it.printf(160, | ||
| - | it.printf(160, | ||
| - | } | ||
| - | - id: page4 | ||
| - | lambda: |- | ||
| - | it.fill(id(ha_black)); | ||
| - | it.print(160, | ||
| - | float ceu = id(current_electric_usage).state; | ||
| - | int rate_color = 65280; | ||
| - | if (ceu > 5000) { | ||
| - | rate_color = 16711680; | ||
| - | } | ||
| - | else if (ceu > 1500) { | ||
| - | rate_color = 16753920; | ||
| - | } | ||
| - | it.printf(160, | ||
| - | |||
| - | |||
| - | interval: | ||
| - | - interval: 5s | ||
| - | then: | ||
| - | - display.page.show_next: | ||
| - | - component.update: | ||
| - | </ | ||
