Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 11/09/2024
- # pa_pin: Changed from PA_BOOST to BOOST due to compile error on ESPHome update.
- # 12/09/2024
- # Add a HA sensor for fundamental sort_p time, to experiment with the range of values that work.
- # By experiment, established a mid point of 405ms. Put 405 in code, was 353 and comment out the sensor.
- # 16/09/2024
- # Set assumed_state to false on the basis that the remote controls are not available.
- # Remove channel 0 commands because they are not compatable with
- # "door/window open" inhibit switches, to be implimented later, when zigbee
- # are delivered.
- # 18/09/2024
- # Added landing blind and 'motor type' to accomodate different protocol.
- # Landing blind assumed_state = true because the manual control is right next
- # to the the blind and because blind motor battery is often flat.
- substitutions:
- motor_type_rollease: '1'
- motor_type_oma: '2'
- downstairs_rollease_addr: '57C5EC9' # Master suite blinds
- upstairs_rollease_addr: 'BF17B48' # Most downstairs living and lounge blinds
- landing_oma_addr: '733fefe' # Upstairs landing blind
- # Rolleasy acmedia and OMA controllers use the same command codes
- up_cmd1_id: 'EE'
- up_cmd2_id: 'E1'
- down_cmd1_id: 'CC'
- down_cmd2_id: 'E3'
- stop_cmd_id: 'AA'
- esphome:
- name: "ds-lilygo-433"
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- level: WARN
- # Enable Home Assistant API
- api:
- encryption:
- key: "XzX2UPeScLDcm/0y5beJEHVMqE9sYz7TlWKHPZlgifg="
- ota:
- platform: esphome
- password: "c1b410230fd4a715f2faf89517286e73"
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Lilygo Fallback Hotspot"
- password: "tFEGtvDxfKY2"
- captive_portal:
- # My Lilygo lora board
- # Detecting chip type... ESP32
- # Chip is ESP32-PICO-D4 (revision 1)
- # Features: Wi-Fi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
- # Crystal is 40MHz
- # MAC: e8:6b:ea:25:28:64
- globals:
- - id: cover_id # Working storage for channel number to id conversion
- type: std::string
- - id: command_str # Working storage for the assembled commant for transmission
- type: std::string
- external_components:
- - source:
- type: git
- url: https://github.com/swoboda1337/sx127x-esphome
- ref: main
- refresh: 1d
- spi:
- clk_pin: GPIO5
- mosi_pin: GPIO27
- miso_pin: GPIO19
- sx127x:
- id: sx127x_id
- nss_pin: GPIO18
- rst_pin: GPIO23
- frequency: 433920000
- modulation: OOK
- pa_pin: BOOST
- pa_power: 17
- rx_start: false
- remote_transmitter:
- id: remote_transmitter_id
- pin: GPIO32
- carrier_duty_percent: 100%
- script:
- - id: tx_cover_command
- parameters:
- motor_type: int # Motor/controller vendor id
- motor_address: string # 7 hex byte address of the motor
- cover_no: int # Channel number 0 - 15
- cmd1_id: string
- cmd2_id: string
- mode: queued
- then:
- - lambda: id(convert_cover_no_to_cover_id)->execute(cover_no);
- - lambda: |-
- switch (motor_type) {
- case ${motor_type_rollease}: {
- id(tx_hex_str)->execute(int(${motor_type_rollease}), (motor_address + id(cover_id) + cmd1_id));
- if (cmd2_id.length() > 0) {
- id(tx_hex_str)->execute(int(${motor_type_rollease}), motor_address + id(cover_id) + cmd2_id);
- }
- }
- case ${motor_type_oma}: {
- id(tx_hex_str)->execute(int(${motor_type_oma}), cmd1_id + motor_address + id(cover_id));
- if (cmd2_id.length() > 0) {
- id(tx_hex_str)->execute(int(${motor_type_oma}), cmd2_id + motor_address + id(cover_id));
- }
- }
- }
- - id: convert_cover_no_to_cover_id
- # Convert decimal cover number to 1's comp hex cover_id global
- parameters:
- cover_decimal: int
- mode: queued
- then:
- - lambda: |-
- switch (cover_decimal) {
- case 0: id(cover_id) = "F"; break;
- case 1: id(cover_id) = "E"; break;
- case 2: id(cover_id) = "D"; break;
- case 3: id(cover_id) = "C"; break;
- case 4: id(cover_id) = "B"; break;
- case 5: id(cover_id) = "A"; break;
- case 6: id(cover_id) = "9"; break;
- case 7: id(cover_id) = "8"; break;
- case 8: id(cover_id) = "7"; break;
- case 9: id(cover_id) = "6"; break;
- case 10: id(cover_id) = "5"; break;
- case 11: id(cover_id) = "4"; break;
- case 12: id(cover_id) = "2"; break;
- case 13: id(cover_id) = "2"; break;
- case 14: id(cover_id) = "1"; break;
- case 15: id(cover_id) = "0"; break;
- }
- - id: tx_hex_str
- parameters:
- mot_type: int
- hex_str: string
- mode: queued
- then:
- - script.execute:
- id: tx_bin_str
- mtr_type: !lambda return mot_type;
- bin_str: !lambda |-
- // ESP_LOGD("custom", "Input hex string is %s", hex_str.c_str());
- std::string binary_str;
- for (char& c : hex_str) {
- switch (c) {
- case '0': binary_str += "0000"; break;
- case '1': binary_str += "0001"; break;
- case '2': binary_str += "0010"; break;
- case '3': binary_str += "0011"; break;
- case '4': binary_str += "0100"; break;
- case '5': binary_str += "0101"; break;
- case '6': binary_str += "0110"; break;
- case '7': binary_str += "0111"; break;
- case '8': binary_str += "1000"; break;
- case '9': binary_str += "1001"; break;
- case 'A': case 'a': binary_str += "1010"; break;
- case 'B': case 'b': binary_str += "1011"; break;
- case 'C': case 'c': binary_str += "1100"; break;
- case 'D': case 'd': binary_str += "1101"; break;
- case 'E': case 'e': binary_str += "1110"; break;
- case 'F': case 'f': binary_str += "1111"; break;
- }
- }
- // ESP_LOGD("custom", "Outputting binary %s", binary_str.c_str());
- return binary_str;
- - id: tx_bin_str
- parameters:
- mtr_type: int
- bin_str: string
- mode: queued
- then:
- - lambda: |-
- // int short_p = id(af83873b5d8f4d3889381d74386b4e35).state;
- int short_p;
- switch (mtr_type) {
- case ${motor_type_rollease}: short_p = 405;
- case ${motor_type_oma}: short_p = 375;
- }
- int short_n = short_p * -1;
- int long_p = short_p * 2;
- int long_n = long_p * -1;
- int preamble_p = short_p * 12;
- int preamble_n = short_p * -4;
- int postamble_n = short_p * -25;
- // ESP_LOGD("custom", "Input binary string is %s", bin_str.c_str());
- // ESP_LOGD("custom", "Size of binary string is %d", bin_str.length());
- esphome::remote_base::RawTimings timings;
- timings.reserve((bin_str.length()*2)+3);
- // ESP_LOGD("Custom", "Timings size at start is %d", timings.size());
- timings = {preamble_p, preamble_n};
- // ESP_LOGD("Custom", "Timings capacity at start is %d", timings.capacity());
- for (char& c : bin_str) {
- switch (c) {
- case '0': {timings.push_back(long_p); timings.push_back(short_n);} break;
- case '1': {timings.push_back(short_p); timings.push_back(long_n);} break;
- }
- }
- timings.push_back(postamble_n);
- // ESP_LOGD("Custom", "Timings size at end is %d", timings.size());
- // ESP_LOGD("Custom", "Timings capacity at end is %d", timings.capacity());
- auto call = id(remote_transmitter_id).transmit();
- call.get_data()->set_data(timings);
- call.set_send_times(4);
- id(sx127x_id).set_mode_tx();
- call.perform();
- id(sx127x_id).set_mode_standby();
- # sensor:
- # Use this to refine the pulse timing.
- # - platform: homeassistant
- # name: Base time
- # entity_id: input_number.blind_base_time
- # id: af83873b5d8f4d3889381d74386b4e35
- cover:
- - platform: time_based
- name: 'Kitchen door'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Dinning door'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Living door 1'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Living door 2'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 5
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 5
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 5
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Lounge window'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 6
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check windows are not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 6
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 6
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Lounge door'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 7
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 7
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${downstairs_rollease_addr}'
- cover_no: 7
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Master bath'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 1
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Master bed door'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- # Add condition here to check door is not open
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 2
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Master bed window'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 3
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 3
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 3
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Master bed void'
- device_class: blind
- assumed_state: false
- open_duration: 31s
- close_duration: 30s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_rollease}'
- motor_address: '${upstairs_rollease_addr}'
- cover_no: 4
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
- - platform: time_based
- name: 'Landing'
- device_class: blind
- assumed_state: true
- open_duration: 22s
- close_duration: 18s
- has_built_in_endstop: true
- open_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_oma}'
- motor_address: '${landing_oma_addr}'
- cover_no: 1
- cmd1_id: '${up_cmd1_id}'
- cmd2_id: '${up_cmd2_id}'
- close_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_oma}'
- motor_address: '${landing_oma_addr}'
- cover_no: 1
- cmd1_id: '${down_cmd1_id}'
- cmd2_id: '${down_cmd2_id}'
- stop_action:
- - script.execute:
- id: tx_cover_command
- motor_type: '${motor_type_oma}'
- motor_address: '${landing_oma_addr}'
- cover_no: 1
- cmd1_id: '${stop_cmd_id}'
- cmd2_id: ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement