11globals :
22 - id : selected_slot
33 type : int
4- restore_value : yes
4+ restore_value : true
55 initial_value : " 0"
66
77script :
@@ -22,22 +22,31 @@ number:
2222 optimistic : false
2323 restore_value : true
2424 icon : mdi:printer-3d-nozzle
25- min_value : 1
25+ min_value : 0
2626 max_value : 4
2727 step : 1
2828 initial_value : 1
2929 set_action :
3030 then :
3131 - lambda : |-
3232 if (id(bambu_model).state == "A1Mini" || id(bambu_model).state == "A1") {
33+ ESP_LOGD("AMS Units", "A1Mini or A1 detected, setting AMS to 1");
3334 id(ams_units).publish_state(1);
3435 } else {
36+ ESP_LOGD("AMS Units", "AMS units: %d", (int)id(ams_units).state);
3537 id(ams_units).publish_state(x);
3638 }
37- on_value :
38- then :
39- - lambda : |-
4039 ESP_LOGD("AMS", "Number of AMS units set: %d", (int)x);
40+
41+ if (x < id(ams_number).state) {
42+ ESP_LOGD("AMS Units", "AMS is higher than current units size, forcing AMS to %d", (int)x);
43+ id(ams_number).publish_state(x);
44+ }
45+ if (x == 0) {
46+ ESP_LOGD("AMS Units", "AMS units is 0, forcing slot to 1");
47+ id(slot_number).publish_state(1);
48+ }
49+ - script.execute : update_selected_slot
4150 web_server :
4251 sorting_group_id : sorting_group_printer_settings
4352 sorting_weight : 100
@@ -55,24 +64,19 @@ number:
5564 set_action :
5665 then :
5766 - lambda : |-
58- if (id(bambu_model).state == "A1Mini" || id(bambu_model).state == "A1") {
59- id(ams_number).publish_state(1);
67+ if (x > id(ams_units).state) {
68+ ESP_LOGD("ams_number", "AMS number too high, setting to %d", (int)id(ams_units).state);
69+ id(ams_number).publish_state(id(ams_units).state);
6070 } else {
61- if (x > id(ams_units).state) {
62- id(ams_number).publish_state(id(ams_units).state);
63- } else {
64- id(ams_number).publish_state(x);
65- }
71+ id(ams_number).publish_state(x);
6672 }
67- - script.execute : update_selected_slot
68- on_value :
69- then :
70- - lambda : |-
7173 ESP_LOGD("AMS", "AMS selected: %d", (int)x);
72- // If AMS is 0, ensure slot is forced to 1
74+
7375 if (x == 0 && id(slot_number).state != 1) {
74- id(slot_number).publish_state(1);
76+ ESP_LOGD("AMS", "AMS is 0, forcing slot to 1");
77+ id(slot_number).publish_state(1);
7578 }
79+ - script.execute : update_selected_slot
7680 web_server :
7781 sorting_group_id : sorting_group_ams
7882
@@ -86,23 +90,16 @@ number:
8690 max_value : 4
8791 step : 1
8892 initial_value : 1
89- mode : box
9093 set_action :
9194 then :
9295 - lambda : |-
9396 if (id(ams_number).state == 0) {
97+ ESP_LOGD("slot_number", "AMS is 0, forcing slot to 1");
9498 id(slot_number).publish_state(1);
9599 } else {
96100 id(slot_number).publish_state(x);
97101 }
98- - script.execute : update_selected_slot
99- on_value :
100- then :
101- - lambda : |-
102102 ESP_LOGD("AMS", "Slot selected: %d", (int)x);
103- // If AMS is 0, ensure slot is forced to 1
104- if (id(ams_number).state == 0 && x != 1) {
105- id(slot_number).publish_state(1);
106- }
103+ - script.execute : update_selected_slot
107104 web_server :
108105 sorting_group_id : sorting_group_ams
0 commit comments