hneve

esp32 display

Nov 13th, 2024
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.25 KB | None | 0 0
  1. esphome:
  2.   name: display
  3.   friendly_name: Display
  4.   comment: Testing st7735 color display
  5.  
  6. esp32:
  7.   board: esp32-c3-devkitm-1
  8.   framework:
  9.     type: arduino
  10.  
  11. <<: !include common/comset.yaml
  12.  
  13. captive_portal:
  14.  
  15. time:
  16.   - platform: homeassistant
  17.     id: esptime
  18.  
  19. sensor:
  20.   - platform: homeassistant
  21.     id: u_temp
  22.     entity_id: sensor.ute_temperatur
  23.     internal: true
  24.   - platform: homeassistant
  25.     id: i_temp
  26.     entity_id: sensor.kontor_temperatur
  27.     internal: true
  28.   - platform: homeassistant
  29.     id: baro
  30.     entity_id: sensor.barometer
  31.     internal: true
  32.  
  33. binary_sensor:
  34.   - platform: homeassistant
  35.     id: g_door
  36.     entity_id: binary_sensor.garage_door
  37.     internal: true
  38.  
  39. # Display stuff
  40. spi:
  41.   clk_pin: 3
  42.   mosi_pin: 4
  43.  
  44. display:
  45.   - platform: ili9xxx
  46.     model: ST7735
  47.     invert_colors: false
  48.     reset_pin: 5
  49.     cs_pin: 2
  50.     dc_pin: 0
  51.     rotation: 0
  52.     color_order: bgr
  53.     dimensions:
  54.       height: 128
  55.       width: 128
  56.       offset_width: 2
  57.       offset_height: 1
  58.  
  59.     update_interval: 1s
  60.     lambda: |-
  61.       // Klokke med sekunder - align center
  62.       it.strftime(64, 16, id(my_font30), id(c_red), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());
  63.      
  64.       // Dato - align center
  65.       it.strftime(64, 40, id(my_font20), id(c_blue), TextAlign::CENTER, "%d-%m-%Y", id(esptime).now());
  66.      
  67.       // Ute temperatur - align left (normal) med 8 px buffer - vises kun om data er tilgjenglig
  68.       if (id(u_temp).has_state()) {
  69.         it.printf(8, 50, id(my_font20), id(c_green), "U: %.1f°", id(u_temp).state);
  70.         }
  71.      
  72.       // Kontor temp ... align right med 8px buffer
  73.       if (id(i_temp).has_state()) {
  74.         it.printf(120, 50, id(my_font20), id(c_green), TextAlign::RIGHT, "I: %.1f°", id(i_temp).state);
  75.         }
  76.      
  77.       it.printf(64, 75, id(my_font20), id(c_green), TextAlign::CENTER, "B: %.1f", id(baro).state);  // Barometer
  78.      
  79.       // eksperiment: viser open/closed basert på binær sensor
  80.       //if ( id(g_door).state ) { it.print( 0, 90, my_font20, id(c_red), "Open" ); }
  81.       //else { it.print( 0, 90, my_font20, id(c_green), "Closed" ); };
  82.  
  83.       // samme som ovenfor bare med ikon i stedet
  84.       if ( !id(g_door).state ) {
  85.         //it.print( 98, 98, icons_50, id(c_green), "\U0000e714" );
  86.         it.image(0, 88, id(i_garage), id(c_green));
  87.         }
  88.       else {
  89.         //it.print( 98, 98, icons_50, id(c_red), "\U0000e714" );
  90.         it.image(0, 88, id(i_garage_o) , id(c_red));
  91.         }
  92.  
  93.       // MDI Testing
  94.       //it.image(0, 88, id(c_green), id(i_garage));
  95.  
  96. image:
  97.   - file: mdi:garage
  98.     id: i_garage
  99.     resize: 40x40
  100.  
  101.   - file: mdi:garage-open
  102.     id: i_garage_o
  103.     resize: 40x40
  104.  
  105.  
  106. font:
  107.   - file: "gfonts://Roboto"
  108.     id: my_font20
  109.     size: 16
  110.    
  111.  
  112.   - file: "gfonts://Roboto"
  113.     id: my_font30
  114.     size: 31
  115.     glyphs: [ 1,2,3,4,5,6,7,8,9,0,"\u003a", ]
  116.  
  117.   - file: "gfonts://Material+Symbols+Outlined"
  118.     id: icons_50
  119.     size: 30
  120.     glyphs: ["\U0000e714"] # Garage door
  121.  
  122. color:
  123.   - id: c_red
  124.     red: 100%
  125.     green: 0%
  126.     blue: 0%
  127.     white: 0%
  128.   - id: c_blue
  129.     red: 0%
  130.     green: 0%
  131.     blue: 100%
  132.     white: 0%
  133.   - id: c_green
  134.     red: 0%
  135.     green: 100%
  136.     blue: 0%
  137.     white: 0%
  138.    
Advertisement