Advertisement
bdnstn

lilygo

Sep 27th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 19.47 KB | None | 0 0
  1. # 11/09/2024
  2. # pa_pin: Changed from PA_BOOST to BOOST due to compile error on ESPHome update.
  3. # 12/09/2024
  4. # Add a HA sensor for fundamental sort_p time, to experiment with the range of values that work.
  5. # By experiment, established a mid point of 405ms. Put 405 in code, was 353 and comment out the sensor.
  6. # 16/09/2024
  7. # Set assumed_state to false on the basis that the remote controls are not available.
  8. # Remove channel 0 commands because they are not compatable with
  9. # "door/window open" inhibit switches, to be implimented later, when zigbee
  10. # are delivered.
  11. # 18/09/2024
  12. # Added landing blind and 'motor type' to accomodate different protocol.
  13. # Landing blind assumed_state = true because the manual control is right next
  14. # to the the blind and because blind motor battery is often flat.
  15.  
  16. substitutions:
  17.   motor_type_rollease: '1'
  18.   motor_type_oma: '2'
  19.   downstairs_rollease_addr: '57C5EC9' # Master suite blinds
  20.   upstairs_rollease_addr:  'BF17B48' # Most downstairs living and lounge blinds
  21.   landing_oma_addr:        '733fefe' # Upstairs landing blind
  22.   # Rolleasy acmedia and OMA controllers use the same command codes
  23.   up_cmd1_id: 'EE'
  24.   up_cmd2_id: 'E1'
  25.   down_cmd1_id: 'CC'
  26.   down_cmd2_id: 'E3'
  27.   stop_cmd_id: 'AA'
  28.  
  29. esphome:
  30.   name: "ds-lilygo-433"
  31.  
  32. esp32:
  33.   board: esp32dev
  34.   framework:
  35.     type: arduino
  36.  
  37. # Enable logging
  38. logger:
  39.   level: WARN
  40.  
  41. # Enable Home Assistant API
  42. api:
  43.   encryption:
  44.     key: "XzX2UPeScLDcm/0y5beJEHVMqE9sYz7TlWKHPZlgifg="
  45.  
  46. ota:
  47.   platform: esphome
  48.   password: "c1b410230fd4a715f2faf89517286e73"
  49.  
  50. wifi:
  51.   ssid: !secret wifi_ssid
  52.   password: !secret wifi_password
  53.  
  54.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  55.   ap:
  56.     ssid: "Lilygo Fallback Hotspot"
  57.     password: "tFEGtvDxfKY2"
  58.  
  59. captive_portal:
  60. # My Lilygo lora board
  61. # Detecting chip type... ESP32
  62. # Chip is ESP32-PICO-D4 (revision 1)
  63. # Features: Wi-Fi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
  64. # Crystal is 40MHz
  65. # MAC: e8:6b:ea:25:28:64
  66.  
  67. globals:
  68.   - id: cover_id    # Working storage for channel number to id conversion
  69.     type: std::string
  70.   - id: command_str # Working storage for the assembled commant for transmission
  71.     type: std::string
  72.  
  73. external_components:
  74.   - source:
  75.       type: git
  76.       url: https://github.com/swoboda1337/sx127x-esphome
  77.       ref: main
  78.     refresh: 1d
  79.  
  80. spi:
  81.   clk_pin: GPIO5
  82.   mosi_pin: GPIO27
  83.   miso_pin: GPIO19
  84.  
  85. sx127x:
  86.   id: sx127x_id
  87.   nss_pin: GPIO18
  88.   rst_pin: GPIO23
  89.   frequency: 433920000
  90.   modulation: OOK
  91.   pa_pin: BOOST
  92.   pa_power: 17
  93.   rx_start: false
  94.  
  95. remote_transmitter:
  96.   id: remote_transmitter_id
  97.   pin: GPIO32
  98.   carrier_duty_percent: 100%
  99.  
  100. script:
  101.   - id: tx_cover_command
  102.     parameters:
  103.       motor_type: int         # Motor/controller vendor id
  104.       motor_address: string   # 7 hex byte address of the motor
  105.       cover_no: int           # Channel number 0 - 15
  106.       cmd1_id: string
  107.       cmd2_id: string
  108.     mode: queued
  109.     then:
  110.       - lambda: id(convert_cover_no_to_cover_id)->execute(cover_no);
  111.       - lambda: |-
  112.           switch (motor_type) {
  113.             case ${motor_type_rollease}: {
  114.               id(tx_hex_str)->execute(int(${motor_type_rollease}), (motor_address + id(cover_id) + cmd1_id));
  115.               if (cmd2_id.length() > 0) {
  116.                 id(tx_hex_str)->execute(int(${motor_type_rollease}), motor_address + id(cover_id) + cmd2_id);
  117.                 }
  118.               }
  119.             case ${motor_type_oma}: {
  120.               id(tx_hex_str)->execute(int(${motor_type_oma}), cmd1_id + motor_address + id(cover_id));
  121.               if (cmd2_id.length() > 0) {
  122.                 id(tx_hex_str)->execute(int(${motor_type_oma}), cmd2_id + motor_address + id(cover_id));
  123.                 }
  124.               }
  125.             }
  126.  
  127.   - id: convert_cover_no_to_cover_id
  128.     # Convert decimal cover number to 1's comp hex cover_id global
  129.     parameters:
  130.       cover_decimal: int
  131.     mode: queued
  132.     then:
  133.       - lambda: |-
  134.           switch (cover_decimal) {
  135.             case 0: id(cover_id) = "F"; break;
  136.             case 1: id(cover_id) = "E"; break;
  137.             case 2: id(cover_id) = "D"; break;
  138.             case 3: id(cover_id) = "C"; break;
  139.             case 4: id(cover_id) = "B"; break;
  140.             case 5: id(cover_id) = "A"; break;
  141.             case 6: id(cover_id) = "9"; break;
  142.             case 7: id(cover_id) = "8"; break;
  143.             case 8: id(cover_id) = "7"; break;
  144.             case 9: id(cover_id) = "6"; break;
  145.             case 10: id(cover_id) = "5"; break;
  146.             case 11: id(cover_id) = "4"; break;
  147.             case 12: id(cover_id) = "2"; break;
  148.             case 13: id(cover_id) = "2"; break;
  149.             case 14: id(cover_id) = "1"; break;
  150.             case 15: id(cover_id) = "0"; break;
  151.             }
  152.  
  153.   - id: tx_hex_str
  154.     parameters:
  155.       mot_type: int
  156.       hex_str: string
  157.     mode: queued
  158.     then:
  159.       - script.execute:
  160.           id: tx_bin_str
  161.           mtr_type: !lambda return mot_type;
  162.           bin_str: !lambda |-
  163.             // ESP_LOGD("custom", "Input hex string is %s", hex_str.c_str());
  164.             std::string binary_str;
  165.             for (char& c : hex_str) {
  166.               switch (c) {
  167.                 case '0': binary_str += "0000"; break;
  168.                 case '1': binary_str += "0001"; break;
  169.                 case '2': binary_str += "0010"; break;
  170.                 case '3': binary_str += "0011"; break;
  171.                 case '4': binary_str += "0100"; break;
  172.                 case '5': binary_str += "0101"; break;
  173.                 case '6': binary_str += "0110"; break;
  174.                 case '7': binary_str += "0111"; break;
  175.                 case '8': binary_str += "1000"; break;
  176.                 case '9': binary_str += "1001"; break;
  177.                 case 'A': case 'a': binary_str += "1010"; break;
  178.                 case 'B': case 'b': binary_str += "1011"; break;
  179.                 case 'C': case 'c': binary_str += "1100"; break;
  180.                 case 'D': case 'd': binary_str += "1101"; break;
  181.                 case 'E': case 'e': binary_str += "1110"; break;
  182.                 case 'F': case 'f': binary_str += "1111"; break;
  183.               }
  184.             }
  185.             // ESP_LOGD("custom", "Outputting binary %s", binary_str.c_str());
  186.             return binary_str;
  187.  
  188.   - id: tx_bin_str
  189.     parameters:
  190.       mtr_type: int
  191.       bin_str: string
  192.     mode: queued
  193.     then:
  194.       - lambda: |-
  195.           // int short_p = id(af83873b5d8f4d3889381d74386b4e35).state;
  196.           int short_p;
  197.           switch (mtr_type) {
  198.             case ${motor_type_rollease}: short_p = 405;
  199.             case ${motor_type_oma}: short_p = 375;
  200.           }
  201.  
  202.           int short_n = short_p * -1;
  203.           int long_p = short_p * 2;
  204.           int long_n = long_p * -1;
  205.           int preamble_p = short_p * 12;
  206.           int preamble_n = short_p * -4;
  207.           int postamble_n = short_p * -25;
  208.           // ESP_LOGD("custom", "Input binary string is  %s", bin_str.c_str());
  209.           // ESP_LOGD("custom", "Size of binary string is %d", bin_str.length());
  210.           esphome::remote_base::RawTimings timings;          
  211.           timings.reserve((bin_str.length()*2)+3);          
  212.           // ESP_LOGD("Custom", "Timings size at start is %d", timings.size());
  213.           timings = {preamble_p, preamble_n};
  214.           // ESP_LOGD("Custom", "Timings capacity at start is %d", timings.capacity());
  215.           for (char& c : bin_str) {
  216.             switch (c) {
  217.               case '0': {timings.push_back(long_p); timings.push_back(short_n);} break;
  218.               case '1': {timings.push_back(short_p); timings.push_back(long_n);} break;
  219.             }
  220.           }
  221.           timings.push_back(postamble_n);
  222.           // ESP_LOGD("Custom", "Timings size at end is %d", timings.size());
  223.           // ESP_LOGD("Custom", "Timings capacity at end is   %d", timings.capacity());
  224.  
  225.           auto call = id(remote_transmitter_id).transmit();
  226.           call.get_data()->set_data(timings);
  227.           call.set_send_times(4);
  228.           id(sx127x_id).set_mode_tx();
  229.           call.perform();
  230.           id(sx127x_id).set_mode_standby();    
  231.  
  232. # sensor:
  233. # Use this to refine the pulse timing.
  234. #   - platform: homeassistant
  235. #     name: Base time
  236. #     entity_id: input_number.blind_base_time
  237. #     id: af83873b5d8f4d3889381d74386b4e35
  238.  
  239. cover:
  240.   - platform: time_based
  241.     name: 'Kitchen door'
  242.     device_class: blind
  243.     assumed_state: false
  244.     open_duration: 31s
  245.     close_duration: 30s
  246.     has_built_in_endstop: true
  247.     open_action:
  248.       - script.execute:
  249.           id: tx_cover_command
  250.           motor_type: '${motor_type_rollease}'
  251.           motor_address: '${downstairs_rollease_addr}'
  252.           cover_no: 1
  253.           cmd1_id: '${up_cmd1_id}'
  254.           cmd2_id: '${up_cmd2_id}'
  255.     close_action:
  256.      # Add condition here to check door is not open
  257.       - script.execute:
  258.           id: tx_cover_command
  259.           motor_type: '${motor_type_rollease}'
  260.           motor_address: '${downstairs_rollease_addr}'
  261.           cover_no: 1
  262.           cmd1_id: '${down_cmd1_id}'
  263.           cmd2_id: '${down_cmd2_id}'
  264.     stop_action:
  265.       - script.execute:
  266.           id: tx_cover_command
  267.           motor_type: '${motor_type_rollease}'
  268.           motor_address: '${downstairs_rollease_addr}'
  269.           cover_no: 1
  270.           cmd1_id: '${stop_cmd_id}'
  271.           cmd2_id: ''            
  272.  
  273.   - platform: time_based
  274.     name: 'Dinning door'
  275.     device_class: blind
  276.     assumed_state: false
  277.     open_duration: 31s
  278.     close_duration: 30s
  279.     has_built_in_endstop: true
  280.     open_action:
  281.       - script.execute:
  282.           id: tx_cover_command
  283.           motor_type: '${motor_type_rollease}'
  284.           motor_address: '${downstairs_rollease_addr}'
  285.           cover_no: 2
  286.           cmd1_id: '${up_cmd1_id}'
  287.           cmd2_id: '${up_cmd2_id}'
  288.     close_action:
  289.      # Add condition here to check door is not open
  290.       - script.execute:
  291.           id: tx_cover_command
  292.           motor_type: '${motor_type_rollease}'
  293.           motor_address: '${downstairs_rollease_addr}'
  294.           cover_no: 2
  295.           cmd1_id: '${down_cmd1_id}'
  296.           cmd2_id: '${down_cmd2_id}'
  297.     stop_action:
  298.       - script.execute:
  299.           id: tx_cover_command
  300.           motor_type: '${motor_type_rollease}'
  301.           motor_address: '${downstairs_rollease_addr}'
  302.           cover_no: 2
  303.           cmd1_id: '${stop_cmd_id}'
  304.           cmd2_id: ''        
  305.  
  306.   - platform: time_based
  307.     name: 'Living door 1'
  308.     device_class: blind
  309.     assumed_state: false
  310.     open_duration: 31s
  311.     close_duration: 30s
  312.     has_built_in_endstop: true
  313.     open_action:
  314.       - script.execute:
  315.           id: tx_cover_command
  316.           motor_type: '${motor_type_rollease}'
  317.           motor_address: '${downstairs_rollease_addr}'
  318.           cover_no: 4
  319.           cmd1_id: '${up_cmd1_id}'
  320.           cmd2_id: '${up_cmd2_id}'
  321.     close_action:
  322.      # Add condition here to check door is not open
  323.       - script.execute:
  324.           id: tx_cover_command
  325.           motor_type: '${motor_type_rollease}'
  326.           motor_address: '${downstairs_rollease_addr}'
  327.           cover_no: 4
  328.           cmd1_id: '${down_cmd1_id}'
  329.           cmd2_id: '${down_cmd2_id}'
  330.     stop_action:
  331.       - script.execute:
  332.           id: tx_cover_command
  333.           motor_type: '${motor_type_rollease}'
  334.           motor_address: '${downstairs_rollease_addr}'
  335.           cover_no: 4
  336.           cmd1_id: '${stop_cmd_id}'
  337.           cmd2_id: ''        
  338.  
  339.   - platform: time_based
  340.     name: 'Living door 2'
  341.     device_class: blind
  342.     assumed_state: false
  343.     open_duration: 31s
  344.     close_duration: 30s
  345.     has_built_in_endstop: true
  346.     open_action:
  347.       - script.execute:
  348.           id: tx_cover_command
  349.           motor_type: '${motor_type_rollease}'
  350.           motor_address: '${downstairs_rollease_addr}'
  351.           cover_no: 5
  352.           cmd1_id: '${up_cmd1_id}'
  353.           cmd2_id: '${up_cmd2_id}'
  354.     close_action:
  355.      # Add condition here to check door is not open
  356.       - script.execute:
  357.           id: tx_cover_command
  358.           motor_type: '${motor_type_rollease}'
  359.           motor_address: '${downstairs_rollease_addr}'
  360.           cover_no: 5
  361.           cmd1_id: '${down_cmd1_id}'
  362.           cmd2_id: '${down_cmd2_id}'
  363.     stop_action:
  364.       - script.execute:
  365.           id: tx_cover_command
  366.           motor_type: '${motor_type_rollease}'
  367.           motor_address: '${downstairs_rollease_addr}'
  368.           cover_no: 5
  369.           cmd1_id: '${stop_cmd_id}'
  370.           cmd2_id: ''            
  371.  
  372.   - platform: time_based
  373.     name: 'Lounge window'
  374.     device_class: blind
  375.     assumed_state: false
  376.     open_duration: 31s
  377.     close_duration: 30s
  378.     has_built_in_endstop: true
  379.     open_action:
  380.       - script.execute:
  381.           id: tx_cover_command
  382.           motor_type: '${motor_type_rollease}'
  383.           motor_address: '${downstairs_rollease_addr}'
  384.           cover_no: 6
  385.           cmd1_id: '${up_cmd1_id}'
  386.           cmd2_id: '${up_cmd2_id}'
  387.     close_action:
  388.      # Add condition here to check windows are not open
  389.       - script.execute:
  390.           id: tx_cover_command
  391.           motor_type: '${motor_type_rollease}'
  392.           motor_address: '${downstairs_rollease_addr}'
  393.           cover_no: 6
  394.           cmd1_id: '${down_cmd1_id}'
  395.           cmd2_id: '${down_cmd2_id}'
  396.     stop_action:
  397.       - script.execute:
  398.           id: tx_cover_command
  399.           motor_type: '${motor_type_rollease}'
  400.           motor_address: '${downstairs_rollease_addr}'
  401.           cover_no: 6
  402.           cmd1_id: '${stop_cmd_id}'
  403.           cmd2_id: ''        
  404.  
  405.   - platform: time_based
  406.     name: 'Lounge door'
  407.     device_class: blind
  408.     assumed_state: false
  409.     open_duration: 31s
  410.     close_duration: 30s
  411.     has_built_in_endstop: true
  412.     open_action:
  413.       - script.execute:
  414.           id: tx_cover_command
  415.           motor_type: '${motor_type_rollease}'
  416.           motor_address: '${downstairs_rollease_addr}'
  417.           cover_no: 7
  418.           cmd1_id: '${up_cmd1_id}'
  419.           cmd2_id: '${up_cmd2_id}'
  420.     close_action:
  421.      # Add condition here to check door is not open
  422.       - script.execute:
  423.           id: tx_cover_command
  424.           motor_type: '${motor_type_rollease}'
  425.           motor_address: '${downstairs_rollease_addr}'
  426.           cover_no: 7
  427.           cmd1_id: '${down_cmd1_id}'
  428.           cmd2_id: '${down_cmd2_id}'
  429.     stop_action:
  430.       - script.execute:
  431.           id: tx_cover_command
  432.           motor_type: '${motor_type_rollease}'
  433.           motor_address: '${downstairs_rollease_addr}'
  434.           cover_no: 7
  435.           cmd1_id: '${stop_cmd_id}'
  436.           cmd2_id: ''            
  437.  
  438.   - platform: time_based
  439.     name: 'Master bath'
  440.     device_class: blind
  441.     assumed_state: false
  442.     open_duration: 31s
  443.     close_duration: 30s
  444.     has_built_in_endstop: true
  445.     open_action:
  446.       - script.execute:
  447.           id: tx_cover_command
  448.           motor_type: '${motor_type_rollease}'
  449.           motor_address: '${upstairs_rollease_addr}'
  450.           cover_no: 1
  451.           cmd1_id: '${up_cmd1_id}'
  452.           cmd2_id: '${up_cmd2_id}'
  453.     close_action:
  454.       - script.execute:
  455.           id: tx_cover_command
  456.           motor_type: '${motor_type_rollease}'
  457.           motor_address: '${upstairs_rollease_addr}'
  458.           cover_no: 1
  459.           cmd1_id: '${down_cmd1_id}'
  460.           cmd2_id: '${down_cmd2_id}'
  461.     stop_action:
  462.       - script.execute:
  463.           id: tx_cover_command
  464.           motor_type: '${motor_type_rollease}'
  465.           motor_address: '${upstairs_rollease_addr}'
  466.           cover_no: 1
  467.           cmd1_id: '${stop_cmd_id}'
  468.           cmd2_id: ''    
  469.  
  470.   - platform: time_based
  471.     name: 'Master bed door'
  472.     device_class: blind
  473.     assumed_state: false
  474.     open_duration: 31s
  475.     close_duration: 30s
  476.     has_built_in_endstop: true
  477.     open_action:
  478.       - script.execute:
  479.           id: tx_cover_command
  480.           motor_type: '${motor_type_rollease}'
  481.           motor_address: '${upstairs_rollease_addr}'
  482.           cover_no: 2
  483.           cmd1_id: '${up_cmd1_id}'
  484.           cmd2_id: '${up_cmd2_id}'
  485.     close_action:
  486.      # Add condition here to check door is not open
  487.       - script.execute:
  488.           id: tx_cover_command
  489.           motor_type: '${motor_type_rollease}'
  490.           motor_address: '${upstairs_rollease_addr}'
  491.           cover_no: 2
  492.           cmd1_id: '${down_cmd1_id}'
  493.           cmd2_id: '${down_cmd2_id}'
  494.     stop_action:
  495.       - script.execute:
  496.           id: tx_cover_command
  497.           motor_type: '${motor_type_rollease}'
  498.           motor_address: '${upstairs_rollease_addr}'
  499.           cover_no: 2
  500.           cmd1_id: '${stop_cmd_id}'
  501.           cmd2_id: ''    
  502.  
  503.   - platform: time_based
  504.     name: 'Master bed window'
  505.     device_class: blind
  506.     assumed_state: false
  507.     open_duration: 31s
  508.     close_duration: 30s
  509.     has_built_in_endstop: true
  510.     open_action:
  511.       - script.execute:
  512.           id: tx_cover_command
  513.           motor_type: '${motor_type_rollease}'
  514.           motor_address: '${upstairs_rollease_addr}'
  515.           cover_no: 3
  516.           cmd1_id: '${up_cmd1_id}'
  517.           cmd2_id: '${up_cmd2_id}'
  518.     close_action:
  519.       - script.execute:
  520.           id: tx_cover_command
  521.           motor_type: '${motor_type_rollease}'
  522.           motor_address: '${upstairs_rollease_addr}'
  523.           cover_no: 3
  524.           cmd1_id: '${down_cmd1_id}'
  525.           cmd2_id: '${down_cmd2_id}'
  526.     stop_action:
  527.       - script.execute:
  528.           id: tx_cover_command
  529.           motor_type: '${motor_type_rollease}'
  530.           motor_address: '${upstairs_rollease_addr}'
  531.           cover_no: 3
  532.           cmd1_id: '${stop_cmd_id}'
  533.           cmd2_id: ''    
  534.  
  535.   - platform: time_based
  536.     name: 'Master bed void'
  537.     device_class: blind
  538.     assumed_state: false
  539.     open_duration: 31s
  540.     close_duration: 30s
  541.     has_built_in_endstop: true
  542.     open_action:
  543.       - script.execute:
  544.           id: tx_cover_command
  545.           motor_type: '${motor_type_rollease}'
  546.           motor_address: '${upstairs_rollease_addr}'
  547.           cover_no: 4
  548.           cmd1_id: '${up_cmd1_id}'
  549.           cmd2_id: '${up_cmd2_id}'
  550.     close_action:
  551.       - script.execute:
  552.           id: tx_cover_command
  553.           motor_type: '${motor_type_rollease}'
  554.           motor_address: '${upstairs_rollease_addr}'
  555.           cover_no: 4
  556.           cmd1_id: '${down_cmd1_id}'
  557.           cmd2_id: '${down_cmd2_id}'
  558.     stop_action:
  559.       - script.execute:
  560.           id: tx_cover_command
  561.           motor_type: '${motor_type_rollease}'
  562.           motor_address: '${upstairs_rollease_addr}'
  563.           cover_no: 4
  564.           cmd1_id: '${stop_cmd_id}'
  565.           cmd2_id: ''
  566.  
  567.  
  568.   - platform: time_based
  569.     name: 'Landing'
  570.     device_class: blind
  571.     assumed_state: true
  572.     open_duration: 22s
  573.     close_duration: 18s
  574.     has_built_in_endstop: true
  575.     open_action:
  576.       - script.execute:
  577.           id: tx_cover_command
  578.           motor_type: '${motor_type_oma}'
  579.           motor_address: '${landing_oma_addr}'
  580.           cover_no: 1
  581.           cmd1_id: '${up_cmd1_id}'
  582.           cmd2_id: '${up_cmd2_id}'
  583.     close_action:
  584.       - script.execute:
  585.           id: tx_cover_command
  586.           motor_type: '${motor_type_oma}'
  587.           motor_address: '${landing_oma_addr}'
  588.           cover_no: 1
  589.           cmd1_id: '${down_cmd1_id}'
  590.           cmd2_id: '${down_cmd2_id}'
  591.     stop_action:
  592.       - script.execute:
  593.           id: tx_cover_command
  594.           motor_type: '${motor_type_oma}'
  595.           motor_address: '${landing_oma_addr}'
  596.           cover_no: 1
  597.           cmd1_id: '${stop_cmd_id}'
  598.           cmd2_id: ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement