Advertisement
bdnstn

not declared error source

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