Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple AMS units #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions firmware/conf.d/bambu_ams.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
select:
- platform: template
name: "AMS Number"
id: ams_number
optimistic: true
restore_value: true
icon: mdi:printer-3d-nozzle
options:
- "1"
- "2"
- "3"
- "4"
initial_option: "1"
set_action:
then:
- lambda: |-
if (id(bambu_model).state == "A1Mini" || id(bambu_model).state == "A1") {
id(ams_number).publish_state("1");
} else if (id(bambu_model).state == "P1P/P1S" || id(bambu_model).state == "X1C/X1E") {
if (x == "1" || x == "2" || x == "3" || x == "4") {
id(ams_number).publish_state(x);
} else {
id(ams_number).publish_state("1");
}
} else {
id(ams_number).publish_state("1");
}
lambda: |-
if (id(bambu_model).state == "A1Mini" || id(bambu_model).state == "A1") {
return {"1"};
} else if (id(bambu_model).state == "P1P/P1S" || id(bambu_model).state == "X1C/X1E") {
return {"1", "2", "3", "4"};
} else {
return {"1"};
}
web_server:
sorting_group_id: sorting_group_ams
230 changes: 114 additions & 116 deletions firmware/conf.d/bambu_printer.yaml
Original file line number Diff line number Diff line change
@@ -1,125 +1,123 @@
---
select:
#TODO: printer model is currently unused, but will be needed for setting AMS type
- platform: template
name: Printer Model
id: bambu_model
state_topic:
options:
- "A1Mini"
- "A1"
- "P1P/P1S"
- "X1C/X1E"
optimistic: true
restore_value: true
icon: mdi:printer-3d
web_server:
sorting_group_id: sorting_group_printer_settings
- platform: template
name: Printer Model
id: bambu_model
state_topic:
options:
- "A1Mini"
- "A1"
- "P1P/P1S"
- "X1C/X1E"
optimistic: true
restore_value: true
icon: mdi:printer-3d
web_server:
sorting_group_id: sorting_group_printer_settings

text:
- platform: template
name: Printer Serial Number
id: bambu_serial_number
state_topic:
optimistic: true
mode: text
restore_value: true
icon: mdi:barcode
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log:
level: info
format: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt

# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
# lambda: |-
# id(bambu_printer_status).topic = "device/" + x + "/report";
- platform: template
name: Printer Lan Access Code
id: bambu_lan_access_code
state_topic:
optimistic: true
mode: password
restore_value: true
icon: mdi:lock
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- lambda: |-
id(bambu_mqtt).set_password(x.c_str());
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log:
level: info
format: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt
- platform: template
name: Printer IP Address
id: bambu_ip_address
state_topic:
optimistic: true
mode: text
restore_value: true
icon: mdi:ip
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- lambda: |-
id(bambu_mqtt).set_broker_address(x.c_str());
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt
- platform: template
name: Printer Serial Number
id: bambu_serial_number
state_topic:
optimistic: true
mode: text
restore_value: true
icon: mdi:barcode
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log:
level: info
format: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
# lambda: |-
# id(bambu_printer_status).topic = "device/" + x + "/report";
- platform: template
name: Printer Lan Access Code
id: bambu_lan_access_code
state_topic:
optimistic: true
mode: password
restore_value: true
icon: mdi:lock
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- lambda: |-
id(bambu_mqtt).set_password(x.c_str());
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log:
level: info
format: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt
- platform: template
name: Printer IP Address
id: bambu_ip_address
state_topic:
optimistic: true
mode: text
restore_value: true
icon: mdi:ip
web_server:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
- lambda: |-
id(bambu_mqtt).set_broker_address(x.c_str());
- if:
condition:
lambda: |-
return !id(bambu_lan_access_code).state.empty() &&
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
level: info
format: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt

button:
- platform: restart
name: "Restart OpenSpool"
id: restart_openspool
state_topic:
entity_category: diagnostic
- platform: restart
name: "Restart OpenSpool"
id: restart_openspool
state_topic:
entity_category: diagnostic

#TODO: Show the current state of the printer

Expand Down
33 changes: 18 additions & 15 deletions firmware/conf.d/web_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ web_server:
version: 3
local: true
sorting_groups:
- id: sorting_group_filament_settings
name: "Filament Settings"
sorting_weight: -50
- id: sorting_group_rfid
name: "RFID Programming"
sorting_weight: -40
- id: sorting_group_printer_settings
name: "Printer Settings"
sorting_weight: -30
- id: sorting_group_info
name: "Information"
sorting_weight: -20
- id: sorting_group_extra
name: "Extra"
sorting_weight: -10
- id: sorting_group_filament_settings
name: "Filament Settings"
sorting_weight: -50
- id: sorting_group_rfid
name: "RFID Programming"
sorting_weight: -40
- id: sorting_group_printer_settings
name: "Printer Settings"
sorting_weight: -30
- id: sorting_group_ams
name: "AMS"
sorting_weight: -25
- id: sorting_group_info
name: "Information"
sorting_weight: -20
- id: sorting_group_extra
name: "Extra"
sorting_weight: -10