From 1d8b8e29141ed4df857f4732162191368e0a845c Mon Sep 17 00:00:00 2001 From: Spencer Owen Date: Thu, 9 Jan 2025 23:11:51 -0700 Subject: [PATCH] Support multiple ams --- firmware/conf.d/bambu_ams.yaml | 37 +++++ firmware/conf.d/bambu_printer.yaml | 230 ++++++++++++++--------------- firmware/conf.d/web_server.yaml | 33 +++-- 3 files changed, 169 insertions(+), 131 deletions(-) create mode 100644 firmware/conf.d/bambu_ams.yaml diff --git a/firmware/conf.d/bambu_ams.yaml b/firmware/conf.d/bambu_ams.yaml new file mode 100644 index 0000000..36bc9a1 --- /dev/null +++ b/firmware/conf.d/bambu_ams.yaml @@ -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 diff --git a/firmware/conf.d/bambu_printer.yaml b/firmware/conf.d/bambu_printer.yaml index 74f11b2..03c68aa 100644 --- a/firmware/conf.d/bambu_printer.yaml +++ b/firmware/conf.d/bambu_printer.yaml @@ -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 diff --git a/firmware/conf.d/web_server.yaml b/firmware/conf.d/web_server.yaml index 408c5e0..ddfe573 100644 --- a/firmware/conf.d/web_server.yaml +++ b/firmware/conf.d/web_server.yaml @@ -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