user58316: How can i restart a variable every day? I have an RTC 1307. The problem is that i cannot use an alarm event because the arduino will be shut down during that hour. So I need a more reliable solution. 
This will work? A date could be an integer?
#include <EEPROM.h>
#include "RTClib.h"

int  lastDay;
int EE_ADDR = 0;
int totalLitres;

void setup() {
  EEPROM.get(EE_ADDR, lastDay);
}

void loop() {
DateTime now;
  if (now.day() != lastDay) // this happens exactly once a day.
    totalLitres = 0; // reset the accumulated volume

  lastDay = now.day();
}


user7508: Here are a few suggestions:

Since your RTC has some non-volatile RAM (NVRAM) onboard, you could
use it instead of the EEPROM. This way you will not have to worry
about the EEPROM endurance.
If there is the possibility that the device gets power-cycled within a
single day, you probably want it to preserve the liter count. This can
be achieved by periodically saving this count to the NVRAM, and
restoring it at startup. You can save often, as you don't have
endurance limits.
If the device is started after a full month of being off, if should
notice some days have passed, even it the day number is the same as
when it was turned off. Instead of saving just the day number, I would
store the total number of days elapsed since 2000 Jan 1.

Untested implementation of the above suggestions:
#include <Wire.h>
#include <RTClib.h>

const uint32_t NVRAM_UPDATE_PERIOD = 10000;  // 10 seconds

/* Addresses for data items saved in the RTC's NVRAM. */
const uint8_t ADDRESS_LITERS    = 0x00;
const uint8_t ADDRESS_RESET_DAY = 0x02;

RTC_DS1307 rtc;
uint16_t liters;
uint16_t reset_day;

/*
 * If `liters' has not been reset today, reset it now and update both
 * the RAM and NVRAM copies of `reset_day'.
 */
void reset_liters_if_needed()
{
    uint16_t current_day = rtc.now().secondstime() / 86400;
    if (current_day > reset_day) {
        liters = 0;
        reset_day = current_day;
        rtc.writenvram(ADDRESS_RESET_DAY,
                (uint8_t *) &reset_day, sizeof reset_day);
    }
}

void setup()
{
    /* Pull the initial `liters' and `rest_day' from NVRAM. */
    rtc.begin();
    rtc.readnvram((uint8_t *) &liters, sizeof liters,
            ADDRESS_LITERS);
    rtc.readnvram((uint8_t *) &reset_day, sizeof reset_day,
            ADDRESS_RESET_DAY);
    reset_liters_if_needed();
}

void loop()
{
    /* Periodically update the NVRAM. */
    static uint32_t last_nvram_update;
    if (millis() - last_nvram_update >= NVRAM_UPDATE_PERIOD) {
        reset_liters_if_needed();
        rtc.writenvram(ADDRESS_LITERS,
                (uint8_t *) &liters, sizeof liters);
    }
}

For extra safety you may want to add a large capacitor in order to keep
the Arduino powered for a few milliseconds after being unplugged. And a
circuit that detects when it gets unplugged in order to immediately save
the data and stop accessing the NVRAM before it gets out of juice. This
kind of trick has already been discussed here, you should be able to
find the relevant questions and answers.

58316: <p>How can i restart a variable every day? I have an RTC 1307. The problem is that i cannot use an alarm event because the arduino will be shut down during that hour. So I need a more reliable solution. </p>

<p>This will work? A date could be an integer?</p>

<pre><code>#include &lt;EEPROM.h&gt;
#include "RTClib.h"

int  lastDay;
int EE_ADDR = 0;
int totalLitres;

void setup() {
  EEPROM.get(EE_ADDR, lastDay);
}

void loop() {
DateTime now;
  if (now.day() != lastDay) // this happens exactly once a day.
    totalLitres = 0; // reset the accumulated volume

  lastDay = now.day();
}
</code></pre>
 7508: <p>Here are a few suggestions:</p>

<ul>
<li>Since your RTC has some non-volatile RAM (NVRAM) onboard, you could
use it instead of the EEPROM. This way you will not have to worry
about the EEPROM endurance.</li>
<li>If there is the possibility that the device gets power-cycled within a
single day, you probably want it to preserve the liter count. This can
be achieved by periodically saving this count to the NVRAM, and
restoring it at startup. You can save often, as you don't have
endurance limits.</li>
<li>If the device is started after a full month of being off, if should
notice some days have passed, even it the day number is the same as
when it was turned off. Instead of saving just the day number, I would
store the total number of days elapsed since 2000 Jan 1.</li>
</ul>

<p>Untested implementation of the above suggestions:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Wire.h&gt;
#include &lt;RTClib.h&gt;

const uint32_t NVRAM_UPDATE_PERIOD = 10000;  // 10 seconds

/* Addresses for data items saved in the RTC's NVRAM. */
const uint8_t ADDRESS_LITERS    = 0x00;
const uint8_t ADDRESS_RESET_DAY = 0x02;

RTC_DS1307 rtc;
uint16_t liters;
uint16_t reset_day;

/*
 * If `liters' has not been reset today, reset it now and update both
 * the RAM and NVRAM copies of `reset_day'.
 */
void reset_liters_if_needed()
{
    uint16_t current_day = rtc.now().secondstime() / 86400;
    if (current_day &gt; reset_day) {
        liters = 0;
        reset_day = current_day;
        rtc.writenvram(ADDRESS_RESET_DAY,
                (uint8_t *) &amp;reset_day, sizeof reset_day);
    }
}

void setup()
{
    /* Pull the initial `liters' and `rest_day' from NVRAM. */
    rtc.begin();
    rtc.readnvram((uint8_t *) &amp;liters, sizeof liters,
            ADDRESS_LITERS);
    rtc.readnvram((uint8_t *) &amp;reset_day, sizeof reset_day,
            ADDRESS_RESET_DAY);
    reset_liters_if_needed();
}

void loop()
{
    /* Periodically update the NVRAM. */
    static uint32_t last_nvram_update;
    if (millis() - last_nvram_update &gt;= NVRAM_UPDATE_PERIOD) {
        reset_liters_if_needed();
        rtc.writenvram(ADDRESS_LITERS,
                (uint8_t *) &amp;liters, sizeof liters);
    }
}
</code></pre>

<p>For extra safety you may want to add a large capacitor in order to keep
the Arduino powered for a few milliseconds after being unplugged. And a
circuit that detects when it gets unplugged in order to immediately save
the data and stop accessing the NVRAM before it gets out of juice. This
kind of trick has already been discussed here, you should be able to
find the relevant questions and answers.</p>
