esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Support for DS3231 (I2C RTC) #515

Open ghost opened 4 years ago

ghost commented 4 years ago

Describe the problem you have/What new integration you would like

I understand supporting this should not be a priority over other useful sensors, but having support for some kind of reliable I2C RTC chip would be nice in certain situations, especially if the ESPHome node is placed at a location where the wifi signal strength is poor. Please describe your use case for this integration and alternatives you've tried:

Without a bulky external antenna, GPS modules don't work that well in some buildings, sometimes it won't even get a fix at all. Additional context

lsaoye commented 4 years ago

Hope to get support

rradar commented 4 years ago

This could go very nice along with a ntp server component https://github.com/esphome/feature-requests/issues/296 :tada:

e-budianto commented 4 years ago

hopefully there will be support for ds1307 too

a-x- commented 4 years ago

Sometimes electricity breaks in our location and then restores, but internet connection restoring in a long time after usually, so our ESP modules cannot understand the time for light controlling logic

Denyerec commented 3 years ago

Just been looking for ways to have backup programming for my boiler and an RTC was a requirement - would love to see it!

wisesokol commented 3 years ago

Me too. If there is no wi fi, I would like to show the correct time on the display.

badbadc0ffee commented 3 years ago

hopefully there will be support for ds1307 too

I have finally started working on that again: https://github.com/esphome/esphome/pull/1441

badbadc0ffee commented 3 years ago

The DS3231 register set is so similar to the one of the DS1307, that the DS1307 component (esphome/esphome#1441) should already work with a DS3231. I could not test this, however, because I don't have such a device at hand; and additional features such as temperature readings and alarms are obviously not supported.

I could definitely also provide a dedicated driver component for the DS3231 if I had one to test with. :-) https://www.amazon.de/hz/wishlist/ls/IKJQ9RPIUL6J

rradar commented 3 years ago

https://github.com/esphome/esphome/pull/1441 is merged in 1.16.0b2.

@badbadc0ffee I need to find my DS3231 somewhere in the drawer so I can test it with your component! Thank's already for your work :+1:

NarinLab commented 3 years ago

Any update on DS3231 support for ESP32? Or if someone can show us how ti write our own code porting from conventional Arduino IDE based approach to get DS3231 integrated into ESPHOME.

jbrepogmailcom commented 3 years ago

I would like if I can wake ESP by external clock to do its job and then turn it off completely. It is not conceptually correct to have ESP sleeping and all supporting circuitry powered up if no job is needed. Everything should be powered down until its time comes.

ckuethe commented 3 years ago

@jbrepogmailcom I think you misunderstand. It is perfectly reasonable to leave the rest of the external support circuitry powered up when calling a routine that is documented to put the processor to sleep. Switching off power to the entire board is beyond the scope of the the deep sleep routine. You could probably build a basic switch from a couple of transistors, or use a dedicated power management IC (eg. AXP192)

jbrepogmailcom commented 3 years ago

Hello, we are probably talking about different things. I meant to switch off both circuitry and ESP32 by DS3231 during the deep sleep, not before. And after wakeup, to reprogram DS3231 for nex sleep. However, I learned in the meanwhile that DS3231 takes about 100µA during sleep, while ESP32 with RTC on takes 10µA in deep sleep and 5µA in hibernation mode. So it is better to use ESP32 itself to manage sleep time and turn on/off supporting electronics.

zenzay commented 3 years ago

A bit late to the discussion, but the DS1307 component in ESPHome seems to work just fine with the DS3231 module. I have it attached to a NodeMCU 32s board and it's ticking along nicely.

Edit: I'm getting two devices at the i2c scan. I'm, ofc, using 0x68. I have no idea what the other is tbh.

[22:17:45][C][i2c:028]: I2C Bus:
[22:17:45][C][i2c:029]:   SDA Pin: GPIO21
[22:17:45][C][i2c:030]:   SCL Pin: GPIO22
[22:17:45][C][i2c:031]:   Frequency: 50000 Hz
[22:17:45][I][i2c:033]: Scanning i2c bus for active devices...
[22:17:45][I][i2c:040]: Found i2c device at address 0x57
[22:17:45][I][i2c:040]: Found i2c device at address 0x68
[22:17:45][C][ds1307:022]: DS1307:
[22:17:45][C][ds1307:023]:   Address: 0x68
WeekendWarrior1 commented 2 years ago

Edit: I'm getting two devices at the i2c scan. I'm, ofc, using 0x68. I have no idea what the other is tbh.

The other is likely 32K of eeprom (AT24C32X), which I know can have an address of 0x57 and appears on modules like this:

image

Writing to and reading from it is not currently supported by esphome.

zenzay commented 2 years ago

That seems very likely, as that's the exact module I have :-)

I currently have no use for the eeprom on the module, so it's not really something I would wish esphome to focus on anyhow.

Thanks for the information!

kdorff commented 2 years ago

Just to throw my two cents in. For my ESPHome sensors, I'm hoping to replicate the work found https://www.raspberrypi.com/news/build-low-power-clock-controlled-devices/ to greatly prolong the battery life on my sensors. It seems like this "sleep" method allows for zero current to the DS321 (via VCC) or ESP32 and very, very low current for the P-Channel Mosfet switch (< 1mA). The DS3231 runs from the coin cell while waiting for the next alarm. When that alarm happens, the DS3231 switches the mosfet, the ESP32 circuit is powered on. The ESP32 can then do it's business, set a next alarm, and when it clears the current DS3231 alarm the ESP32 circuit is shutdown (completely), along with the VCC input on the DS3231 (so it is only running from the coin-cell until it triggers the next alarm, turning the ESP32 circuit back on).

It seems like several others have more or less the same goal. Has anyone made any progress?

I first will probably just do it as an Arduino or MicroPython app and publish to Home Assistant via MQTT (via node-red probably). I'd love to then transfer what I've learned to be able to do this with ESPHome, but we'll see how far I get on that front. It's currently not clear to me how I'd want to implement this in ESPHome. Maybe as an alternative to deep sleep or via lambda scripts?

The unit I ordered for testing is https://www.amazon.com/gp/product/B07WJZ7NKM - I've read you specifically should prefer the DS3231SN versions of the chip.

nagyrobi commented 2 years ago

https://esphome.io/components/time.html?#ds1307-time-source

kevindorff commented 2 years ago

https://esphome.io/components/time.html?#ds1307-time-source

That's an interesting device for reading/writing time. The ds3231 could enable doing a lot more. See my description above.

My goal is to be able to use the ds3231 to be able to be able to power down circuit including the esp32 for stretches of time and it can trigger turning the circuit back on to do work - and the cycle repeats.

ptr727 commented 9 months ago

I have a Norvi NORVI-ENET-AE06-R DIN mount ESP32 that uses a DS3231, I found that the built-in ds1307 component seems to works fine for RTC only purposes.