Display a timer

I want to display the amount of time an ESP32 device has been turned on days/hours/minutes
Using an lcd2004 but could be an oled
I can figure out how to display “timer” I just can’t figure out how the get it
Tried looking at duty cycle

Any ideas?
Thanks,
Grey

Are you looking for the current uptime? Use the uptime sensor.

If cumulative is what you are after, create a global variable and add 1 to it every second. You can use a time trigger.

1 Like

Thanks,
The uptime sensor ~works, but on my display it shows either secs, mins, days, etc
I suppose I could use days as I am looking for Day 15 and day 17 in reality, but it would be much sexier to see Days:hours:mins
I suppose I could just create 3 sensors, one for each.

When I look at the sensor in HA it looks good.
Afraid I cannot figure out your second suggestion, on_time triger

quail timer

I lied :slight_smile:
I do not know how to create 3 uptime sensors

Thanks,
Grey

You can create a global variable, a number type specifically. This number will be saved through restarts. This will represent seconds. Set the restore value to yes

# Example configuration entry
 globals:
   - id: my_global_int
     type: int
     restore_value: yes
     initial_value: '0'

Then use one of the time triggers set to trigger every second. Increase the global by 1

      - globals.set:
          id: my_global_int
          value: !lambda 'return id(my_global_int) += 1;'

Now you have the time in seconds, you’ll need to convert in c to display the time as d h m s .

Okay thanks I will try that, gaining on the other option

  • platform: homeassistant
    id: egg_minutes
    entity_id: sensor.esphome_web_fdb438_eggs_minutes
    internal: true

  • platform: homeassistant
    id: egg_hours
    entity_id: sensor.esphome_web_fdb438_egg_hours
    internal: true

Example configuration entry

  • platform: uptime
    name: Eggs Minutes
    id: eggm
  • platform: uptime
    name: Egg Hours
    id: eggh

I was under the impression you were trying to keep this all on the esp32. It’s easier to do this in home assistant and then bring the value back to the esp.

Add a binary sensor to the esp

*Edit it says mqtt but it is also applicable if you don’t use mqtt

Use that to create

bring that value back to the esp using the homeassistant platform.

https://esphome.io/components/time/#strftime

1 Like

yea, my idea of 3 up time(s) is giving me 154 minutes
let me try this other stuff
Thanks,
Grey

The uptime docs used to have examples for this kind of thing.

I guess the reason for removal makes sense…

1 Like

Thanks everyone. Here is where I ended up. I do not need seconds so it updates every 60 seconds
display 02D 05H 12M for example

text_sensor:
  - platform: template
    name: "timeegg"
    id: timeegg
    update_interval: 60s
    lambda: |-
      auto s = millis() / 1000;
      char buffer[20];
      snprintf(buffer, sizeof(buffer), "%02dD %02dH %02dM", s / 86400, s / 3600 % 24, s / 60 % 60);
      return {buffer};