Skip to content

Commit

Permalink
uptime text with 2 digits and small correction
Browse files Browse the repository at this point in the history
  • Loading branch information
txubelaxu committed Jul 1, 2024
1 parent 3d1895b commit e43d65e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions esp32-S3-example-jkpb-rs485_0master_2slaves.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ esphome:
comment: ${device_description}
project:
name: "txubelaxu.esphome-jk-bms"
version: 1.0.0
version: 1.3.1
# libraries:
# - "ArduinoJson"
# includes:
Expand Down Expand Up @@ -290,19 +290,21 @@ sensor:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
char buf[10];
int uptime_sec = round(id(uptime_sensor).raw_state);
int days = (int)(uptime_sec / 86400);
int hours = (int)((uptime_sec % 86400) / 3600);
int minutes = (int)((uptime_sec % 3600) / 60);
int seconds = (int)(uptime_sec % 60);
return(
(
(days ? sprintf(buf, "%02dd ", days), std::string(buf) : "") +
(hours ? sprintf(buf, "%02dh ", hours), std::string(buf) : "") +
(minutes ? sprintf(buf, "%02dm ", minutes), std::string(buf) : "") +
(sprintf(buf, "%02ds", seconds), std::string(buf))
).c_str()
);
- platform: jk_rs485_bms
jk_rs485_bms_id: bms0
Expand Down

0 comments on commit e43d65e

Please sign in to comment.