Skip to content

Commit caf5296

Browse files
committed
Fix mqtt enabled icon
1 parent b56e776 commit caf5296

File tree

3 files changed

+68
-19
lines changed

3 files changed

+68
-19
lines changed

firmware/common.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,13 @@ esphome:
5050
!id(bambu_ip_address).state.empty() &&
5151
!id(bambu_serial_number).state.empty();
5252
then:
53-
- logger.log:
54-
format: "Connecting to Bambu printer"
55-
tag: "MQTT"
56-
level: INFO
53+
- logger.log: "Connecting to Bambu printer"
5754
- mqtt.enable:
5855
id: bambu_mqtt
5956
else:
60-
- logger.log:
61-
format: "Missing Bambu Credentials, skipping mqtt connect"
62-
tag: "MQTT"
63-
level: INFO
57+
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
58+
- mqtt.disable:
59+
id: bambu_mqtt
6460
# - script.execute: set_all_leds_white
6561
# - lambda: |-
6662
# //TODO: this appears to have broken and no longer blinks blue

firmware/conf.d/bambu_printer.yaml

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,23 @@ text:
4848
icon: mdi:barcode
4949
web_server:
5050
sorting_group_id: sorting_group_printer_settings
51-
# on_value:
52-
# then:
51+
on_value:
52+
then:
53+
- if:
54+
condition:
55+
lambda: |-
56+
return !id(bambu_lan_access_code).state.empty() &&
57+
!id(bambu_ip_address).state.empty() &&
58+
!id(bambu_serial_number).state.empty();
59+
then:
60+
- logger.log: "Connecting to Bambu printer"
61+
- mqtt.enable:
62+
id: bambu_mqtt
63+
else:
64+
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
65+
- mqtt.disable:
66+
id: bambu_mqtt
67+
5368
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
5469
# lambda: |-
5570
# id(bambu_printer_status).topic = "device/" + x + "/report";
@@ -65,9 +80,22 @@ text:
6580
sorting_group_id: sorting_group_printer_settings
6681
on_value:
6782
then:
68-
lambda: |-
69-
id(bambu_mqtt).set_password(x.c_str());
70-
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
83+
- lambda: |-
84+
id(bambu_mqtt).set_password(x.c_str());
85+
- if:
86+
condition:
87+
lambda: |-
88+
return !id(bambu_lan_access_code).state.empty() &&
89+
!id(bambu_ip_address).state.empty() &&
90+
!id(bambu_serial_number).state.empty();
91+
then:
92+
- logger.log: "Connecting to Bambu printer"
93+
- mqtt.enable:
94+
id: bambu_mqtt
95+
else:
96+
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
97+
- mqtt.disable:
98+
id: bambu_mqtt
7199
- platform: template
72100
name: Printer IP Address
73101
id: bambu_ip_address
@@ -80,9 +108,23 @@ text:
80108
sorting_group_id: sorting_group_printer_settings
81109
on_value:
82110
then:
83-
lambda: |-
84-
id(bambu_mqtt).set_broker_address(x.c_str());
85-
# - script.execute: check_mqtt_creds #TODO: Enable once this is merged: https://github.com/esphome/esphome/pull/7716
111+
- lambda: |-
112+
id(bambu_mqtt).set_broker_address(x.c_str());
113+
- if:
114+
condition:
115+
lambda: |-
116+
return !id(bambu_lan_access_code).state.empty() &&
117+
!id(bambu_ip_address).state.empty() &&
118+
!id(bambu_serial_number).state.empty();
119+
then:
120+
- logger.log: "Connecting to Bambu printer"
121+
- mqtt.enable:
122+
id: bambu_mqtt
123+
else:
124+
- logger.log: "Missing Bambu Credentials, skipping mqtt connect"
125+
- mqtt.disable:
126+
id: bambu_mqtt
127+
86128

87129
button:
88130
- platform: restart

firmware/conf.d/mqtt_bambu_lan.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ mqtt:
4646
Rs6d8SCU89xyrwzQ0PR853irHas3WrHVqab3P+qNwR0YirL0Qk7Xt/q3O1griNg2
4747
Blbjg3obpHo9
4848
-----END CERTIFICATE-----
49-
# clean_session: true
50-
# enable_on_boot: false
49+
clean_session: true
50+
enable_on_boot: false
51+
on_connect:
52+
- logger.log: "Connected to printer!"
53+
on_disconnect:
54+
- logger.log: "Disconnected from printer!"
5155

5256
# text_sensor:
5357
# - platform: mqtt_subscribe
@@ -86,13 +90,20 @@ mqtt:
8690
# # # then:
8791
# # # - lambda: |-
8892
binary_sensor:
89-
- platform: status
93+
# Note platform.status won't turn on if 'api' is enabled (yet disconnected)
94+
# api is required for dashboard_import, which is required for made-for-esphome program
95+
# api isn't actually used
96+
# - platform: status
97+
- platform: template
9098
name: "MQTT Connection"
9199
id: mqtt_connected
92100
state_topic: # Don't post update to MQTT
93101
icon: mdi:lan-connect
94102
web_server:
95103
sorting_group_id: sorting_group_printer_settings
104+
device_class: connectivity #TODO: use this class
105+
lambda: |-
106+
return id(bambu_mqtt)->is_connected();
96107
97108
# sensor:
98109
# - platform: mqtt_subscribe

0 commit comments

Comments
 (0)