Merge pull request #71 from edwardtfn/expose-relay-indicator-leds

Expose relay-indicator LEDs
This commit is contained in:
Edward Firmo
2024-12-25 01:44:54 +01:00
committed by GitHub
6 changed files with 540 additions and 427 deletions

View File

@@ -41,6 +41,15 @@ api:
then: then:
- script.execute: publish_device_info - script.execute: publish_device_info
binary_sensor:
- id: bs_pending_restart
name: Pending Restart Status
internal: false
disabled_by_default: false
platform: template
entity_category: diagnostic
device_class: problem
button: button:
- id: bt_restart - id: bt_restart
name: Restart name: Restart
@@ -97,7 +106,7 @@ ota:
psram: psram:
mode: octal mode: octal
speed: 40MHz speed: 80MHz
script: script:
- id: api_send_ha_event_boot - id: api_send_ha_event_boot
@@ -130,11 +139,24 @@ script:
- script.execute: - script.execute:
id: api_send_ha_event_boot id: api_send_ha_event_boot
type: start type: start
- wait_until:
condition:
- lambda: return sl_tx_model_format->active_index().has_value();
- lambda: return sl_tx_model_gang->active_index().has_value();
- lambda: |-
id(is_us_model) = (sl_tx_model_format->state == "${TX_MODEL_FORMAT_US_TEXT}");
id(gang_count) = sl_tx_model_gang->active_index().value() + 1;
if (id(gang_count) < 1 || id(gang_count) > 4) {
ESP_LOGE("core_hw_leds", "Invalid number of gangs: %" PRIu8, id(gang_count));
}
- id: boot_sequence - id: boot_sequence
mode: restart mode: restart
then: then:
- script.execute: publish_device_info - script.execute: publish_device_info
- binary_sensor.template.publish:
id: bs_pending_restart
state: false
- id: publish_device_info - id: publish_device_info
mode: restart mode: restart
@@ -159,6 +181,9 @@ select:
icon: mdi:tablet-cellphone icon: mdi:tablet-cellphone
on_value: on_value:
then: then:
- binary_sensor.template.publish:
id: bs_pending_restart
state: true
- lambda: |- - lambda: |-
id(is_us_model) = (x == "${TX_MODEL_FORMAT_US_TEXT}"); id(is_us_model) = (x == "${TX_MODEL_FORMAT_US_TEXT}");
ESP_LOGI("core", "New model selected: %s", id(is_us_model) ? "US" : "EU"); ESP_LOGI("core", "New model selected: %s", id(is_us_model) ? "US" : "EU");
@@ -180,6 +205,9 @@ select:
icon: mdi:dip-switch icon: mdi:dip-switch
on_value: on_value:
then: then:
- binary_sensor.template.publish:
id: bs_pending_restart
state: true
- lambda: |- - lambda: |-
id(gang_count) = static_cast<uint8_t>(i) + 1; id(gang_count) = static_cast<uint8_t>(i) + 1;
ESP_LOGI("core", "New model selected: %" PRIu8 "-%s", id(gang_count), id(gang_count) > 1 ? "Gangs" : "Gang"); ESP_LOGI("core", "New model selected: %" PRIu8 "-%s", id(gang_count), id(gang_count) > 1 ? "Gangs" : "Gang");

View File

@@ -86,28 +86,19 @@ script:
- id: boot_initialize_buttons - id: boot_initialize_buttons
mode: restart mode: restart
then: then:
- wait_until:
condition:
- lambda: return sl_tx_model_gang->active_index().has_value();
- lambda: |- - lambda: |-
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) ?
(sl_tx_model_gang->active_index().value() + 1) : 0;
if (num_gangs < 1 || num_gangs > 4) {
ESP_LOGE("core_hw_buttons", "Invalid number of gangs: %" PRIu8, num_gangs);
return;
}
bs_button_1->publish_state(false); bs_button_1->publish_state(false);
bs_button_1->set_internal(num_gangs < 1); bs_button_1->set_internal(id(gang_count) < 1);
sl_button_1_action->set_internal(num_gangs < 1); sl_button_1_action->set_internal(id(gang_count) < 1);
bs_button_2->publish_state(false); bs_button_2->publish_state(false);
bs_button_2->set_internal(num_gangs < 2); bs_button_2->set_internal(id(gang_count) < 2);
sl_button_2_action->set_internal(num_gangs < 2); sl_button_2_action->set_internal(id(gang_count) < 2);
bs_button_3->publish_state(false); bs_button_3->publish_state(false);
bs_button_3->set_internal(num_gangs < 3); bs_button_3->set_internal(id(gang_count) < 3);
sl_button_3_action->set_internal(num_gangs < 3); sl_button_3_action->set_internal(id(gang_count) < 3);
bs_button_4->publish_state(false); bs_button_4->publish_state(false);
bs_button_4->set_internal(num_gangs < 4); bs_button_4->set_internal(id(gang_count) < 4);
sl_button_4_action->set_internal(num_gangs < 4); sl_button_4_action->set_internal(id(gang_count) < 4);
- id: button_action - id: button_action
mode: parallel mode: parallel

View File

@@ -28,7 +28,6 @@ substitutions:
LIGHT_FULL_RESTORE_MODE: RESTORE_DEFAULT_OFF LIGHT_FULL_RESTORE_MODE: RESTORE_DEFAULT_OFF
LIGHT_SIDES_RESTORE_MODE: RESTORE_DEFAULT_OFF LIGHT_SIDES_RESTORE_MODE: RESTORE_DEFAULT_OFF
LIGHT_INDIVIDUAL_RESTORE_MODE: RESTORE_DEFAULT_OFF LIGHT_INDIVIDUAL_RESTORE_MODE: RESTORE_DEFAULT_OFF
LIGHT_RELAYS_RESTORE_MODE: RESTORE_DEFAULT_OFF
globals: globals:
- id: gb_lights_1 - id: gb_lights_1
@@ -418,334 +417,32 @@ light:
from: 31 from: 31
to: 31 to: 31
# These lights are used to indicate relay's statuses
- &light_partition_relays
id: light_eu_rl_1_1_bottom
name: Light - Relay 1 of 1 (bottom)
platform: partition
internal: true
default_transition_length: ${default_transition_length}
restore_mode: ${LIGHT_RELAYS_RESTORE_MODE}
segments:
- id: light_full
from: 9
to: 9
- id: light_eu_rl_1_1_top
name: Light - Relay 1 of 1 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 23
- id: light_eu_rl_1_2_bottom
name: Light - Relay 1 of 2 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 11
to: 11
- id: light_eu_rl_1_2_top
name: Light - Relay 1 of 2 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 21
to: 21
- id: light_eu_rl_2_2_bottom
name: Light - Relay 2 of 2 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 7
to: 7
- id: light_eu_rl_2_2_top
name: Light - Relay 2 of 2 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 25
to: 25
- id: light_eu_rl_1_3_bottom
name: Light - Relay 1 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 12
to: 12
- id: light_eu_rl_1_3_top
name: Light - Relay 1 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 20
- id: light_eu_rl_2_3_bottom
name: Light - Relay 2 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 9
to: 9
- id: light_eu_rl_2_3_top
name: Light - Relay 2 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 23
- id: light_eu_rl_3_3_bottom
name: Light - Relay 3 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 6
- id: light_eu_rl_3_3_top
name: Light - Relay 3 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 26
to: 26
- id: light_eu_rl_1_4_bottom
name: Light - Relay 1 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 12
to: 12
- id: light_eu_rl_1_4_top
name: Light - Relay 1 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 20
- id: light_eu_rl_2_4_bottom
name: Light - Relay 2 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 10
to: 10
- id: light_eu_rl_2_4_top
name: Light - Relay 2 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 22
to: 22
- id: light_eu_rl_3_4_bottom
name: Light - Relay 3 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 8
to: 8
- id: light_eu_rl_3_4_top
name: Light - Relay 3 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 24
to: 24
- id: light_eu_rl_4_4_bottom
name: Light - Relay 4 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 6
- id: light_eu_rl_4_4_top
name: Light - Relay 4 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 26
to: 26
- id: light_us_rl_1_1_left
name: Light - Relay 1 of 1 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 24
- id: light_us_rl_1_1_right
name: Light - Relay 1 of 1 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 8
- id: light_us_rl_1_2_left
name: Light - Relay 1 of 2 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 24
- id: light_us_rl_1_2_right
name: Light - Relay 1 of 2 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 3
- id: light_us_rl_2_2_left
name: Light - Relay 2 of 2 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 19
- id: light_us_rl_2_2_right
name: Light - Relay 2 of 2 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 4
to: 8
- id: light_us_rl_1_3_left
name: Light - Relay 1 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 22
to: 23
- id: light_us_rl_1_3_right
name: Light - Relay 1 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 0
to: 1
- id: light_us_rl_2_3_left
name: Light - Relay 2 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 19
to: 20
- id: light_us_rl_2_3_right
name: Light - Relay 2 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 3
to: 4
- id: light_us_rl_3_3_left
name: Light - Relay 3 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 16
to: 17
- id: light_us_rl_3_3_right
name: Light - Relay 3 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 7
- id: light_us_rl_1_4_left
name: Light - Relay 1 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 24
- id: light_us_rl_1_4_right
name: Light - Relay 1 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 0
- id: light_us_rl_2_4_left
name: Light - Relay 2 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 21
to: 22
- id: light_us_rl_2_4_right
name: Light - Relay 2 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 1
to: 2
- id: light_us_rl_3_4_left
name: Light - Relay 3 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 17
to: 18
- id: light_us_rl_3_4_right
name: Light - Relay 3 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 5
to: 6
- id: light_us_rl_4_4_left
name: Light - Relay 4 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 16
- id: light_us_rl_4_4_right
name: Light - Relay 4 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 7
to: 8
script: script:
- id: !extend boot_initialize - id: !extend boot_initialize
then: then:
- wait_until:
condition:
- lambda: return sl_tx_model_format->active_index().has_value();
- lambda: return sl_tx_model_gang->active_index().has_value();
- lambda: |- - lambda: |-
const bool is_model_us = sl_tx_model_format->active_index().has_value() and light_28->set_internal(!id(is_us_model));
sl_tx_model_format->active_index().value() == 1; light_29->set_internal(!id(is_us_model));
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) ? light_30->set_internal(!id(is_us_model));
(sl_tx_model_gang->active_index().value() + 1) : 0; light_31->set_internal(!id(is_us_model));
if (num_gangs < 1 || num_gangs > 4) { light_eu->set_internal(id(is_us_model));
ESP_LOGE("core_hw_leds", "Invalid number of gangs: %" PRIu8, num_gangs); light_eu_bottom->set_internal(id(is_us_model));
return; light_eu_left->set_internal(id(is_us_model));
} light_eu_right->set_internal(id(is_us_model));
light_28->set_internal(!is_model_us); light_eu_top->set_internal(id(is_us_model));
light_29->set_internal(!is_model_us); light_us->set_internal(!id(is_us_model));
light_30->set_internal(!is_model_us); light_us_bottom->set_internal(!id(is_us_model));
light_31->set_internal(!is_model_us); light_us_left->set_internal(!id(is_us_model));
light_eu->set_internal(is_model_us); light_us_right->set_internal(!id(is_us_model));
light_eu_bottom->set_internal(is_model_us); light_us_top->set_internal(!id(is_us_model));
light_eu_left->set_internal(is_model_us);
light_eu_right->set_internal(is_model_us); // LED Group Assignment:
light_eu_top->set_internal(is_model_us); // - For US model: gb_lights_1 = left side LEDs, gb_lights_2 = right side LEDs
light_us->set_internal(!is_model_us); // - For EU model: gb_lights_1 = bottom LEDs, gb_lights_2 = top LEDs
light_us_bottom->set_internal(!is_model_us); // Gang configurations determine which LED segments are active
light_us_left->set_internal(!is_model_us); switch (id(gang_count)) {
light_us_right->set_internal(!is_model_us);
light_us_top->set_internal(!is_model_us);
switch (num_gangs) {
case 1: // 1 Gang case 1: // 1 Gang
if (is_model_us) { if (id(is_us_model)) {
id(gb_lights_1) = { light_us_rl_1_1_left }; id(gb_lights_1) = { light_us_rl_1_1_left };
id(gb_lights_2) = { light_us_rl_1_1_right }; id(gb_lights_2) = { light_us_rl_1_1_right };
} else { } else {
@@ -754,7 +451,7 @@ script:
} }
break; break;
case 2: // 2 Gang case 2: // 2 Gang
if (is_model_us) { if (id(is_us_model)) {
id(gb_lights_1) = { light_us_rl_1_2_left, light_us_rl_2_2_left }; id(gb_lights_1) = { light_us_rl_1_2_left, light_us_rl_2_2_left };
id(gb_lights_2) = { light_us_rl_1_2_right, light_us_rl_2_2_right }; id(gb_lights_2) = { light_us_rl_1_2_right, light_us_rl_2_2_right };
} else { } else {
@@ -763,7 +460,7 @@ script:
} }
break; break;
case 3: // 3 Gang case 3: // 3 Gang
if (is_model_us) { if (id(is_us_model)) {
id(gb_lights_1) = { light_us_rl_1_3_left, light_us_rl_2_3_left, light_us_rl_3_3_left }; id(gb_lights_1) = { light_us_rl_1_3_left, light_us_rl_2_3_left, light_us_rl_3_3_left };
id(gb_lights_2) = { light_us_rl_1_3_right, light_us_rl_2_3_right, light_us_rl_3_3_right }; id(gb_lights_2) = { light_us_rl_1_3_right, light_us_rl_2_3_right, light_us_rl_3_3_right };
} else { } else {
@@ -772,7 +469,7 @@ script:
} }
break; break;
case 4: // 4 Gang case 4: // 4 Gang
if (is_model_us) { if (id(is_us_model)) {
id(gb_lights_1) = { light_us_rl_1_4_left, light_us_rl_2_4_left, id(gb_lights_1) = { light_us_rl_1_4_left, light_us_rl_2_4_left,
light_us_rl_3_4_left, light_us_rl_4_4_left }; light_us_rl_3_4_left, light_us_rl_4_4_left };
id(gb_lights_2) = { light_us_rl_1_4_right, light_us_rl_2_4_right, id(gb_lights_2) = { light_us_rl_1_4_right, light_us_rl_2_4_right,
@@ -798,10 +495,12 @@ script:
static const uint32_t LIGHT_TRANSITION_TURN_OFF = ${LIGHT_TRANSITION_TURN_OFF}; static const uint32_t LIGHT_TRANSITION_TURN_OFF = ${LIGHT_TRANSITION_TURN_OFF};
static const uint8_t LIGHT_BRIGHTNESS_TURN_ON = ${LIGHT_BRIGHTNESS_TURN_ON}; static const uint8_t LIGHT_BRIGHTNESS_TURN_ON = ${LIGHT_BRIGHTNESS_TURN_ON};
const bool is_model_us = sl_tx_model_format->active_index().has_value() and const std::string light_mode_group_1 = id(is_us_model)
sl_tx_model_format->active_index().value() == 1; ? "${LIGHT_MODE_LEFT_TEXT}"
const std::string light_mode_group_1 = is_model_us ? "${LIGHT_MODE_LEFT_TEXT}" : "${LIGHT_MODE_BOTTOM_TEXT}"; : "${LIGHT_MODE_BOTTOM_TEXT}";
const std::string light_mode_group_2 = is_model_us ? "${LIGHT_MODE_RIGHT_TEXT}" : "${LIGHT_MODE_TOP_TEXT}"; const std::string light_mode_group_2 = id(is_us_model)
? "${LIGHT_MODE_RIGHT_TEXT}"
: "${LIGHT_MODE_TOP_TEXT}";
switch (light_group) { switch (light_group) {
case 1: case 1:

View File

@@ -15,13 +15,28 @@ substitutions:
RELAY_MODE_TEXT_SWITCH: "Switch" RELAY_MODE_TEXT_SWITCH: "Switch"
RELAY_MODE_TEXT_LIGHT: "Light" RELAY_MODE_TEXT_LIGHT: "Light"
RELAY_MODE_TEXT_NOT_USED: "Not in use" RELAY_MODE_TEXT_NOT_USED: "Not in use"
RELAY_RESTORE_MODE: RESTORE_DEFAULT_OFF RELAY_RESTORE_MODE: RESTORE_DEFAULT_OFF
LIGHT_RELAYS_RESTORE_MODE: RESTORE_DEFAULT_OFF
globals: globals:
- id: boot_initialization_relays - id: boot_initialization_relays
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: 'false'
- id: boot_initialization_relays_light_modes
type: bool
restore_value: false
initial_value: 'false'
- id: boot_initialization_relays_relay_leds
type: bool
restore_value: false
initial_value: 'false'
- id: boot_initialization_relays_relay_modes
type: bool
restore_value: false
initial_value: 'false'
light: light:
# These lights are used for the physical relays to be shown as lights # These lights are used for the physical relays to be shown as lights
@@ -103,19 +118,312 @@ light:
then: then:
- switch.turn_off: sw_relay_4 - switch.turn_off: sw_relay_4
# These lights are used to indicate relay's statuses
- &light_partition_relays
id: light_eu_rl_1_1_bottom
name: Light - Relay 1 of 1 (bottom)
platform: partition
internal: true
disabled_by_default: true
default_transition_length: ${default_transition_length}
restore_mode: ${LIGHT_RELAYS_RESTORE_MODE}
segments:
- id: light_full
from: 9
to: 9
- id: light_eu_rl_1_1_top
name: Light - Relay 1 of 1 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 23
- id: light_eu_rl_1_2_bottom
name: Light - Relay 1 of 2 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 11
to: 11
- id: light_eu_rl_1_2_top
name: Light - Relay 1 of 2 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 21
to: 21
- id: light_eu_rl_2_2_bottom
name: Light - Relay 2 of 2 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 7
to: 7
- id: light_eu_rl_2_2_top
name: Light - Relay 2 of 2 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 25
to: 25
- id: light_eu_rl_1_3_bottom
name: Light - Relay 1 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 12
to: 12
- id: light_eu_rl_1_3_top
name: Light - Relay 1 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 20
- id: light_eu_rl_2_3_bottom
name: Light - Relay 2 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 9
to: 9
- id: light_eu_rl_2_3_top
name: Light - Relay 2 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 23
- id: light_eu_rl_3_3_bottom
name: Light - Relay 3 of 3 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 6
- id: light_eu_rl_3_3_top
name: Light - Relay 3 of 3 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 26
to: 26
- id: light_eu_rl_1_4_bottom
name: Light - Relay 1 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 12
to: 12
- id: light_eu_rl_1_4_top
name: Light - Relay 1 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 20
- id: light_eu_rl_2_4_bottom
name: Light - Relay 2 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 10
to: 10
- id: light_eu_rl_2_4_top
name: Light - Relay 2 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 22
to: 22
- id: light_eu_rl_3_4_bottom
name: Light - Relay 3 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 8
to: 8
- id: light_eu_rl_3_4_top
name: Light - Relay 3 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 24
to: 24
- id: light_eu_rl_4_4_bottom
name: Light - Relay 4 of 4 (bottom)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 6
- id: light_eu_rl_4_4_top
name: Light - Relay 4 of 4 (top)
<<: *light_partition_relays
segments:
- id: light_full
from: 26
to: 26
- id: light_us_rl_1_1_left
name: Light - Relay 1 of 1 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 24
- id: light_us_rl_1_1_right
name: Light - Relay 1 of 1 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 8
- id: light_us_rl_1_2_left
name: Light - Relay 1 of 2 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 20
to: 24
- id: light_us_rl_1_2_right
name: Light - Relay 1 of 2 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 3
- id: light_us_rl_2_2_left
name: Light - Relay 2 of 2 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 19
- id: light_us_rl_2_2_right
name: Light - Relay 2 of 2 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 4
to: 8
- id: light_us_rl_1_3_left
name: Light - Relay 1 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 22
to: 23
- id: light_us_rl_1_3_right
name: Light - Relay 1 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 0
to: 1
- id: light_us_rl_2_3_left
name: Light - Relay 2 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 19
to: 20
- id: light_us_rl_2_3_right
name: Light - Relay 2 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 3
to: 4
- id: light_us_rl_3_3_left
name: Light - Relay 3 of 3 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 16
to: 17
- id: light_us_rl_3_3_right
name: Light - Relay 3 of 3 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 6
to: 7
- id: light_us_rl_1_4_left
name: Light - Relay 1 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 23
to: 24
- id: light_us_rl_1_4_right
name: Light - Relay 1 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 31
to: 31
- id: light_full
from: 0
to: 0
- id: light_us_rl_2_4_left
name: Light - Relay 2 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 21
to: 22
- id: light_us_rl_2_4_right
name: Light - Relay 2 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 1
to: 2
- id: light_us_rl_3_4_left
name: Light - Relay 3 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 17
to: 18
- id: light_us_rl_3_4_right
name: Light - Relay 3 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 5
to: 6
- id: light_us_rl_4_4_left
name: Light - Relay 4 of 4 (left)
<<: *light_partition_relays
segments:
- id: light_full
from: 15
to: 16
- id: light_us_rl_4_4_right
name: Light - Relay 4 of 4 (right)
<<: *light_partition_relays
segments:
- id: light_full
from: 7
to: 8
output: output:
- id: output_relay_1 - id: output_relay_1
platform: gpio platform: gpio
pin: GPIO18 pin: GPIO18
- id: output_relay_2 - id: output_relay_2
platform: gpio platform: gpio
pin: GPIO17 pin: GPIO17
- id: output_relay_3 - id: output_relay_3
platform: gpio platform: gpio
pin: GPIO27 pin: GPIO27
- id: output_relay_4 - id: output_relay_4
platform: gpio platform: gpio
pin: GPIO23 pin: GPIO23
@@ -128,31 +436,112 @@ script:
- id: boot_initialize_relays - id: boot_initialize_relays
mode: restart mode: restart
then: then:
- script.execute: boot_initialize_relays_light_modes
- script.execute: boot_initialize_relays_relay_leds
- script.execute: boot_initialize_relays_relay_modes
- script.wait: boot_initialize_relays_light_modes
- script.wait: boot_initialize_relays_relay_leds
- script.wait: boot_initialize_relays_relay_modes
- wait_until: - wait_until:
condition: condition:
- lambda: return sl_tx_model_format->active_index().has_value(); - lambda: return id(boot_initialization_relays_light_modes);
- lambda: return sl_tx_model_gang->active_index().has_value(); - lambda: return id(boot_initialization_relays_relay_leds);
- lambda: return id(boot_initialization_relays_relay_modes);
- globals.set:
id: boot_initialization_relays
value: 'true'
- id: boot_initialize_relays_light_modes
mode: restart
then:
- lambda: |- - lambda: |-
const bool is_model_us = sl_tx_model_format->active_index().has_value() and // EU light modes
sl_tx_model_format->active_index().value() == 1; sl_relay_1_light_mode_eu->set_internal(id(is_us_model) or id(gang_count) < 1);
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) ? sl_relay_2_light_mode_eu->set_internal(id(is_us_model) or id(gang_count) < 2);
(sl_tx_model_gang->active_index().value() + 1) : 0; sl_relay_3_light_mode_eu->set_internal(id(is_us_model) or id(gang_count) < 3);
if (num_gangs < 1 || num_gangs > 4) { sl_relay_4_light_mode_eu->set_internal(id(is_us_model) or id(gang_count) < 4);
ESP_LOGE("core_hw_relays", "Invalid number of gangs: %" PRIu8, num_gangs);
return; // US light modes
} sl_relay_1_light_mode_us->set_internal(!id(is_us_model) or id(gang_count) < 1);
sl_relay_1_mode->set_internal(num_gangs < 1); sl_relay_2_light_mode_us->set_internal(!id(is_us_model) or id(gang_count) < 2);
sl_relay_1_light_mode_eu->set_internal(is_model_us or num_gangs < 1); sl_relay_3_light_mode_us->set_internal(!id(is_us_model) or id(gang_count) < 3);
sl_relay_1_light_mode_us->set_internal(!is_model_us or num_gangs < 1); sl_relay_4_light_mode_us->set_internal(!id(is_us_model) or id(gang_count) < 4);
sl_relay_2_mode->set_internal(num_gangs < 2);
sl_relay_2_light_mode_eu->set_internal(is_model_us or num_gangs < 2); // Set this section of initialization as completed
sl_relay_2_light_mode_us->set_internal(!is_model_us or num_gangs < 2); id(boot_initialization_relays_light_modes) = true;
sl_relay_3_mode->set_internal(num_gangs < 3);
sl_relay_3_light_mode_eu->set_internal(is_model_us or num_gangs < 3); - id: boot_initialize_relays_relay_leds
sl_relay_3_light_mode_us->set_internal(!is_model_us or num_gangs < 3); mode: restart
sl_relay_4_mode->set_internal(num_gangs < 4); then:
sl_relay_4_light_mode_eu->set_internal(is_model_us or num_gangs < 4); - lambda: |-
sl_relay_4_light_mode_us->set_internal(!is_model_us or num_gangs < 4); const bool set_internal = not sw_expose_relays_leds_to_ha->state;
// EU model LEDs
// EU model - 1 Gang
light_eu_rl_1_1_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 1);
light_eu_rl_1_1_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 1);
// EU model - 2 Gang
light_eu_rl_1_2_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 2);
light_eu_rl_1_2_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 2);
light_eu_rl_2_2_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 2);
light_eu_rl_2_2_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 2);
// EU model - 3 Gang
light_eu_rl_1_3_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
light_eu_rl_1_3_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
light_eu_rl_2_3_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
light_eu_rl_2_3_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
light_eu_rl_3_3_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
light_eu_rl_3_3_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 3);
// EU model - 4 Gang
light_eu_rl_1_4_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_1_4_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_2_4_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_2_4_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_3_4_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_3_4_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_4_4_bottom->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
light_eu_rl_4_4_top->set_internal(set_internal or id(is_us_model) or id(gang_count) != 4);
// US model LEDs
// US model - 1 Gang
light_us_rl_1_1_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 1);
light_us_rl_1_1_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 1);
// US model - 2 Gang
light_us_rl_1_2_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 2);
light_us_rl_1_2_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 2);
light_us_rl_2_2_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 2);
light_us_rl_2_2_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 2);
// US model - 3 Gang
light_us_rl_1_3_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
light_us_rl_1_3_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
light_us_rl_2_3_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
light_us_rl_2_3_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
light_us_rl_3_3_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
light_us_rl_3_3_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 3);
// US model - 4 Gang
light_us_rl_1_4_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_1_4_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_2_4_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_2_4_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_3_4_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_3_4_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_4_4_left->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
light_us_rl_4_4_right->set_internal(set_internal or !id(is_us_model) or id(gang_count) != 4);
// Set this section of initialization as completed
id(boot_initialization_relays_relay_leds) = true;
- id: boot_initialize_relays_relay_modes
mode: restart
then:
- lambda: |-
// Set selector internal based on the model (num of relays)
sl_relay_1_mode->set_internal(id(gang_count) < 1);
sl_relay_2_mode->set_internal(id(gang_count) < 2);
sl_relay_3_mode->set_internal(id(gang_count) < 3);
sl_relay_4_mode->set_internal(id(gang_count) < 4);
// Set indicator (either switch or light) visible on Home Assistant
auto relay_mode_index = sl_relay_1_mode->active_index(); auto relay_mode_index = sl_relay_1_mode->active_index();
if (relay_mode_index.has_value()) { if (relay_mode_index.has_value()) {
light_output_1->set_internal(false or relay_mode_index.value() != 1); light_output_1->set_internal(false or relay_mode_index.value() != 1);
@@ -160,20 +549,22 @@ script:
} }
relay_mode_index = sl_relay_2_mode->active_index(); relay_mode_index = sl_relay_2_mode->active_index();
if (relay_mode_index.has_value()) { if (relay_mode_index.has_value()) {
light_output_2->set_internal(num_gangs < 2 or relay_mode_index.value() != 1); light_output_2->set_internal(id(gang_count) < 2 or relay_mode_index.value() != 1);
sw_relay_2->set_internal(num_gangs < 2 or relay_mode_index.value() != 0); sw_relay_2->set_internal(id(gang_count) < 2 or relay_mode_index.value() != 0);
} }
relay_mode_index = sl_relay_3_mode->active_index(); relay_mode_index = sl_relay_3_mode->active_index();
if (relay_mode_index.has_value()) { if (relay_mode_index.has_value()) {
light_output_3->set_internal(num_gangs < 3 or relay_mode_index.value() != 1); light_output_3->set_internal(id(gang_count) < 3 or relay_mode_index.value() != 1);
sw_relay_3->set_internal(num_gangs < 3 or relay_mode_index.value() != 0); sw_relay_3->set_internal(id(gang_count) < 3 or relay_mode_index.value() != 0);
} }
relay_mode_index = sl_relay_4_mode->active_index(); relay_mode_index = sl_relay_4_mode->active_index();
if (relay_mode_index.has_value()) { if (relay_mode_index.has_value()) {
light_output_4->set_internal(num_gangs < 4 or relay_mode_index.value() != 1); light_output_4->set_internal(id(gang_count) < 4 or relay_mode_index.value() != 1);
sw_relay_4->set_internal(num_gangs < 4 or relay_mode_index.value() != 0); sw_relay_4->set_internal(id(gang_count) < 4 or relay_mode_index.value() != 0);
} }
id(boot_initialization_relays) = true;
// Set this section of initialization as completed
id(boot_initialization_relays_relay_modes) = true;
- id: !extend button_click_event - id: !extend button_click_event
then: then:
@@ -247,28 +638,20 @@ script:
mode: restart mode: restart
then: then:
- script.wait: boot_initialize_relays - script.wait: boot_initialize_relays
- wait_until:
condition:
- lambda: return id(boot_initialization_relays);
- lambda: |- - lambda: |-
const bool is_model_us = sl_tx_model_format->active_index().has_value() and if (not id(boot_initialization_relays)) {
sl_tx_model_format->active_index().value() == 1; ESP_LOGW("core_hw_relays", "Relays not initialized yet");
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) if (not boot_initialize_relays->is_running())
? (sl_tx_model_gang->active_index().value() + 1) boot_initialize_relays->execute();
: 0;
if (num_gangs < 1 || num_gangs > 4) {
ESP_LOGE("core_hw_relays", "Invalid number of gangs: %" PRIu8, num_gangs);
return; return;
} }
for (uint8_t i = 0; i < id(gang_count); i++) {
for (uint8_t i = 0; i < num_gangs; i++) {
bool relay_state = false; bool relay_state = false;
std::string light_mode; std::string light_mode;
const std::string light_mode_group_1 = is_model_us const std::string light_mode_group_1 = id(is_us_model)
? "${LIGHT_MODE_LEFT_TEXT}" ? "${LIGHT_MODE_LEFT_TEXT}"
: "${LIGHT_MODE_BOTTOM_TEXT}"; : "${LIGHT_MODE_BOTTOM_TEXT}";
const std::string light_mode_group_2 = is_model_us const std::string light_mode_group_2 = id(is_us_model)
? "${LIGHT_MODE_RIGHT_TEXT}" ? "${LIGHT_MODE_RIGHT_TEXT}"
: "${LIGHT_MODE_TOP_TEXT}"; : "${LIGHT_MODE_TOP_TEXT}";
@@ -276,25 +659,25 @@ script:
switch (i) { switch (i) {
case 0: case 0:
relay_state = id(sw_relay_1).state; relay_state = id(sw_relay_1).state;
light_mode = is_model_us light_mode = id(is_us_model)
? id(sl_relay_1_light_mode_us)->state ? id(sl_relay_1_light_mode_us)->state
: id(sl_relay_1_light_mode_eu)->state; : id(sl_relay_1_light_mode_eu)->state;
break; break;
case 1: case 1:
relay_state = id(sw_relay_2).state; relay_state = id(sw_relay_2).state;
light_mode = is_model_us light_mode = id(is_us_model)
? id(sl_relay_2_light_mode_us)->state ? id(sl_relay_2_light_mode_us)->state
: id(sl_relay_2_light_mode_eu)->state; : id(sl_relay_2_light_mode_eu)->state;
break; break;
case 2: case 2:
relay_state = id(sw_relay_3).state; relay_state = id(sw_relay_3).state;
light_mode = is_model_us light_mode = id(is_us_model)
? id(sl_relay_3_light_mode_us)->state ? id(sl_relay_3_light_mode_us)->state
: id(sl_relay_3_light_mode_eu)->state; : id(sl_relay_3_light_mode_eu)->state;
break; break;
case 3: case 3:
relay_state = id(sw_relay_4).state; relay_state = id(sw_relay_4).state;
light_mode = is_model_us light_mode = id(is_us_model)
? id(sl_relay_4_light_mode_us)->state ? id(sl_relay_4_light_mode_us)->state
: id(sl_relay_4_light_mode_eu)->state; : id(sl_relay_4_light_mode_eu)->state;
break; break;
@@ -333,20 +716,40 @@ select:
entity_category: config entity_category: config
disabled_by_default: false disabled_by_default: false
icon: mdi:dip-switch icon: mdi:dip-switch
on_value:
then:
- binary_sensor.template.publish:
id: bs_pending_restart
state: true
- id: sl_relay_2_mode - id: sl_relay_2_mode
name: Relay 2 display mode name: Relay 2 display mode
<<: *relay_select_mode_base <<: *relay_select_mode_base
- id: sl_relay_3_mode - id: sl_relay_3_mode
name: Relay 3 display mode name: Relay 3 display mode
<<: *relay_select_mode_base <<: *relay_select_mode_base
- id: sl_relay_4_mode - id: sl_relay_4_mode
name: Relay 4 display mode name: Relay 4 display mode
<<: *relay_select_mode_base <<: *relay_select_mode_base
switch: switch:
- id: sw_expose_relays_leds_to_ha
name: Expose Relay's LEDs to Home Assistant
platform: template
restore_mode: RESTORE_DEFAULT_OFF
optimistic: true
internal: false
entity_category: config
on_turn_on:
then:
- binary_sensor.template.publish:
id: bs_pending_restart
state: true
on_turn_off:
then:
- binary_sensor.template.publish:
id: bs_pending_restart
state: true
- id: sw_relay_1 - id: sw_relay_1
name: Relay 1 name: Relay 1
output: output_relay_1 output: output_relay_1
@@ -369,7 +772,6 @@ switch:
- light.is_on: light_output_1 - light.is_on: light_output_1
then: then:
- light.turn_off: light_output_1 - light.turn_off: light_output_1
- id: sw_relay_2 - id: sw_relay_2
name: Relay 2 name: Relay 2
output: output_relay_2 output: output_relay_2
@@ -392,7 +794,6 @@ switch:
- light.is_on: light_output_2 - light.is_on: light_output_2
then: then:
- light.turn_off: light_output_2 - light.turn_off: light_output_2
- id: sw_relay_3 - id: sw_relay_3
name: Relay 3 name: Relay 3
output: output_relay_3 output: output_relay_3
@@ -415,7 +816,6 @@ switch:
- light.is_on: light_output_3 - light.is_on: light_output_3
then: then:
- light.turn_off: light_output_3 - light.turn_off: light_output_3
- id: sw_relay_4 - id: sw_relay_4
name: Relay 4 name: Relay 4
output: output_relay_4 output: output_relay_4

View File

@@ -2,7 +2,7 @@
##### TX Ultimate Easy for ESPHome ##### ##### TX Ultimate Easy for ESPHome #####
##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy ##### ##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy #####
#################################################################################################### ####################################################################################################
##### Purpose: ESPHome Core - Hardware - Speaker ##### ##### Purpose: ESPHome Core - Hardware - Media player #####
#################################################################################################### ####################################################################################################
##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo ##### ##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo #####
#################################################################################################### ####################################################################################################
@@ -17,8 +17,8 @@ i2s_audio:
i2s_lrclk_pin: GPIO4 i2s_lrclk_pin: GPIO4
media_player: media_player:
- id: mp_speaker - id: mp_media_player
name: Speaker name: Media Player
internal: false internal: false
platform: i2s_audio platform: i2s_audio
i2s_dout_pin: GPIO15 i2s_dout_pin: GPIO15

View File

@@ -256,13 +256,8 @@ script:
- id: boot_initialize_touch_gang - id: boot_initialize_touch_gang
mode: restart mode: restart
then: then:
- wait_until:
condition:
- lambda: return sl_tx_model_gang->active_index().has_value();
- lambda: |- - lambda: |-
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) ? tx_ultimate->set_gang_count(id(gang_count));
(sl_tx_model_gang->active_index().value() + 1) : 0;
tx_ultimate->set_gang_count(num_gangs);
bs_button_1_click_event->publish_state(false); bs_button_1_click_event->publish_state(false);
bs_button_2_click_event->publish_state(false); bs_button_2_click_event->publish_state(false);
bs_button_3_click_event->publish_state(false); bs_button_3_click_event->publish_state(false);
@@ -275,18 +270,18 @@ script:
bs_button_2_long_press_event->publish_state(false); bs_button_2_long_press_event->publish_state(false);
bs_button_3_long_press_event->publish_state(false); bs_button_3_long_press_event->publish_state(false);
bs_button_4_long_press_event->publish_state(false); bs_button_4_long_press_event->publish_state(false);
bs_button_1_click_event->set_internal(num_gangs < 1); bs_button_1_click_event->set_internal(id(gang_count) < 1);
bs_button_2_click_event->set_internal(num_gangs < 2); bs_button_2_click_event->set_internal(id(gang_count) < 2);
bs_button_3_click_event->set_internal(num_gangs < 3); bs_button_3_click_event->set_internal(id(gang_count) < 3);
bs_button_4_click_event->set_internal(num_gangs < 4); bs_button_4_click_event->set_internal(id(gang_count) < 4);
bs_button_1_double_click_event->set_internal(num_gangs < 1); bs_button_1_double_click_event->set_internal(id(gang_count) < 1);
bs_button_2_double_click_event->set_internal(num_gangs < 2); bs_button_2_double_click_event->set_internal(id(gang_count) < 2);
bs_button_3_double_click_event->set_internal(num_gangs < 3); bs_button_3_double_click_event->set_internal(id(gang_count) < 3);
bs_button_4_double_click_event->set_internal(num_gangs < 4); bs_button_4_double_click_event->set_internal(id(gang_count) < 4);
bs_button_1_long_press_event->set_internal(num_gangs < 1); bs_button_1_long_press_event->set_internal(id(gang_count) < 1);
bs_button_2_long_press_event->set_internal(num_gangs < 2); bs_button_2_long_press_event->set_internal(id(gang_count) < 2);
bs_button_3_long_press_event->set_internal(num_gangs < 3); bs_button_3_long_press_event->set_internal(id(gang_count) < 3);
bs_button_4_long_press_event->set_internal(num_gangs < 4); bs_button_4_long_press_event->set_internal(id(gang_count) < 4);
- id: touch_on_multi_touch_release - id: touch_on_multi_touch_release
mode: restart mode: restart