Esphome Set your time

Is it possible to set your own time if there is no connection to the server?

Really? This component will be able to change time: component?

How often do you expect to be disconnected from a server that updates time?

If your talking about doing something that wont have network access at all and you need a time source, then you should just use a physical RTC module like the DS1307

there is such a module… DS1307. I would like to understand whether the ESP can work without receiving time from outside. Only a local network and the ability to set the time, for example, through a web server

Yes

datetime.date.setAction¶

This is an Action for setting a datetime date state. The date provided can be in one of 3 formats:

And

datetime.time.setAction¶

This is an Action for setting a datetime time state. The time provided can be in one of 3 formats:

Yes, it works fine without receiving time synchronization and doesn’t need it to function. If you need to use the Time component, then you will need a Time source because it will need to update/sync the Time periodically and whenever it reboots.

Even if you configure a Time component in your config and then lose connection to a server, the esp board will still function and all the other things you setup will still work as long as it doesn’t require Time, like if you made an automation that said…

time:
  - platform: sntp
    # ...
    on_time:
      # Every 5 minutes
      - seconds: 0
        minutes: /5
        then:
          - switch.toggle: my_switch

That (switch.toggle: my_switch) it won’t automatically get toggled every 5min until the Time component can synchronize and update. You could still manually toggle (my_switch) and that stuff will work just fine.

A lot of people do what you’re doing too… They try to figure out all the answers to everything before they attempt to do anything and that’s a big mistake.

Try setting up a Time component on an esp board and experiment with things, do some playing around and learn things. You don’[t need to figure it all out first. These esp boards aren’t single use and then need disposed of, you can flash them many many times and that’s perfectly normal to do.

Yes, we all know there is a DateTime where someone can configure a date/time and use it to set an appointment for waxing your back end but, that isn’t exactly what he’s asking here or that’s only half the question.

If he has no access to an outside NTP server and can’t set the system time, then what good does it do him to use TimeDate if it has nothing to compare against like the system time?

If you don’t know what day of the week is today and I tell DateTime to set a date and time in the future to turn something On, how will it know when it reaches that specefic time/date if it doesn’t know the current time/date?

I’m not 100% sure what your end goal is but, whatever it is, you’re most likely over complicating this. If this will be in an area with network access, you don’t need to worry about long and frequent periods where it can’t synchronize. If you won’t have access to a server then you just need to get yourself a RTC w/battery backup. Don’t make it more complicated than it is.

I’m not complicating things, I’m just curious.

Let’s create a situation: there is RTS, no access to the network. The BATTERY is dead in RTS; the device must work on time.

There is only one way out: install a new battery and set the time MANUALLY for RTS via the web server

You can take the battery out and hardwire it to DC power, You can monitor the battery voltage and have it report to HA as a sensor so that it doesn’t just suddenly die, you will know when it’s low and need to change it, If no direct power option you can use a small solar cell to recharge a battery… That’s a few options but, it would help more if you would elaborate on what your actually trying to do and why updating Time is so critical. A lot of times new people do exactly this and only want a vague question answered. A lot of times, people don’t always ask the better questions or seek better solutions and no one can help you or them if they insist on determining what is or isn’t relevant information.

What network? SNTP time doesn’t ask anything else than internet connection. Home assistant and all the related network can be off.
Also, ESP32 keeps the system time pretty well for long time even without synch. So if it’s not rebooting you should be fine.

1 Like

I’m afraid you really are complicating things unnecessarily.

Ask yourself how many times in your life you’ve seen an offline PC lose track of time because its RTC battery was dead.

I’m betting on a number <=1

No network no messages HA

I just asked a question, I know everything you suggested.

All the talk is pointless. I asked a clear question with input data. But everyone is trying to persuade me: install a solar battery, connect this, turn off that.

  1. There is no network, it is impossible to get time neither from sntp nor from ha. There is a local Wi-Fi network.
  2. The RTS battery is dead.
  3. ESP cannot be removed.

How to set your time in RTS if I changed the battery? Who does not know is approaching past without advice on the code.

What is RTS here?

Same way you put together a desk you order online or a toy for a child… You read the documentation/instructions and it explains most of this.

Trying to persuade you? You asked about a hypothetical situation and I gave you several options to address that situation and resolve the problem so, I don’t know how you interpreted that as trying to persuade you, that’s just silly.

You need to read the documentation for the relevant components you are considering using and determine what functionality you want there to be and then focus on the relevant documentation for them.

As I said already, you need to read the documentation. You also need to look through the documentation to find out what components are supported, for example there are 3 different RTC modules that Esphome supports so, you need to look at them and decide if one might be better for your needs or is overall better for you.

https://esphome.io/components/time/ds1307.html

DS1307 - real time clock

I don’t think this is too hypothetical – I was thinking about the same for standalone esphome devices you want to give someone but don’t want to force people to connect it to the network/HA/… (In my case, esphome-based LED light with alarm functionality.)

I found a solution. Partially modified the code. Everything works fine.