Skip to content

Update 'Uptime' sensor lambda to be compatible with ESPHome 2026.1.0#143

Open
Roving-Ronin wants to merge 22 commits intoathom-tech:mainfrom
Roving-Ronin:ESPHome-2026-1-0-ESP_IDF
Open

Update 'Uptime' sensor lambda to be compatible with ESPHome 2026.1.0#143
Roving-Ronin wants to merge 22 commits intoathom-tech:mainfrom
Roving-Ronin:ESPHome-2026-1-0-ESP_IDF

Conversation

@Roving-Ronin
Copy link
Copy Markdown

Corrects issues with STRINGS that occurs with update to ESP-IDF with ESPHome 2026.1.0

@MaJerle
Copy link
Copy Markdown

MaJerle commented Jan 21, 2026

Couldn't the "uptime" sensor become a package if it is in every product?

@Roving-Ronin
Copy link
Copy Markdown
Author

@MaJerle if you want to write it ;-) Hell I'd change a heap of stuff and add useful sensors (as per below), let alone use packages pulled from a single common file set, so instead of wasting time having to update lots of individual yaml, we'd only need to update a single core location for a change to affect all other configs (like I also do with my own configs)... but its Tarontop / Athoms repository and he prefers them all to operate seperately.

image

@MaJerle
Copy link
Copy Markdown

MaJerle commented Jan 21, 2026

I don't. You've just said owner doesn't like this, so why bother.

@dewi-ny-je
Copy link
Copy Markdown

Is the calculation of hours minutes and seconds really needed? If the uptime is assigned the correct category home assistant will do it automatically, see a similar issue with another project which got solved by a simple "device class"

Hypfer/Valetudo#2335 (comment)

@dewi-ny-je
Copy link
Copy Markdown

Isn't it just better to use the platform uptime??

From:

  - platform: template
    name: "Uptime"
    entity_category: diagnostic
    lambda: |-
      int seconds = (id(uptime_sensor).state);
      int days = seconds / (24 * 3600);
      seconds = seconds % (24 * 3600);
      int hours = seconds / 3600;
      seconds = seconds % 3600;
      int minutes = seconds /  60;
      seconds = seconds % 60;
      if ( days > 3650 ) {
        return { "Starting up" };
      } else if ( days ) {
        return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
      } else if ( hours ) {
        return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
      } else if ( minutes ) {
        return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
      } else {
        return { (String(seconds) +"s").c_str() };
      }
    icon: mdi:clock-start

to:

sensor:
  - platform: uptime
    name: "Uptime Sensor"
    id: uptime_sensor
    type:
      timestamp
    entity_category: "diagnostic"

which I took from https://github.com/athom-tech/esp32-configs/blob/main/athom-smart-plug.yaml

@dewi-ny-je
Copy link
Copy Markdown

@MaJerle

Couldn't the "uptime" sensor become a package if it is in every product?

it's already part of the core ESPhome! we are reinventing the wheel here, which is even worse than putting code in each config instead of a separate package

@Roving-Ronin
Copy link
Copy Markdown
Author

This isn't the uptime sensor in ESPHome. This is a template sensor that reformats the output of the raw ESPHome uptime sensors and gives a more usable days/hours/minutes etc type formatted output.

Re packages it would be logical, however Athom prefers to not use any packages, but instead keep the full config in every single device/product config file, so newbies can see/read it in one place.

IMHO I think most people who dive into the yaml end up doing their own config and use packages, whilst the bulk of users pulling from the default setup don't ever change or get into the yaml anyhow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants