substitutions: name: "shys-txult-cover" friendly_name: "TX Ultimate Cover" relay_count: "3" # only used on 3-way switch (relay_count = 3) toggle_relay_3_on_touch: "true" cover_name: "My Cover" cover_open_duration: 25s cover_close_duration: 25s vibra_time: 150ms button_on_time: 500ms button_brightness: "0.7" button_color: "{0,0,100}" nightlight: "on" nightlight_brightness: "0.2" nightlight_color: "{80,70,0}" cover_brightness: "0.7" cover_color1: "{0,255,0}" #open cover_color2: "{255,0,0}" #close latitude: "51.132241°" longitude: "7.178795°" touch_brightness: "1" touch_color: "{0,100,100}" touch_effect: "Scan" boot_brightness: "0.7" boot_color1: "{100,0,0}" boot_color2: "{100,100,0}" boot_effect: "Scan" long_press_brightness: "1" long_press_color: "{100,0,0}" long_press_effect: "Scan" multi_touch_brightness: "1" multi_touch_color: "{0,0,0}" multi_touch_effect: "Rainbow" swipe_left_brightness: "1" swipe_left_color: "{0,100,0}" swipe_left_effect: "Pulse" swipe_right_brightness: "1" swipe_right_color: "{100,0,70}" swipe_right_effect: "Pulse" relay_1_pin: GPIO18 relay_2_pin: GPIO17 relay_3_pin: GPIO27 relay_4_pin: GPIO23 vibra_motor_pin: GPIO21 pa_power_pin: GPIO26 led_pin: GPIO13 status_led_pin: GPIO33 uart_tx_pin: GPIO19 uart_rx_pin: GPIO22 audio_lrclk_pin: GPIO4 audio_bclk_pin: GPIO2 audio_sdata_pin: GPIO15 touchpanel_power_pin: GPIO5 esphome: name: ${name} friendly_name: ${friendly_name} project: name: smarthomeyourself.tx_ult_cover version: "1.0" on_boot: priority: 700 #-100 then: - light.turn_on: id: leds_top brightness: ${boot_brightness} red: !lambda "return id(boot_color1)[0]/100.0;" green: !lambda "return id(boot_color1)[1]/100.0;" blue: !lambda "return id(boot_color1)[2]/100.0;" effect: ${boot_effect} - wait_until: condition: wifi.connected: timeout: 1min - light.turn_on: id: leds_top brightness: ${boot_brightness} red: !lambda "return id(boot_color2)[0]/100.0;" green: !lambda "return id(boot_color2)[1]/100.0;" blue: !lambda "return id(boot_color2)[2]/100.0;" effect: ${boot_effect} - wait_until: condition: api.connected: timeout: 10s - binary_sensor.template.publish: id: touchfield_1 state: OFF - binary_sensor.template.publish: id: touchfield_2 state: OFF - binary_sensor.template.publish: id: touchfield_3 state: OFF - binary_sensor.template.publish: id: multi_touch state: OFF - binary_sensor.template.publish: id: swipe_left state: OFF - binary_sensor.template.publish: id: swipe_right state: OFF - binary_sensor.template.publish: id: long_press state: OFF - script.execute: refresh_nightlight - script.execute: refresh_led_default - light.turn_on: id: leds_right brightness: !lambda "return id(nightlight).state?${nightlight_brightness}:${cover_brightness};" effect: "Cover Position" esp32: board: esp32dev framework: type: esp-idf logger: # hardware_uart: UART2 level: DEBUG logs: binary_sensor: INFO light: INFO script: DEBUG switch: INFO tx_ultimate_touch: INFO uart_debug: INFO dashboard_import: package_import_url: github://SmartHome-yourself/shys-collection/templates/esphome/setups/sonoff-tx-ultimate/variants/tx_ult_cover.yaml@main import_full_config: false api: ota: - platform: esphome wifi: ap: password: "12345678" improv_serial: captive_portal: external_components: # - source: /config/esphome/my_components - source: type: git url: https://github.com/SmartHome-yourself/sonoff-tx-ultimate-for-esphome ref: main components: [tx_ultimate_touch] globals: - id: nightlight_color type: int [3] restore_value: no initial_value: ${nightlight_color} - id: button_color type: int [3] restore_value: no initial_value: ${button_color} - id: long_press_color type: int [3] restore_value: no initial_value: ${long_press_color} - id: multi_touch_color type: int [3] restore_value: no initial_value: ${multi_touch_color} - id: swipe_left_color type: int [3] restore_value: no initial_value: ${swipe_left_color} - id: swipe_right_color type: int [3] restore_value: no initial_value: ${swipe_right_color} - id: touch_color type: int [3] restore_value: no initial_value: ${touch_color} - id: boot_color1 type: int [3] restore_value: no initial_value: ${boot_color1} - id: boot_color2 type: int [3] restore_value: no initial_value: ${boot_color2} - id: cover_color1 type: int [3] restore_value: no initial_value: ${cover_color1} - id: cover_color2 type: int [3] restore_value: no initial_value: ${cover_color2} binary_sensor: - platform: template name: "Touchfield 1" id: touchfield_1 on_press: - script.execute: cover_open_action - delay: ${button_on_time} - binary_sensor.template.publish: id: touchfield_1 state: OFF - script.execute: refresh_led_default - platform: template name: "Touchfield 2" id: touchfield_2 on_press: - if: condition: lambda: "return (${relay_count}==3);" then: - if: condition: lambda: "return ${toggle_relay_3_on_touch};" then: - switch.toggle: relay_3 else: - script.execute: cover_close_action - delay: ${button_on_time} - binary_sensor.template.publish: id: touchfield_2 state: OFF - script.execute: refresh_led_default - platform: template name: "Touchfield 3" id: touchfield_3 on_press: - script.execute: cover_close_action - delay: ${button_on_time} - binary_sensor.template.publish: id: touchfield_3 state: OFF - script.execute: refresh_led_default - platform: template name: "Swipe left" id: swipe_left on_press: - delay: ${button_on_time} - binary_sensor.template.publish: id: swipe_left state: OFF - script.execute: refresh_led_default - platform: template name: "Swipe_right" id: swipe_right on_press: - delay: ${button_on_time} - binary_sensor.template.publish: id: swipe_right state: OFF - script.execute: refresh_led_default - platform: template name: "Multi Touch" id: multi_touch on_press: - delay: ${button_on_time} - binary_sensor.template.publish: id: multi_touch state: OFF - script.execute: refresh_led_default - platform: template name: "Long Press" id: long_press on_press: - delay: ${button_on_time} - binary_sensor.template.publish: id: long_press state: OFF - script.execute: refresh_led_default switch: - platform: gpio id: relay_1 name: "${friendly_name} L1" pin: ${relay_1_pin} restore_mode: RESTORE_DEFAULT_OFF interlock: &interlock_group [relay_1, relay_2] internal: true on_turn_on: then: - script.execute: refresh_led_default on_turn_off: then: - script.execute: refresh_led_default - platform: gpio id: relay_2 name: "${friendly_name} L2" pin: ${relay_2_pin} restore_mode: RESTORE_DEFAULT_OFF interlock: *interlock_group internal: true on_turn_on: then: - script.execute: refresh_led_default on_turn_off: then: - script.execute: refresh_led_default - platform: gpio id: relay_3 name: "${friendly_name} L3" pin: ${relay_3_pin} restore_mode: RESTORE_DEFAULT_OFF on_turn_on: then: - script.execute: refresh_led_default on_turn_off: then: - script.execute: refresh_led_default - platform: gpio id: vibra pin: ${vibra_motor_pin} name: "${friendly_name} Vibration" restore_mode: ALWAYS_OFF on_turn_on: - delay: ${vibra_time} - switch.turn_off: vibra - platform: gpio id: pa_power pin: ${pa_power_pin} name: "PA Power" internal: true restore_mode: ALWAYS_ON - platform: gpio name: "touch panel power" pin: number: ${touchpanel_power_pin} inverted: true id: touch_power internal: true restore_mode: RESTORE_DEFAULT_ON - platform: template name: "Nightlight" id: nightlight internal: true optimistic: true restore_mode: RESTORE_DEFAULT_OFF on_turn_on: then: - script.execute: refresh_led_default on_turn_off: then: - script.execute: refresh_led_default - platform: template name: "Nightlight" id: nightlight_active optimistic: true restore_mode: RESTORE_DEFAULT_OFF on_turn_on: then: - script.execute: refresh_led_default on_turn_off: then: - script.execute: refresh_led_default - platform: restart name: "${friendly_name} Restart" light: - platform: esp32_rmt_led_strip chipset: WS2811 rgb_order: GRB pin: ${led_pin} num_leds: 28 name: "NeoPixel Light" id: leds default_transition_length: 0s effects: - addressable_rainbow: name: "Rainbow" speed: 30 width: 8 - pulse: name: "Pulse" transition_length: 1.4s update_interval: 1s on_turn_off: then: - script.execute: refresh_led_default - platform: partition name: "LEDs Button right" id: leds_button_right internal: true segments: - id: leds from: 7 to: 7 - platform: partition name: "LEDs Button middle" id: leds_button_middle internal: true segments: - id: leds from: 9 to: 9 - platform: partition name: "LEDs Button left" id: leds_button_left internal: true segments: - id: leds from: 11 to: 11 - platform: partition name: "LEDs Nightlight" id: leds_nightlight internal: true segments: - id: leds from: 8 to: 8 - id: leds from: 10 to: 10 - id: leds from: 12 to: 19 - id: leds_top from: 0 to: 6 - platform: partition name: "LEDs Top" id: leds_top internal: true segments: - id: leds from: 20 to: 26 effects: - addressable_scan: name: "Scan" - addressable_rainbow: name: "Rainbow" speed: 10 width: 20 - platform: partition name: "LEDs Left" id: leds_left internal: true segments: - id: leds from: 13 to: 19 effects: - pulse: name: "Pulse" transition_length: 600ms update_interval: 300ms - platform: partition name: "LEDs Right" id: leds_right internal: true segments: - id: leds from: 27 to: 27 - id: leds from: 0 to: 5 effects: - pulse: name: "Pulse" transition_length: 600ms update_interval: 300ms - addressable_lambda: name: "Cover Position" update_interval: 500ms lambda: |- int16_t pos = (int16_t)round(id(my_cover).position * 7); it.range(7-pos, 7) = esphome::Color(id(cover_color1)[0],id(cover_color1)[1],id(cover_color1)[2]); if (pos < 7){ it.range(0, 7-pos) = esphome::Color(id(cover_color2)[0],id(cover_color2)[1],id(cover_color2)[2]); } i2s_audio: id: audio_i2s i2s_lrclk_pin: ${audio_lrclk_pin} i2s_bclk_pin: ${audio_bclk_pin} speaker: - platform: i2s_audio id: media_out dac_type: external i2s_dout_pin: ${audio_sdata_pin} i2s_audio_id: audio_i2s i2s_comm_fmt: i2s_lsb channel: mono uart: tx_pin: ${uart_tx_pin} rx_pin: ${uart_rx_pin} id: my_uart baud_rate: 115200 data_bits: 8 stop_bits: 1 parity: NONE debug: direction: RX dummy_receiver: false after: timeout: 2s bytes: 2048 sequence: - lambda: UARTDebug::log_hex(direction, bytes, ' '); tx_ultimate_touch: id: tx_touch uart: my_uart on_press: # - script.execute: led_on_touch - lambda: > ESP_LOGD("tx_ultimate_touch.on_press", "Touch Position: %d / State: %d", touch.x, touch.state); on_release: - script.execute: id: handle_release pos: !lambda "return touch.x;" - switch.turn_on: vibra - lambda: > ESP_LOGD("tx_ultimate_touch.on_release", "Release Position: %d / State: %d", touch.x, touch.state); on_swipe_left: - script.execute: led_on_swipe_left - switch.turn_on: vibra - binary_sensor.template.publish: id: swipe_left state: ON - lambda: > ESP_LOGD("tx_ultimate_touch.on_swipe_left", "Swipe Left Position: %d / State: %d", touch.x, touch.state); on_swipe_right: - script.execute: led_on_swipe_right - switch.turn_on: vibra - binary_sensor.template.publish: id: swipe_right state: ON - lambda: > ESP_LOGD("tx_ultimate_touch.on_swipe_right", "Swipe Right Position: %d / State: %d", touch.x, touch.state); on_full_touch_release: - script.execute: led_on_full_touch - switch.turn_on: vibra - binary_sensor.template.publish: id: multi_touch state: ON - lambda: > ESP_LOGD("tx_ultimate_touch.on_full_touch_release", "Full Touch Release Position: %d / State: %d", touch.x, touch.state); on_long_touch_release: - script.execute: led_on_long_touch - switch.turn_on: vibra - binary_sensor.template.publish: id: long_press state: ON - lambda: > ESP_LOGD("tx_ultimate_touch.on_long_touch_release", "Long Touch Release Position: %d / State: %d", touch.x, touch.state); time: - platform: homeassistant - platform: sntp on_time: # Every 5 minutes - seconds: 0 minutes: /5 then: - script.execute: refresh_nightlight sun: latitude: ${latitude} longitude: ${longitude} cover: - platform: time_based name: ${cover_name} id: my_cover assumed_state: false open_action: - light.turn_on: id: leds_right brightness: !lambda "return id(nightlight).state?${nightlight_brightness}:${cover_brightness};" effect: "Cover Position" - script.execute: open_cover open_duration: ${cover_open_duration} close_action: - light.turn_on: id: leds_right brightness: !lambda "return id(nightlight).state?${nightlight_brightness}:${cover_brightness};" effect: "Cover Position" - script.execute: close_cover close_duration: ${cover_close_duration} stop_action: - script.execute: stop_cover script: - id: open_cover mode: restart then: - switch.turn_on: relay_1 - id: close_cover mode: restart then: - switch.turn_on: relay_2 - id: stop_cover mode: restart then: - switch.turn_off: relay_1 - switch.turn_off: relay_2 - id: refresh_nightlight mode: restart then: - if: condition: lambda: 'return "${nightlight}" == "on";' then: - if: condition: - sun.is_below_horizon: then: - switch.turn_on: id: nightlight else: - switch.turn_off: id: nightlight - id: refresh_led_default mode: restart then: - if: condition: lambda: "return id(nightlight).state || id(nightlight_active).state;" then: - light.turn_on: id: leds_top brightness: ${nightlight_brightness} red: !lambda "return id(nightlight_color)[0]/100.0;" green: !lambda "return id(nightlight_color)[1]/100.0;" blue: !lambda "return id(nightlight_color)[2]/100.0;" effect: "None" - script.execute: led_on_nightlight else: - light.turn_off: id: leds_top - light.turn_off: leds_nightlight - if: condition: lambda: "return (id(relay_1).state) ;" then: - script.execute: led_on_button_left else: - script.execute: led_off_button_left - if: condition: lambda: "return (${relay_count}==3 && id(relay_3).state);" then: - script.execute: led_on_button_middle else: - script.execute: led_off_button_middle - if: condition: lambda: "return id(relay_2).state;" then: - script.execute: led_on_button_right else: - script.execute: led_off_button_right - id: led_on_button_left mode: restart then: - light.turn_on: id: leds_button_left brightness: ${button_brightness} red: !lambda "return id(button_color)[0]/100.0;" green: !lambda "return id(button_color)[1]/100.0;" blue: !lambda "return id(button_color)[2]/100.0;" - id: led_on_button_middle mode: restart then: - light.turn_on: id: leds_button_middle brightness: ${button_brightness} red: !lambda "return id(button_color)[0]/100.0;" green: !lambda "return id(button_color)[1]/100.0;" blue: !lambda "return id(button_color)[2]/100.0;" - id: led_on_button_right mode: restart then: - light.turn_on: id: leds_button_right brightness: ${button_brightness} red: !lambda "return id(button_color)[0]/100.0;" green: !lambda "return id(button_color)[1]/100.0;" blue: !lambda "return id(button_color)[2]/100.0;" - id: led_off_button_left mode: restart then: - if: condition: lambda: "return id(nightlight).state || id(nightlight_active).state;" then: - light.turn_on: id: leds_button_left brightness: ${nightlight_brightness} red: !lambda "return id(nightlight_color)[0]/100.0;" green: !lambda "return id(nightlight_color)[1]/100.0;" blue: !lambda "return id(nightlight_color)[2]/100.0;" else: - light.turn_off: id: leds_button_left - id: led_off_button_middle mode: restart then: - if: condition: lambda: "return id(nightlight).state || id(nightlight_active).state;" then: - light.turn_on: id: leds_button_middle brightness: ${nightlight_brightness} red: !lambda "return id(nightlight_color)[0]/100.0;" green: !lambda "return id(nightlight_color)[1]/100.0;" blue: !lambda "return id(nightlight_color)[2]/100.0;" else: - light.turn_off: id: leds_button_middle - id: led_off_button_right mode: restart then: - if: condition: lambda: "return id(nightlight).state || id(nightlight_active).state;" then: - light.turn_on: id: leds_button_right brightness: ${nightlight_brightness} red: !lambda "return id(nightlight_color)[0]/100.0;" green: !lambda "return id(nightlight_color)[1]/100.0;" blue: !lambda "return id(nightlight_color)[2]/100.0;" else: - light.turn_off: id: leds_button_right - id: led_on_nightlight mode: restart then: - light.turn_on: id: leds_nightlight brightness: ${nightlight_brightness} red: !lambda "return id(nightlight_color)[0]/100.0;" green: !lambda "return id(nightlight_color)[1]/100.0;" blue: !lambda "return id(nightlight_color)[2]/100.0;" effect: "None" - id: led_on_release mode: restart then: # - light.turn_off: # id: leds_top - script.execute: refresh_led_default - id: led_on_touch mode: restart then: - light.turn_on: id: leds_top brightness: ${touch_brightness} red: !lambda "return id(touch_color)[0]/100.0;" green: !lambda "return id(touch_color)[1]/100.0;" blue: !lambda "return id(touch_color)[2]/100.0;" effect: ${touch_effect} - delay: 6s - script.execute: refresh_led_default - id: led_on_swipe_left mode: restart then: - light.turn_on: id: leds_left brightness: ${swipe_left_brightness} red: !lambda "return id(swipe_left_color)[0]/100.0;" green: !lambda "return id(swipe_left_color)[1]/100.0;" blue: !lambda "return id(swipe_left_color)[2]/100.0;" effect: ${swipe_left_effect} - delay: 2.4s - light.turn_off: id: leds_left - script.execute: refresh_led_default - id: led_on_swipe_right mode: restart then: - light.turn_on: id: leds_right brightness: ${swipe_right_brightness} red: !lambda "return id(swipe_right_color)[0]/100.0;" green: !lambda "return id(swipe_right_color)[1]/100.0;" blue: !lambda "return id(swipe_right_color)[2]/100.0;" effect: ${swipe_right_effect} - delay: 2.4s - light.turn_on: id: leds_right effect: "Cover Position" - id: led_on_full_touch mode: restart then: - light.turn_on: id: leds_top brightness: ${multi_touch_brightness} red: !lambda "return id(multi_touch_color)[0]/100.0;" green: !lambda "return id(multi_touch_color)[1]/100.0;" blue: !lambda "return id(multi_touch_color)[2]/100.0;" effect: ${multi_touch_effect} - id: led_on_long_touch mode: restart then: - light.turn_on: id: leds_top brightness: ${long_press_brightness} red: !lambda "return id(long_press_color)[0]/100.0;" green: !lambda "return id(long_press_color)[1]/100.0;" blue: !lambda "return id(long_press_color)[2]/100.0;" effect: ${long_press_effect} - id: handle_release mode: restart parameters: pos: int then: - if: condition: lambda: "return ${relay_count}==1;" then: - binary_sensor.template.publish: id: touchfield_1 state: ON - if: condition: lambda: "return ${relay_count}==2;" then: - if: condition: lambda: "return pos <= 5;" then: - binary_sensor.template.publish: id: touchfield_1 state: ON else: - binary_sensor.template.publish: id: touchfield_2 state: ON - if: condition: lambda: "return ${relay_count}==3;" then: - if: condition: lambda: "return pos <= 3;" then: - binary_sensor.template.publish: id: touchfield_1 state: ON else: - if: condition: lambda: "return pos <= 7;" then: - binary_sensor.template.publish: id: touchfield_2 state: ON else: - binary_sensor.template.publish: id: touchfield_3 state: ON - id: cover_open_action mode: restart then: - lambda: | if (id(my_cover).current_operation == COVER_OPERATION_IDLE) { id(my_cover).make_call().set_command_open().perform(); } else { id(my_cover).make_call().set_command_stop().perform(); } - id: cover_close_action mode: restart then: - lambda: | if (id(my_cover).current_operation == COVER_OPERATION_IDLE) { id(my_cover).make_call().set_command_close().perform(); } else { id(my_cover).make_call().set_command_stop().perform(); }