Time & Date sensor is not updating

Thank you for quick help. This fix is working.

Hey Petro,

Thanks for all your responses, it took me a few days of googling through the forums to finally stumble on this one comment and it was the fix I needed.

While I see that introspecting the template to resolve the dependent sensors is an improvement, in this particular use case it seems like a step backwards: the template is more complex and less intuitive now. Are there plans to improve things for time-dependent templates?

Thanks!

Yes, in 0.117 now() will update once per minute so you don’t need the dump line.

That’s excellent! Good to know.

Actually, my use case doesn’t use now(), could you recommend an alternate approach to this:

      pressure_last_reading:
        friendly_name: 'Pressure (Last Reading)'
        icon_template: mdi:clock-outline
        value_template: >
          {% set dump = states('sensor.time') %}
          {{ relative_time(states.sensor.pressure.last_updated) }}

Maybe I should drop relative_time() and calculate it myself based on now()?

what’s the point, what you have is working. I wouldn’t bother changing it personally.

Hello, @petro. My system has the same symptoms but with an automatically generated sensor.time_2 that is updating, as you asked the OP. Does that indicate right away where the problem lies? If not, I’ll create a new thread with config, logs and screenshots. Thanks!

Yes that would be the problem. Somehow your system created a new sensor instead of using the original. Not sure how that would happen. Shutdown HA and goes through the entity registry and delete the sensor.time in it.

Thanks.

I think that I’ve tracked the issue down to a custom component, remote_homeassistant. I’m testing now with remote_homeassistant uninstalled. I’ll see if it behaves for a few days.

Something’s got me perplexed, though. I tried to do what you suggested, but there are no entries for sensor.time, sensor.time_2 or any other sensors from the time_date platform in core.entity_registry, even though the sensors exist and are visible in Configuration/Entites and Dev Tools/States. Have I misunderstood and there’s somewhere else that I should be looking?

The relevant config in sensors.yaml:

# Time & date
- platform: time_date
  display_options:
  - time
  - date
  - date_time
  - time_utc
  - date_time_utc

Well, it’s possible that the date_time platform doesn’t create an entity in the entity_registry. That integration is old enough for that to be the case. In instances like that, it’s first come first serve. So whatever integration is integrated first will get sensor.time, whatever’s second will get sensor.time_2

This chicken egg scenario is why the entity_registry was created in the first place.

Got it. Thanks for your help. :+1:

Hi!
Here somebody with an out of sync date and time problem! Seems when my hardware restarts or is down for some hours or days, it does not keep the date and time, I’m using the blue edition (odroid from hardkernel) and I changed the coin-cell that is attached to the hardware, just in case, but I keep having this issue… and now via ssh i’m unable to set the date, I can use date -s HH:MM:SS but not the year, month and day string…
Any idea how to set the day, month and year via ssh?
Any idea how to keep the datetime up-to-date even I restart or switch off the hardware for some minutes, hours or days?
Thanks in advance! (please, if you want me to create a new question with all this info, let me know)