Skip to content

Commit

Permalink
Fix mqtt enabled icon
Browse files Browse the repository at this point in the history
  • Loading branch information
spuder committed Nov 24, 2024
1 parent b56e776 commit caf5296
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
12 changes: 4 additions & 8 deletions firmware/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ esphome:
!id(bambu_ip_address).state.empty() &&
!id(bambu_serial_number).state.empty();
then:
- logger.log:
format: "Connecting to Bambu printer"
tag: "MQTT"
level: INFO
- logger.log: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log:
format: "Missing Bambu Credentials, skipping mqtt connect"
tag: "MQTT"
level: INFO
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
- mqtt.disable:
id: bambu_mqtt
# - script.execute: set_all_leds_white
# - lambda: |-
# //TODO: this appears to have broken and no longer blinks blue
Expand Down
58 changes: 50 additions & 8 deletions firmware/conf.d/bambu_printer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@ text:
icon: mdi:barcode
web_server:
sorting_group_id: sorting_group_printer_settings
# on_value:
# then:
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: "Connecting to Bambu printer"
- mqtt.enable:
id: bambu_mqtt
else:
- logger.log: "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";
Expand All @@ -65,9 +80,22 @@ text:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
lambda: |-
id(bambu_mqtt).set_password(x.c_str());
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
- 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: "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 IP Address
id: bambu_ip_address
Expand All @@ -80,9 +108,23 @@ text:
sorting_group_id: sorting_group_printer_settings
on_value:
then:
lambda: |-
id(bambu_mqtt).set_broker_address(x.c_str());
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
- 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: "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
Expand Down
17 changes: 14 additions & 3 deletions firmware/conf.d/mqtt_bambu_lan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ mqtt:
Rs6d8SCU89xyrwzQ0PR853irHas3WrHVqab3P+qNwR0YirL0Qk7Xt/q3O1griNg2
Blbjg3obpHo9
-----END CERTIFICATE-----
# clean_session: true
# enable_on_boot: false
clean_session: true
enable_on_boot: false
on_connect:
- logger.log: "Connected to printer!"
on_disconnect:
- logger.log: "Disconnected from printer!"

# text_sensor:
# - platform: mqtt_subscribe
Expand Down Expand Up @@ -86,13 +90,20 @@ mqtt:
# # # then:
# # # - lambda: |-
binary_sensor:
- platform: status
# Note platform.status won't turn on if 'api' is enabled (yet disconnected)
# api is required for dashboard_import, which is required for made-for-esphome program
# api isn't actually used
# - platform: status
- platform: template
name: "MQTT Connection"
id: mqtt_connected
state_topic: # Don't post update to MQTT
icon: mdi:lan-connect
web_server:
sorting_group_id: sorting_group_printer_settings
device_class: connectivity #TODO: use this class
lambda: |-
return id(bambu_mqtt)->is_connected();
# sensor:
# - platform: mqtt_subscribe
Expand Down

0 comments on commit caf5296

Please sign in to comment.