Optimize nvs even more with dual light attributes saving

This commit is contained in:
Edward Firmo
2025-08-06 16:30:40 +02:00
parent 6a1a5d5ae2
commit 4634b650d9
6 changed files with 729 additions and 163 deletions

View File

@@ -30,6 +30,7 @@ substitutions:
LIGHT_INDIVIDUAL_RESTORE_MODE: RESTORE_DEFAULT_OFF
LIGHT_ATTRS_DEFAULT: '0x64FFFFFF' # brightness=100, RGB=255,255,255
LIGHT_DUAL_ATTRS_DEFAULT: '0x64FFFFFF64FFFFFF' # Both lights: brightness=100, RGB=255,255,255
TAG_CORE_HW_LEDS: core.hw.leds
@@ -559,6 +560,22 @@ script:
ESP_LOGI("${TAG_CORE_HW_LEDS}", "Restored light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
attrs.brightness, attrs.red, attrs.green, attrs.blue);
- id: light_attributes_restore_dual
mode: parallel
parameters:
light_ptr: light::LightState*
attr_global_ptr: uint64_t*
group_index: uint8_t # 1 or 2
then:
- lambda: |-
auto attrs_pair = tx_ultimate_easy::unpack_dual_light_attributes(*attr_global_ptr);
tx_ultimate_easy::LightAttributes attrs = (group_index == 1) ? attrs_pair.first : attrs_pair.second;
auto call = light_ptr->make_call();
call.set_brightness(attrs.brightness / 100.0f);
call.set_rgb(attrs.red / 255.0f, attrs.green / 255.0f, attrs.blue / 255.0f);
call.perform();
- id: light_attributes_save
mode: parallel
parameters:
@@ -578,6 +595,32 @@ script:
ESP_LOGD("${TAG_CORE_HW_LEDS}", "Saved light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
attrs.brightness, attrs.red, attrs.green, attrs.blue);
- id: light_attributes_save_dual
mode: parallel
parameters:
light_ptr: light::LightState*
attr_global_ptr: uint64_t*
group_index: uint8_t # 1 or 2 (which group within the dual pack)
then:
- lambda: |-
auto current = light_ptr->current_values;
tx_ultimate_easy::LightAttributes new_attrs = {
.brightness = uint8_t(current.get_brightness() * 100.0f),
.red = uint8_t(current.get_red() * 255.0f),
.green = uint8_t(current.get_green() * 255.0f),
.blue = uint8_t(current.get_blue() * 255.0f)
};
// Unpack existing dual attributes
auto existing = tx_ultimate_easy::unpack_dual_light_attributes(*attr_global_ptr);
// Update the appropriate group
if (group_index == 1) {
*attr_global_ptr = tx_ultimate_easy::pack_dual_light_attributes(new_attrs, existing.second);
} else {
*attr_global_ptr = tx_ultimate_easy::pack_dual_light_attributes(existing.first, new_attrs);
}
select:
# EU relay light mode template
- &relay_light_mode_eu

View File

@@ -69,89 +69,29 @@ globals:
initial_value: '0' # All switches default to OFF
# Bit layout: [unused(3)][sw_relay4][sw_relay3][sw_relay2][sw_relay1][sw_expose_leds]
- &global_attr_light
id: attr_light_eu_rl_1_1_bottom
type: uint32_t
- &global_attr_dual_light
id: attr_light_rl_1_1_both # 1-gang: relay 1, both groups
type: uint64_t
restore_value: true
initial_value: '${LIGHT_ATTRS_DEFAULT}'
- id: attr_light_eu_rl_1_1_top
<<: *global_attr_light
- id: attr_light_eu_rl_1_2_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_1_2_top
<<: *global_attr_light
- id: attr_light_eu_rl_2_2_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_2_2_top
<<: *global_attr_light
- id: attr_light_eu_rl_1_3_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_1_3_top
<<: *global_attr_light
- id: attr_light_eu_rl_2_3_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_2_3_top
<<: *global_attr_light
- id: attr_light_eu_rl_3_3_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_3_3_top
<<: *global_attr_light
- id: attr_light_eu_rl_1_4_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_1_4_top
<<: *global_attr_light
- id: attr_light_eu_rl_2_4_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_2_4_top
<<: *global_attr_light
- id: attr_light_eu_rl_3_4_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_3_4_top
<<: *global_attr_light
- id: attr_light_eu_rl_4_4_bottom
<<: *global_attr_light
- id: attr_light_eu_rl_4_4_top
<<: *global_attr_light
- id: attr_light_us_rl_1_1_left
<<: *global_attr_light
- id: attr_light_us_rl_1_1_right
<<: *global_attr_light
- id: attr_light_us_rl_1_2_left
<<: *global_attr_light
- id: attr_light_us_rl_1_2_right
<<: *global_attr_light
- id: attr_light_us_rl_2_2_left
<<: *global_attr_light
- id: attr_light_us_rl_2_2_right
<<: *global_attr_light
- id: attr_light_us_rl_1_3_left
<<: *global_attr_light
- id: attr_light_us_rl_1_3_right
<<: *global_attr_light
- id: attr_light_us_rl_2_3_left
<<: *global_attr_light
- id: attr_light_us_rl_2_3_right
<<: *global_attr_light
- id: attr_light_us_rl_3_3_left
<<: *global_attr_light
- id: attr_light_us_rl_3_3_right
<<: *global_attr_light
- id: attr_light_us_rl_1_4_left
<<: *global_attr_light
- id: attr_light_us_rl_1_4_right
<<: *global_attr_light
- id: attr_light_us_rl_2_4_left
<<: *global_attr_light
- id: attr_light_us_rl_2_4_right
<<: *global_attr_light
- id: attr_light_us_rl_3_4_left
<<: *global_attr_light
- id: attr_light_us_rl_3_4_right
<<: *global_attr_light
- id: attr_light_us_rl_4_4_left
<<: *global_attr_light
- id: attr_light_us_rl_4_4_right
<<: *global_attr_light
initial_value: '${LIGHT_DUAL_ATTRS_DEFAULT}'
- id: attr_light_rl_1_2_both # 2-gang: relay 1, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_2_2_both # 2-gang: relay 2, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_1_3_both # 3-gang: relay 1, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_2_3_both # 3-gang: relay 2, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_3_3_both # 3-gang: relay 3, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_1_4_both # 4-gang: relay 1, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_2_4_both # 4-gang: relay 2, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_3_4_both # 4-gang: relay 3, both groups
<<: *global_attr_dual_light
- id: attr_light_rl_4_4_both # 4-gang: relay 4, both groups
<<: *global_attr_dual_light
light:
# These lights are used for the physical relays to be shown as lights
@@ -248,9 +188,10 @@ light:
to: 9
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_1_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_1_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_1_1_both);
group_index: 1
- id: light_eu_rl_1_1_top
name: Light - Relay 1 of 1 (top)
<<: *light_partition_relays
@@ -260,9 +201,10 @@ light:
to: 23
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_1_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_1_top);
attr_global_ptr: !lambda return &id(attr_light_rl_1_1_both);
group_index: 2
- id: light_eu_rl_1_2_bottom
name: Light - Relay 1 of 2 (bottom)
<<: *light_partition_relays
@@ -272,9 +214,10 @@ light:
to: 11
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_2_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_2_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_1_2_both);
group_index: 1
- id: light_eu_rl_1_2_top
name: Light - Relay 1 of 2 (top)
<<: *light_partition_relays
@@ -284,9 +227,10 @@ light:
to: 21
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_2_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_2_top);
attr_global_ptr: !lambda return &id(attr_light_rl_1_2_both);
group_index: 2
- id: light_eu_rl_2_2_bottom
name: Light - Relay 2 of 2 (bottom)
<<: *light_partition_relays
@@ -296,9 +240,10 @@ light:
to: 7
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_2_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_2_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_2_2_both);
group_index: 1
- id: light_eu_rl_2_2_top
name: Light - Relay 2 of 2 (top)
<<: *light_partition_relays
@@ -308,9 +253,10 @@ light:
to: 25
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_2_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_2_top);
attr_global_ptr: !lambda return &id(attr_light_rl_2_2_both);
group_index: 2
- id: light_eu_rl_1_3_bottom
name: Light - Relay 1 of 3 (bottom)
<<: *light_partition_relays
@@ -320,9 +266,10 @@ light:
to: 12
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_1_3_both);
group_index: 1
- id: light_eu_rl_1_3_top
name: Light - Relay 1 of 3 (top)
<<: *light_partition_relays
@@ -332,9 +279,10 @@ light:
to: 20
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_3_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_3_top);
attr_global_ptr: !lambda return &id(attr_light_rl_1_3_both);
group_index: 2
- id: light_eu_rl_2_3_bottom
name: Light - Relay 2 of 3 (bottom)
<<: *light_partition_relays
@@ -344,9 +292,10 @@ light:
to: 9
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_2_3_both);
group_index: 1
- id: light_eu_rl_2_3_top
name: Light - Relay 2 of 3 (top)
<<: *light_partition_relays
@@ -356,9 +305,10 @@ light:
to: 23
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_3_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_3_top);
attr_global_ptr: !lambda return &id(attr_light_rl_2_3_both);
group_index: 2
- id: light_eu_rl_3_3_bottom
name: Light - Relay 3 of 3 (bottom)
<<: *light_partition_relays
@@ -368,9 +318,10 @@ light:
to: 6
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_3_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_3_3_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_3_3_both);
group_index: 1
- id: light_eu_rl_3_3_top
name: Light - Relay 3 of 3 (top)
<<: *light_partition_relays
@@ -380,9 +331,10 @@ light:
to: 26
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_3_3_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_3_3_top);
attr_global_ptr: !lambda return &id(attr_light_rl_3_3_both);
group_index: 2
- id: light_eu_rl_1_4_bottom
name: Light - Relay 1 of 4 (bottom)
<<: *light_partition_relays
@@ -392,9 +344,10 @@ light:
to: 12
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_1_4_both);
group_index: 1
- id: light_eu_rl_1_4_top
name: Light - Relay 1 of 4 (top)
<<: *light_partition_relays
@@ -404,9 +357,10 @@ light:
to: 20
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_1_4_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_1_4_top);
attr_global_ptr: !lambda return &id(attr_light_rl_1_4_both);
group_index: 2
- id: light_eu_rl_2_4_bottom
name: Light - Relay 2 of 4 (bottom)
<<: *light_partition_relays
@@ -416,9 +370,10 @@ light:
to: 10
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_2_4_both);
group_index: 1
- id: light_eu_rl_2_4_top
name: Light - Relay 2 of 4 (top)
<<: *light_partition_relays
@@ -428,9 +383,10 @@ light:
to: 22
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_2_4_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_2_4_top);
attr_global_ptr: !lambda return &id(attr_light_rl_2_4_both);
group_index: 2
- id: light_eu_rl_3_4_bottom
name: Light - Relay 3 of 4 (bottom)
<<: *light_partition_relays
@@ -440,9 +396,10 @@ light:
to: 8
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_3_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_3_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_3_4_both);
group_index: 1
- id: light_eu_rl_3_4_top
name: Light - Relay 3 of 4 (top)
<<: *light_partition_relays
@@ -452,9 +409,10 @@ light:
to: 24
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_3_4_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_3_4_top);
attr_global_ptr: !lambda return &id(attr_light_rl_3_4_both);
group_index: 2
- id: light_eu_rl_4_4_bottom
name: Light - Relay 4 of 4 (bottom)
<<: *light_partition_relays
@@ -464,9 +422,10 @@ light:
to: 6
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_4_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_4_4_bottom);
attr_global_ptr: !lambda return &id(attr_light_rl_4_4_both);
group_index: 1
- id: light_eu_rl_4_4_top
name: Light - Relay 4 of 4 (top)
<<: *light_partition_relays
@@ -476,9 +435,10 @@ light:
to: 26
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_eu_rl_4_4_top);
attr_global_ptr: !lambda return &id(attr_light_eu_rl_4_4_top);
attr_global_ptr: !lambda return &id(attr_light_rl_4_4_both);
group_index: 2
- id: light_us_rl_1_1_left
name: Light - Relay 1 of 1 (left)
<<: *light_partition_relays
@@ -488,9 +448,10 @@ light:
to: 24
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_1_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_1_left);
attr_global_ptr: !lambda return &id(attr_light_rl_1_1_both);
group_index: 1
- id: light_us_rl_1_1_right
name: Light - Relay 1 of 1 (right)
<<: *light_partition_relays
@@ -503,9 +464,10 @@ light:
to: 8
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_1_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_1_right);
attr_global_ptr: !lambda return &id(attr_light_rl_1_1_both);
group_index: 2
- id: light_us_rl_1_2_left
name: Light - Relay 1 of 2 (left)
<<: *light_partition_relays
@@ -515,9 +477,10 @@ light:
to: 24
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_2_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_2_left);
attr_global_ptr: !lambda return &id(attr_light_rl_1_2_both);
group_index: 1
- id: light_us_rl_1_2_right
name: Light - Relay 1 of 2 (right)
<<: *light_partition_relays
@@ -530,9 +493,10 @@ light:
to: 3
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_2_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_2_right);
attr_global_ptr: !lambda return &id(attr_light_rl_1_2_both);
group_index: 2
- id: light_us_rl_2_2_left
name: Light - Relay 2 of 2 (left)
<<: *light_partition_relays
@@ -542,9 +506,10 @@ light:
to: 19
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_2_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_2_left);
attr_global_ptr: !lambda return &id(attr_light_rl_2_2_both);
group_index: 1
- id: light_us_rl_2_2_right
name: Light - Relay 2 of 2 (right)
<<: *light_partition_relays
@@ -554,9 +519,10 @@ light:
to: 8
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_2_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_2_right);
attr_global_ptr: !lambda return &id(attr_light_rl_2_2_both);
group_index: 2
- id: light_us_rl_1_3_left
name: Light - Relay 1 of 3 (left)
<<: *light_partition_relays
@@ -566,9 +532,10 @@ light:
to: 23
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_3_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_3_left);
attr_global_ptr: !lambda return &id(attr_light_rl_1_3_both);
group_index: 1
- id: light_us_rl_1_3_right
name: Light - Relay 1 of 3 (right)
<<: *light_partition_relays
@@ -578,9 +545,10 @@ light:
to: 1
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_3_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_3_right);
attr_global_ptr: !lambda return &id(attr_light_rl_1_3_both);
group_index: 2
- id: light_us_rl_2_3_left
name: Light - Relay 2 of 3 (left)
<<: *light_partition_relays
@@ -590,9 +558,10 @@ light:
to: 20
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_3_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_3_left);
attr_global_ptr: !lambda return &id(attr_light_rl_2_3_both);
group_index: 1
- id: light_us_rl_2_3_right
name: Light - Relay 2 of 3 (right)
<<: *light_partition_relays
@@ -602,9 +571,10 @@ light:
to: 4
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_3_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_3_right);
attr_global_ptr: !lambda return &id(attr_light_rl_2_3_both);
group_index: 2
- id: light_us_rl_3_3_left
name: Light - Relay 3 of 3 (left)
<<: *light_partition_relays
@@ -614,9 +584,10 @@ light:
to: 17
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_3_3_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_3_3_left);
attr_global_ptr: !lambda return &id(attr_light_rl_3_3_both);
group_index: 1
- id: light_us_rl_3_3_right
name: Light - Relay 3 of 3 (right)
<<: *light_partition_relays
@@ -626,9 +597,10 @@ light:
to: 7
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_3_3_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_3_3_right);
attr_global_ptr: !lambda return &id(attr_light_rl_3_3_both);
group_index: 2
- id: light_us_rl_1_4_left
name: Light - Relay 1 of 4 (left)
<<: *light_partition_relays
@@ -638,9 +610,10 @@ light:
to: 24
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_4_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_4_left);
attr_global_ptr: !lambda return &id(attr_light_rl_1_4_both);
group_index: 1
- id: light_us_rl_1_4_right
name: Light - Relay 1 of 4 (right)
<<: *light_partition_relays
@@ -653,9 +626,10 @@ light:
to: 0
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_1_4_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_1_4_right);
attr_global_ptr: !lambda return &id(attr_light_rl_1_4_both);
group_index: 2
- id: light_us_rl_2_4_left
name: Light - Relay 2 of 4 (left)
<<: *light_partition_relays
@@ -665,9 +639,10 @@ light:
to: 22
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_4_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_4_left);
attr_global_ptr: !lambda return &id(attr_light_rl_2_4_both);
group_index: 1
- id: light_us_rl_2_4_right
name: Light - Relay 2 of 4 (right)
<<: *light_partition_relays
@@ -677,9 +652,10 @@ light:
to: 2
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_2_4_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_2_4_right);
attr_global_ptr: !lambda return &id(attr_light_rl_2_4_both);
group_index: 2
- id: light_us_rl_3_4_left
name: Light - Relay 3 of 4 (left)
<<: *light_partition_relays
@@ -689,9 +665,10 @@ light:
to: 18
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_3_4_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_3_4_left);
attr_global_ptr: !lambda return &id(attr_light_rl_3_4_both);
group_index: 1
- id: light_us_rl_3_4_right
name: Light - Relay 3 of 4 (right)
<<: *light_partition_relays
@@ -701,9 +678,10 @@ light:
to: 6
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_3_4_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_3_4_right);
attr_global_ptr: !lambda return &id(attr_light_rl_3_4_both);
group_index: 2
- id: light_us_rl_4_4_left
name: Light - Relay 4 of 4 (left)
<<: *light_partition_relays
@@ -713,9 +691,10 @@ light:
to: 16
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_4_4_left);
attr_global_ptr: !lambda return &id(attr_light_us_rl_4_4_left);
attr_global_ptr: !lambda return &id(attr_light_rl_4_4_both);
group_index: 1
- id: light_us_rl_4_4_right
name: Light - Relay 4 of 4 (right)
<<: *light_partition_relays
@@ -725,9 +704,10 @@ light:
to: 8
on_state:
- script.execute:
id: light_attributes_save
id: light_attributes_save_dual
light_ptr: !lambda return id(light_us_rl_4_4_right);
attr_global_ptr: !lambda return &id(attr_light_us_rl_4_4_right);
attr_global_ptr: !lambda return &id(attr_light_rl_4_4_both);
group_index: 2
output:
- id: output_relay_1
@@ -1144,7 +1124,7 @@ script:
id: sl_relay_4_mode
index: !lambda return std::min((uint8_t)((id(relay_modes_packed) >> 12) & 0x0F), (uint8_t)2);
# Switch states (new - your improved version)
# Switch states
- if:
condition:
lambda: return (id(relay_switches_packed) & 0x01) == 0;
@@ -1184,6 +1164,72 @@ script:
# update lights based on new relay statuses (catch up, as this should be done when each relay is updated)
- script.execute: show_relay_status
# Light attributes restoration
- lambda: |-
// Restore all light attributes based on current model and gang count
switch (id(gang_count)) {
case 1:
if (id(is_us_model)) {
light_attributes_restore_dual->execute(id(light_us_rl_1_1_left), &id(attr_light_rl_1_1_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_1_1_right), &id(attr_light_rl_1_1_both), 2);
} else {
light_attributes_restore_dual->execute(id(light_eu_rl_1_1_bottom), &id(attr_light_rl_1_1_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_1_1_top), &id(attr_light_rl_1_1_both), 2);
}
break;
case 2:
if (id(is_us_model)) {
light_attributes_restore_dual->execute(id(light_us_rl_1_2_left), &id(attr_light_rl_1_2_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_1_2_right), &id(attr_light_rl_1_2_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_2_2_left), &id(attr_light_rl_2_2_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_2_2_right), &id(attr_light_rl_2_2_both), 2);
} else {
light_attributes_restore_dual->execute(id(light_eu_rl_1_2_bottom), &id(attr_light_rl_1_2_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_1_2_top), &id(attr_light_rl_1_2_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_2_2_bottom), &id(attr_light_rl_2_2_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_2_2_top), &id(attr_light_rl_2_2_both), 2);
}
break;
case 3:
if (id(is_us_model)) {
light_attributes_restore_dual->execute(id(light_us_rl_1_3_left), &id(attr_light_rl_1_3_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_1_3_right), &id(attr_light_rl_1_3_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_2_3_left), &id(attr_light_rl_2_3_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_2_3_right), &id(attr_light_rl_2_3_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_3_3_left), &id(attr_light_rl_3_3_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_3_3_right), &id(attr_light_rl_3_3_both), 2);
} else {
light_attributes_restore_dual->execute(id(light_eu_rl_1_3_bottom), &id(attr_light_rl_1_3_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_1_3_top), &id(attr_light_rl_1_3_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_2_3_bottom), &id(attr_light_rl_2_3_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_2_3_top), &id(attr_light_rl_2_3_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_3_3_bottom), &id(attr_light_rl_3_3_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_3_3_top), &id(attr_light_rl_3_3_both), 2);
}
break;
case 3:
if (id(is_us_model)) {
light_attributes_restore_dual->execute(id(light_us_rl_1_4_left), &id(attr_light_rl_1_4_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_1_4_right), &id(attr_light_rl_1_4_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_2_4_left), &id(attr_light_rl_2_4_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_2_4_right), &id(attr_light_rl_2_4_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_3_4_left), &id(attr_light_rl_3_4_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_3_4_right), &id(attr_light_rl_3_4_both), 2);
light_attributes_restore_dual->execute(id(light_us_rl_4_4_left), &id(attr_light_rl_4_4_both), 1);
light_attributes_restore_dual->execute(id(light_us_rl_4_4_right), &id(attr_light_rl_4_4_both), 2);
} else {
light_attributes_restore_dual->execute(id(light_eu_rl_1_4_bottom), &id(attr_light_rl_1_4_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_1_4_top), &id(attr_light_rl_1_4_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_2_4_bottom), &id(attr_light_rl_2_4_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_2_4_top), &id(attr_light_rl_2_4_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_3_4_bottom), &id(attr_light_rl_3_4_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_3_4_top), &id(attr_light_rl_3_4_both), 2);
light_attributes_restore_dual->execute(id(light_eu_rl_4_4_bottom), &id(attr_light_rl_4_4_both), 1);
light_attributes_restore_dual->execute(id(light_eu_rl_4_4_top), &id(attr_light_rl_4_4_both), 2);
}
break;
}
- id: show_relay_status
mode: restart
then: