TuXaMaT

Ulanzi Tramvay

Jun 12th, 2024
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 15.38 KB | Source Code | 0 0
  1. wifi:
  2.   ssid: !secret wifi_ssid
  3.   password: !secret wifi_password
  4.  
  5.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  6.   ap:
  7.     ssid: "Ulanzi-Tram Fallback Hotspot"
  8.     password: "password"
  9.  
  10. captive_portal:
  11.    
  12. esphome:
  13.   name: ${device}
  14.   comment: $comment
  15.   build_path: ./.build/$device
  16.   project:
  17.     name: $project_name
  18.     version: $project_version
  19.   on_boot:
  20.     then:
  21.       - ds1307.read_time:
  22. esp32:
  23.   board: esp32dev
  24.  
  25. # Enable logging
  26. logger:
  27.   level: DEBUG
  28.   baud_rate: 0
  29.   id: esp_log
  30.  
  31. # Enable Home Assistant API
  32. api:
  33.   encryption:
  34.     key: "key"
  35.   reboot_timeout: ${reboot_timeout}
  36.   services:
  37.     - service: tune
  38.       variables:
  39.         tune: string
  40.       then:
  41.         - rtttl.play:
  42.             rtttl: !lambda 'return tune;'
  43.  
  44.  
  45. ota:
  46.   password: "d92b7b427db7a24b3e387e0be7cb2464"
  47.   on_error:
  48.     then:
  49.       - logger.log:
  50.           format: "OTA Update error %d"
  51.           args: ["x"]
  52.           level: "ERROR"
  53.           tag: "ota"
  54.   on_end:
  55.     then:
  56.       - logger.log:
  57.           format: "OTA Update has completed successfully"
  58.           level: "WARN"
  59.           tag: "ota"
  60.  
  61.    
  62. web_server:
  63.   log: false
  64.  
  65.  
  66. time:
  67.   - platform: homeassistant
  68.     id: esp_time
  69.     update_interval: 1h
  70.     on_time_sync:
  71.       then:
  72.         if:
  73.           condition:
  74.             time.has_time:
  75.           then:
  76.             - logger.log: Time has been set and is valid!
  77.   - platform: homeassistant
  78.     on_time_sync:
  79.       then:
  80.         ds1307.write_time:
  81.   - platform: ds1307
  82.     update_interval: never
  83.     id: ehmtx_time
  84.  
  85.  
  86. i2c:
  87.   sda: $sda_pin
  88.   scl: $scl_pin
  89.   scan: true
  90.   id: i2cbus
  91.  
  92. light:
  93.   - platform: neopixelbus
  94.     id: ehmtx_light
  95.     type: GRB
  96.     internal: true
  97.     variant: WS2812
  98.     pin: $matrix_pin
  99.     num_leds: 256
  100.     color_correct: [30%, 30%, 30%]
  101.     gamma_correct: 2.0
  102.     name: "${name} Light"
  103.     restore_mode: ALWAYS_OFF
  104.    
  105. image:
  106.    - file: img/1pixel.gif
  107.      id: breaking20237
  108.  
  109. animation:
  110.   - file: img/1pixel.gif
  111.     id: breaking202371
  112.  
  113. display:
  114.   - platform: addressable_light
  115.     id: ehmtx_display
  116.     addressable_light_id: ehmtx_light
  117.     width: 32
  118.     height: 8
  119.     pixel_mapper: |-
  120.       if (y % 2 == 0)
  121.       {
  122.         return (y * 32) + x;
  123.       }
  124.       return (y * 32) + (31 - x);
  125.     rotation: 0°
  126.     update_interval: 16ms
  127. #    auto_clear_enabled: true
  128.     auto_clear_enabled: false
  129.     lambda: |-
  130.       id(rgb8x32)->tick();
  131.       id(rgb8x32)->draw();
  132.  
  133. output:
  134.   - platform: ledc
  135.     pin: $buzzer_pin
  136.     id: rtttl_out
  137.  
  138. rtttl:
  139.   output: rtttl_out
  140.  
  141. external_components:
  142.   - source:
  143.       type: git
  144.       url: https://github.com/lubeda/EspHoMaTriXv2
  145.       ref: latest
  146.     components: [ ehmtxv2 ]
  147.     refresh: 60s
  148.  
  149.  
  150.  
  151. ### User Settings
  152.  
  153. ehmtxv2:
  154.   id: rgb8x32
  155.   icons2html: true
  156.   matrix_component: ehmtx_display
  157.   time_component: ehmtx_time
  158.   time_format: "%H:%M"
  159.   date_format: "%d/%m"
  160.   weekdays: "ВСПНВТСРЧТПТСБ"
  161.   show_seconds: false
  162.   default_font_id: default_font
  163.   default_font_yoffset: 7
  164.   special_font_id: special_font
  165.   special_font_yoffset: 8
  166.   blend_steps: 32
  167.   scroll_count: 1 # scroll long text at least two times
  168.   scroll_interval: 80 # milliseconds
  169.   rainbow_interval: 32 # milliseconds
  170.   vertical_scroll: false
  171.   advanced_clock: true
  172.   flip_flop_clock: true
  173.  
  174.   night_mode_screens:
  175.   - 2
  176.    - 3
  177.    - 16
  178.  
  179.   on_start_running:
  180.     then:
  181.       lambda: |-
  182.         if (id(ehmtx_time).now().day_of_week == 7) {
  183.           id(rgb8x32)->icon_clock("calendar|day#2", 525600, 10, true);
  184.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  185.           id(rgb8x32)->expand_icon_to_9(3);
  186.           id(rgb8x32)->set_calendar_color(255,0,0);
  187.           id(rgb8x32)->set_today_color(255,0,0);
  188.           }
  189.         else if (id(ehmtx_time).now().day_of_week == 1) {
  190.           id(rgb8x32)->icon_clock("calendar|day#2", 525600, 10, true);
  191.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  192.           id(rgb8x32)->expand_icon_to_9(3);
  193.           id(rgb8x32)->set_calendar_color(255,0,0);
  194.           id(rgb8x32)->set_today_color(255,0,0);
  195.           }
  196.         else {
  197.           id(rgb8x32)->icon_clock("calendar|day#2", 525600, 10, true);
  198.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  199.           id(rgb8x32)->expand_icon_to_9(3);
  200.           id(rgb8x32)->set_calendar_color(255,0,0);
  201.           id(rgb8x32)->set_today_color(0,255,255);
  202.           }
  203.          
  204.  
  205.  
  206.   on_empty_queue:
  207.     then:
  208.       lambda: |-
  209.         if (id(ehmtx_time).now().day_of_week == 7) {
  210.           id(rgb8x32)->icon_clock("calendar|day#2", 525600, 10, true);
  211.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  212.           id(rgb8x32)->expand_icon_to_9(3);
  213.           id(rgb8x32)->set_calendar_color(255,0,0);
  214.           id(rgb8x32)->set_today_color(255,0,0);
  215.           }
  216.         else if (id(ehmtx_time).now().day_of_week == 1) {
  217.           id(rgb8x32)->icon_clock("calendar_|day#2", 525600, 10, true);
  218.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  219.           id(rgb8x32)->expand_icon_to_9(3);
  220.           id(rgb8x32)->set_calendar_color(255,0,0);
  221.           id(rgb8x32)->set_today_color(255,0,0);
  222.           }
  223.         else {
  224.           id(rgb8x32)->icon_clock("calendar|day#2", 525600, 10, true);
  225.           id(rgb8x32)->set_infotext_color(50, 50, 50, 50, 50, 50, true, 1);
  226.           id(rgb8x32)->expand_icon_to_9(3);
  227.           id(rgb8x32)->set_calendar_color(255,0,0);
  228.           id(rgb8x32)->set_today_color(0,255,255);          
  229.           }
  230.  
  231.  
  232.  
  233.          
  234.          
  235.  
  236.   on_next_screen:
  237.     - homeassistant.event:
  238.         event: esphome.new_screen
  239.         data_template:
  240.           iconname: !lambda "return icon.c_str();"
  241.           text: !lambda "return text.c_str();"
  242.     - lambda: |-
  243.         id(current_screen).publish_state(icon.c_str());
  244.  
  245.   on_next_clock:
  246.     lambda: |-
  247.       id(current_screen).publish_state("Clock");
  248.  
  249.   on_add_screen:
  250.     - homeassistant.event:
  251.         event: esphome.add_screen
  252.         data_template:
  253.           icon: !lambda "return icon.c_str();"
  254.           mode: !lambda "return mode;"
  255.  
  256.  
  257.   # https://developer.lametric.com/icons
  258.   icons:
  259.     - id: home_assistant
  260.       lameid: 56370
  261.     - id: temperature_cold
  262.       lameid: 6980
  263.     - id: temperature_home
  264.       lameid: 22295
  265.     - id: temperature_hot
  266.       lameid: 9275
  267.     - id: temperature
  268.       lameid: 13593
  269.     - id: temperature_down
  270.       lameid: 19649
  271.     - id: temperature_up
  272.       lameid: 19650
  273.     - id: bell
  274.       lameid: 55163      
  275.     - id: door_open
  276.       lameid: 21376  
  277.     - id: umbrella
  278.       lameid: 41619
  279.     - id: snow
  280.       lameid: 17140
  281.     - id: weather_clear_night #чистая ночь
  282.       lameid: 26086
  283.     - id: weather_exceptional
  284.       lameid: 16754
  285.     - id: weather_fog #туман
  286.       lameid: 56703
  287.     - id: weather_lightning #гроза
  288.       lameid: 60936
  289.     - id: weather_lightning_rainy #дождь с грозой
  290.       lameid: 49299
  291.     - id: weather_partlycloudy #малооблачно
  292.       lameid: 60931
  293.     - id: weather_cloudy #облачно
  294.       lameid: 22160
  295.     - id: weather_overcast #пасмурно
  296.       lameid: 2283
  297.     - id: weather_pouring #ливень
  298.       lameid: 49300
  299.     - id: weather_rainy #сильный дождь
  300.       lameid: 2284
  301.     - id: weather_extreme_rain #длительный сильный дождь
  302.       lameid: 60932
  303.     - id: weather_small_rain #небольшой дождь
  304.       lameid: 60930
  305.     - id: weather_hail #град
  306.       lameid: 60933
  307.     - id: weather_drizzle #морось
  308.       lameid: 60934
  309.     - id: weather_lightning_hail #гроза с градом
  310.       lameid: 60935
  311.     - id: weather_snowy #снег
  312.       lameid: 2289
  313.     - id: weather_snowfall #снегопад
  314.       lameid: 60937
  315.     - id: weather_small_snow #небольшой снег
  316.       lameid: 60938
  317.     - id: weather_snowy_rainy #снег с дождем
  318.       lameid: 49301
  319.     - id: weather_sunny #солнечно
  320.       lameid: 2282
  321.     - id: weather_windy
  322.       lameid: 21909
  323.     - id: weather_windy_variant
  324.       lameid: 21909
  325.     - id: weather_cloudy_night # луна и облачно
  326.       lameid: 60950
  327.     - id: weather_moon_drizzle # луна и дождь
  328.       lameid: 26091
  329.     - id: weather_moon_rain # луна и сильный дождь
  330.       lameid: 26092
  331.     - id: weather_moon_lightning # луна и молния
  332.       lameid: 60939
  333.     - id: weather_moon_fog # луна и туман
  334.       lameid: 26085
  335.     - id: humidifier
  336.       lameid: 53067
  337.     - id: humidity_out
  338.       lameid: 39042
  339.     - id: humidity_home
  340.       lameid: 39041
  341.     - id: wind
  342.       lameid: 17076
  343.     - id: wind_direction
  344.       lameid: 21909
  345.     - id: co2_aqi
  346.       lameid: 44182
  347.     - id: co2_good
  348.       lameid: 60913
  349.     - id: co2_middle
  350.       lameid: 60916
  351.     - id: co2_high
  352.       lameid: 60917
  353.     - id: pm25
  354.       lameid: 38873
  355.     - id: teapot
  356.       lameid: 35124
  357.     - id: doorbell
  358.       lameid: 42802
  359.     - id: washing
  360.       lameid: 37472
  361.     - id: purifier
  362.       lameid: 21368
  363.     - id: battery_full
  364.       lameid: 12126
  365.     - id: heart
  366.       lameid: 5859
  367.     - id: alice_listen
  368.       lameid: 57047
  369.     - id: alice_talking
  370.       lameid: 57048
  371.     - id: cover
  372.       lameid: 32098
  373.     - id: tv_on
  374.       lameid: 9754
  375.     - id: tv_off
  376.       lameid: 13582
  377.     - id: light_on
  378.       lameid: 57051
  379.     - id: alice_playing
  380.       lameid: 57065
  381.     - id: prognose
  382.       lameid: 41116
  383.     - id: alarma
  384.       lameid: 34175
  385.     - id: ozone
  386.       lameid: 21688
  387.     - id: chtree
  388.       lameid: 47754
  389.     - id: home
  390.       lameid: 22737
  391.     - id: door
  392.       lameid: 42480
  393.     - id: wnet
  394.       lameid: 40695
  395. #    - id: calendar
  396. #      lameid: 55812
  397. #    - id: calendar_r
  398. #      lameid: 3575
  399.     - id: shower
  400.       lameid: 39805
  401.  
  402.  
  403.  
  404.  
  405.      
  406.  
  407. globals:
  408.  # aab = auto-adjustable brightness
  409.   - id: aab_enable
  410.     type: "bool"
  411.     restore_value: true
  412.     initial_value: "true"
  413.  
  414.   - id: aab_add
  415.     type: int
  416.     initial_value: '5'
  417.  
  418.   - id: aab_max
  419.     type: int
  420.     initial_value: '220'
  421.  
  422.   - id: aab_min
  423.     type: int
  424.     initial_value: '20'
  425.  
  426. font:
  427.  # Matrix Clock Fonts
  428.   # Grab these from hhttps://github.com/trip5/Matrix-Fonts
  429.   # Store in a "fonts" subfolder of your ESPHome config folder or change paths below
  430.   - file: fonts/MatrixChunky6.ttf
  431.     size: 6
  432.     id: default_font
  433.     glyphs: |
  434.      ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz°|АаБбВвГ㥴ДдЕеЄєЖжЗзИиІіЇїЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЬьЮюЯяЁёЪъЫыЭэ℃₴€일월화수목금토
  435.  
  436.   - file: fonts/MatrixChunky8.ttf
  437.     size: 8
  438.     id: special_font
  439.     glyphs: |
  440.      ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz°|АаБбВвГ㥴ДдЕеЄєЖжЗзИиІіЇїЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЬьЮюЯяЁёЪъЫыЭэ℃₴€일월화수목금토
  441.  
  442.  
  443. ### Home Assistant Entities
  444.  
  445. binary_sensor:
  446.   - platform: status
  447.     name: ${name} Status
  448.     device_class: connectivity
  449.  
  450.   - platform: gpio
  451.     pin:
  452.       number: $left_button_pin
  453.       inverted: true
  454.     name: "${name} Left button"
  455.  
  456.   - platform: gpio
  457.     pin:
  458.       inverted: true
  459.       number: $mid_button_pin
  460.       mode: INPUT_PULLUP
  461.     name: "${name} Middle button"
  462.  
  463.   - platform: gpio
  464.     pin:
  465.       number: $right_button_pin
  466.       inverted: true
  467.     name: "${name} Right button"
  468.  
  469. sensor:
  470.  # - platform: sht3xd
  471.   #   temperature:
  472.   #     name: "${name} Temperature"
  473.   #   humidity:
  474.   #     name: "${name} Relative Humidity"
  475.   #   update_interval: ${update_interval}
  476.  
  477.   - platform: adc
  478.     pin: $battery_pin
  479.     name: "${name} Battery"
  480.     id: battery_voltage
  481.     update_interval: 10s
  482.     device_class: battery
  483.     accuracy_decimals: 0
  484.     attenuation: auto
  485.     filters:
  486.       - sliding_window_moving_average:
  487.           window_size: 15
  488.           send_every: 15
  489.           send_first_at: 1
  490.       - multiply: 1.6
  491.       - lambda: |-
  492.           auto r = ((x - 3) / 0.69 * 100.00);
  493.           if (r >= 100) return 100;
  494.           if (r > 0) return r;
  495.           if (r <= 0) return 1;
  496.           return 0;
  497.     unit_of_measurement: '%'
  498.  
  499.   - platform: adc
  500.     id: light_sensor
  501.     name: "${name} Illuminance"
  502.     pin: $ldr_pin
  503.     update_interval: 10s
  504.     attenuation: auto
  505.     unit_of_measurement: lx
  506.     device_class: illuminance
  507.     accuracy_decimals: 0
  508.     filters:
  509.       - lambda: |-
  510.           return (x / 10000.0) * 2000000.0 - 15 ;
  511.     on_value:
  512.       then:
  513.         - lambda: |-
  514.             if ( id(aab_enable) )
  515.             {
  516.               int n = x / 4 + id(aab_add); // new_value
  517.               if (n > id(aab_max)) n = id(aab_max);
  518.               if (n < id(aab_min)) n = id(aab_min);
  519.               int c = id(rgb8x32)->get_brightness(); // current value
  520.               c = c > 0 ? c : 1;
  521.               int d = (n - c) * 100 / c; // diff in %
  522.               if (n > 50) id(rgb8x32)->set_brightness(190);
  523.                 else if (abs(d) > 2) id(rgb8x32)->set_brightness(n);
  524.             }
  525.  
  526.  
  527.  
  528. text_sensor:
  529.   - platform: template
  530.     name: "${name} Current Screen"
  531.     id: current_screen
  532.     update_interval: never
  533.     icon: "mdi:overscan"
  534.     entity_category: diagnostic
  535.  
  536. switch:
  537.   - platform: restart
  538.     name: ${name} Restart
  539.  
  540.   - platform: template
  541.     name: "${name} Auto-Adjust Brightness"
  542.     id: switch_autobrightness
  543.     icon: mdi:brightness-auto
  544.     restore_mode: RESTORE_DEFAULT_ON
  545.     lambda: |-
  546.       if (id(aab_enable))
  547.       {
  548.         return true;
  549.       }
  550.       else
  551.       {
  552.         return false;
  553.       }
  554.     turn_on_action:
  555.       lambda: |-
  556.         id(aab_enable) = true;
  557.     turn_off_action:
  558.       lambda: |-
  559.         id(aab_enable) = false;
  560.  
  561.   - platform: template
  562.     name: "${name} Night Mode"
  563.     id: switch_night_mode
  564.     icon: mdi:weather-night
  565.     restore_mode: RESTORE_DEFAULT_OFF
  566.     lambda: |-
  567.       return id(rgb8x32)->night_mode;
  568.     turn_on_action:
  569.       lambda: |-
  570.         id(rgb8x32)->set_night_mode_on();
  571.     turn_off_action:
  572.       lambda: |-
  573.         id(rgb8x32)->set_night_mode_off();
  574.  
  575.        
  576.   - platform: template
  577.     name: "${name} Display"
  578.     icon: "mdi:clock-digital"
  579.     restore_mode: ALWAYS_ON
  580.     lambda: |-
  581.       return id(rgb8x32)->show_display;
  582.     turn_on_action:
  583.       lambda: |-
  584.         id(rgb8x32)->set_display_on();
  585.     turn_off_action:
  586.       lambda: |-
  587.         id(rgb8x32)->set_display_off();
  588.  
  589. number:
  590.   - platform: template
  591.     name: "${name} Brightness"
  592.     min_value: 20
  593.     max_value: 220
  594.     step: 1
  595.     lambda: |-
  596.       return id(rgb8x32)->get_brightness();
  597.     set_action:
  598.       lambda: |-
  599.         id(rgb8x32)->set_brightness(x);
  600.  
  601. ### Firmware, Hardware, ESP
  602.  
  603. substitutions:
  604.   device: ulanzi_tram
  605.   name: Ulanzi_tram
  606.   location: ${name}
  607.   update_interval: 60s
  608.   reboot_timeout: 0s
  609.   project_name: "Ulanzi.EHMTXv2"
  610.   project_version: "2023.9.1"
  611.   comment: "Ulanzi Pixel Clock"
  612.  
  613.   # Pin definition from https://github.com/aptonline/PixelIt_Ulanzi
  614.   battery_pin: GPIO34
  615.   buzzer_pin: GPIO15
  616.   ldr_pin: GPIO35
  617.   matrix_pin: GPIO32
  618.   left_button_pin: GPIO26
  619.   mid_button_pin: GPIO27
  620.   right_button_pin: GPIO14
  621.   scl_pin: GPIO22
  622.   sda_pin: GPIO21
Tags: ulanzi
Advertisement
Add Comment
Please, Sign In to add comment