A problem I have and asking for ideas on how to address the "problem"

Yes, I know there is an "easy" solution, but.....

TLDR:
I have an arduino - with RTC - to water my plants.
There is no easy way to change the RTC time. (Stupid me)
It triggers at mid day.

Me, being anal, don't have it always powered. I use a Tasmota powerpoint and turn it on at 11:55 and off at 12:05 each day.
This has a bonus feature that if it is raining, I can not turn it on and the day is skipped.
That was a nice feature I got when I started playing with N-R.

AND there is no "Summer time" adjustment, so I have to have TWO schedules.
One for normal time and one for summer time.
Anyway.....

Until I noticed things weren't adding up.
Long story short: the time on the RTC was drifting.

The workings:

There are 3 modes the flow has:
From mid-night
At the time specified
From Dawn

The first and last:

Every hour it queries the weather and checks if there is rain.
If the total rain for that day exceeds a value, the day is skipped.

The middle one:

At 11:55 the signal is sent and the weather is checked.
If it is pissing down then things are aborted. (as per the other two modes)

Thoughts on how things work:

The first/last ones allow for rainy days to be avoided.
Their start times differ only in that if it is going to be a slow wet day or a somewhat wet day.
That the reading are taken ON THE HOUR was academic - and maybe still is - as their totals are added and though the Mid-day one is not included, I would still get a somewhat of a picture of the rain events leading up to then anyway.

Temporary solution:

I've modified the times so it turns on at 11:40 and off at 11:59 giving a window of 20 minutes rather than 10.

Problem:

1 - The RTC things it is 12:00 at 11:50, so a lot of watering was being missed.
2 - Checking the weather ON THE HOUR.

The one I use most is the middle one: Check at the given time.
Which is easy enough:

Send signal
  |
  |
check weather
  |
  |
Enough rain?   (Abort)
  |
  |
Water plants

The other ones are kind of:

Hourly signal starting at determined time depending on mode.
  |
  |
get weather/rain
  |
  |
Add cumulative rain
  |
  |
Mid day
  |
  |
Enough rain?  (Abort)
  |
  |
Water plants

There is more code but keeping it simple for what I want to do.

But me being me the other ones - on the hour - bug me.
If it is now turning on at time:40 shouldn't I check the weather at those times and not on the hour?

But Adjusting the hourly signal (cron+ node) would not be easy.

I'm over thinking it - aren't I? :slight_smile:
It works as is.
It doesn't need to be THAT in sync with things.

Thoughts?

What model Arduino are you using?
Is the RTC built-in or an add-on board?

When you fire up the power point (smart plug?), Tasmota almost certainly syncs it's clock with the internet so you could maybe use the Tasmota time?

The Arduino is a very early UNO model. 5v I/O pins.

The RTC is an addon board. I2C bus.

Ok, to better explain:
ORIGINALLY it was built as a stand alone unit - which it still kind of is.
It has an RTC so it waters the plants daily at a given time.

That as being built when I started in NR.

It was completed, but I would daily turn the power on/off around 12 and off some times after it was done.
That wasn't good.

ITMT, I got into NR. After than I discovered Tasmota and it's Smart plugs (Yeah, forgot that name before. Sorry.)

Ah! So the RTC was kinda redundant as I would turn the power on/off with the smart plug daily.
Tangent: This was NEARLY done, but there were problems with the Pies and power supplies I believe and there was a whole world of hurt there.
So kinda good it was never implemented in that way.

The Arduino has little memory and no network connectivity. Be it Cat-5 or WiFi. None.

So, the power would turn on at 11:55 and off at 12:05 - sorry if I got that wrong earlier. As the RTC (Arduino) would do it's stuff at 12:00. 5 minutes either side.

Then, I noticed the water (in the tank) wasn't going down as expected.
Also a couple of times I was home at/near the time and I would hear the Smart plug turn on and usually it would be 5 minutes and the plants would be watered.
But I heard virtually NO GAP between the plug being turned on and the plants being watered.

!!??
:confused:

Luckily it shows the RTC time/date on boot and I noticed it was saying 12:00 at 11:55.
A-ha!
So, I had to Wind the times back a bit.
Now I am settled on 11:40 - 11:59. Dunno what the RTC is doing.
(As stated, I didn't include code to adjust the time. Never thought of it when writing the code.)

So, what was Originally 12:00 is now...... 11:50?
I am hung up on when the preceding readings are made. As it stands (in the NR world) on the hour.
But that isn't aligning with the RTC/Arduino's time.

Does it matter?
Probably not.
As explained in the first post.
But it is bugging me and I have to ask/get an external perspective.

Clearer?

Possibly. :smiley:
I guess that the smart plug switches mains voltage, while the Arduino provides 5V for the water pump.

If there is a GPIO pin available which is always +5V while power is on, can you connect the water pump to that?
Then the Arduino programming and RTC become irrelevant, you are just making use of the Arduino's power supply. The pump should run during the exact times when the Tasmota plug is ON.

But I'm assuming that Node-red on your Pi has the right time and there is no RTC on a Pi.
I seem to remember that you have your own NTP server.
So if Node-red is setup to send power ON at 12:00, power OFF at 12:10, does it actually do so with sufficient accuracy?

Well......

:wink:

Not quite.

You lost me.

Where?

On the smart plug?

That's a sealed unit. I don't want to play with it.

Being an Early Arduino it has a 12v barrel input.

So I have a 5A 12V PSU.

The Arduino has 5 outputs that drive open collector transistors that switch 12V relays to switch 12V Solenoids and the 12V pump.

The pump pulls about 3A. So I can't just connect it to an Arduino I/O pin.

WRT the PI, correct.
It's time is correct. (If there is such a thing)

Now, yes. Earlier on: NO! It was a whole world of hurt.
It is actually 11:55 to 12:05 (5 minutes either side of the actual desired time. Well, 5 before about 4 after as the run time is about 1 minute)

(Going way off topic, but....)

What I'd love it to have an arduino with Wifi.

Then, I could control the Mains voltage with the smart plug, and call things to action with the WiFi.
That would be great in that I would get better feedback from the device also.
Confirmation power was applied (though academic)
Times for each output being active.
Time when all complete.
Then it would turn the main power off.

But that is a whole redesign as power levels and all that stuff.
I built it for 5V working and most of the new Arduinos are 3.3V.
And they don't have the power ratings of the older ones either.

For the fun of it:

This is the dashboard

Sorry it is not a nice fit.
I need to zoom to that level so the buttons are correctly laid out.

OK I misunderstood the power requirements of the pump.

An ESP32 can be compared to an Arduino with wifi.
You can program it with the Arduino IDE, or alternatively it can run Tasmota.
But of course it's gpio pins are 3.3V.

Some folks on the forum would no doubt knock up a tiny PCB design in a few minutes to take an ESP and relays & have half a dozen copies manufactured in China, all for the price of a pint of ale.

But if your current problem is just that the RTC is out of sync... You must have been able to initially set it, can you do so again?

Well, yes I can.

I just have to flash it a couple of times.
Once to set the time to NOW and the second time to reload the program.

I was more WORRIED about the times.

As the trigger time is now time:50 for the plants to be watered, can I make the hourly weather check reflect that too?

But I am sure it is just me being too OCD on it as I explained.
In the bigger picture, it doesn't really matter anyway.

Originally all things happened at time:00 not time:50

Where is the pump getting power from ? If it’s mains powered why not just turn it on and off via the smart switch directly rather than use the arguing at all.

Good question.

The pump is 12V DC. 3 Amps (there about)

This was my early days of Arduino when they did 12V barrel jack inputs.
I'm a 12V person.
It is also a bit safer than playing with 240 VAC.
And 5v doesn't quite do anything for a 12V solenoid.

So the story is a bit more complicated than just ONE output.
There are 5 pots to water. (Solenoids mentioned)

So, each one has a different Run time (need for water).

There are 5 relays (6 actually, but anyway)
Each relay has 2 poles. DPDT if you will.

One of those is commoned (how ever you spell it) together so if ANY relay is active, the pump gets power.
The other POLE controls the solenoid.
(Note: the next solenoid is turned ON be fore the existing one is turned OFF to keep smooth pump running)

There is a 12V 5A power supply powering it all.

So I can't just use the smart switch/plug as there would be no control of the solenoids.

Clear?

If you REALLY want, I can dig up the schematics.

Ok so the 12v comes from somewhere. Probably a power brick to the mains ? Does it just drive the pump Or does the 12 v go other places that have to be on all the time ? If not then you could still control the power to the pump, and use a gpio on the arduino to detect the 12v being turned on ( via suitable isolation) and use that to trigger your sequence directly.
Or indeed if the arduino is also powered up at same time then just start the sequence at that time

The 12v is for this only.

It was built to water the plants as I get eaten by mosquitoes.

(We are kinda getting off topic)

The pump is controlled by any of the 5 relays.
Each of them (each? any?) control their solenoid. (12V DC about 1Amp needed)
When that relays operates, the solenoid ..... opens, and the pump is turned on.
After the prescribed time the next relay operates and the existing one releases.
(less than 1 second switch over time)
This repeats until all 5 relays have had their turn and all 5 pots are watered.
The last relay releases and all things stop.

ALL things are 12V DC.
I don't like playing with 240VAC. I can, but it is not preferred. Things can get nasty.

As explained way earlier, I was about to make an option that as soon as power is on, it would cycle the sequence.

But as said: there was a whole world of hurt with power supplies for the Pi's.
So it was aborted.
Yes, now things are stable, I could go back to that methodology.

I am only asking about my compulsive obsession with the time mis-match that is now happening.
(As explained)

It is probably not a problem - my concern - but I was wanting an outside check.
Do you lot want the schematic? I have it somewhere as it is a good project I designed.

Though not perfect, this is a schematic to show enough of how it works.
(I hope) :wink:

I'm old school and did it on paper.

Might be time to re-think your setup and consider a newer microcontroller. For example, there are many controllers with built-in WiFi, ADC pins, I2C and some with loads of RAM and flash.

Reading through your thread it seems the decision on whether to water or not is based on whether it is raining or will rain today.

I built a Moisture Detector and Water Pump Controller as a project a year or so ago. The approach I took was to check the moisture content of up to four pots of herbs and if any needed "water" then turn on an irrigation pump. Although the system could work autonomously, for most of the time it would report moisture, temp, humidity, air pressure, ambient light level, battery voltage back to Node-RED using MQTT. Likewise, Node-RED could send commands to the Controller to force or stop a watering sequence. To prevent corrosion of the moisture-probes - the power is only turned-on just before a set of readings are taken.

In case you are interested, I've managed to find the schematic and some views of the board.

Schematic.pdf (97.2 KB)

Noice!

:wink:

Mine was a bit of a test bed to save me being eaten alive by the mosquitoes.

I was going to have moisture sensors and all that, but it just became too complicated.
(And getting the wires from the board to the pots.)

The question I am asking is to do with the RTC drift.
Originally the check time is/was 12:00 (mid day)
But the time in the RTC has moved about 10 minutes fast.
My weather polls still happen at/on the hour. Not 10 minutes before.
I was wanting to .... tweak the time so it matches the active time rather than the "on the hour" one.

But I feel/fear it is of no real difference.
If DAWN or FROM MIDNIGHT is selected, the number of readings being made doesn't matter 10 minutes here or there.

But TOP POINTS for that board.
Way above what I can do.
Mine is vero board and a lot of wires. :wink:

It is a misnomer to think that RTC's retain absolutely the "correct" time. So I'm not surprised you are seeing drift, only that it has taken a while to spot it.

Since you don't have any remote access to that device (did I get that right?), one less than perfect option would be to automatically apply a time adjustment when the device powers up. I suppose that if you wanted to get clever, you could use some of the Pi's GPIO to allow external serial access and add a startup script such that you could externally set an offset.

However, all of that seems rather excessive when you could buy a dirt-cheap ESP32 dev board and use ESPHome so you don't have to mess with C++. Then you can connect to it via Wi-Fi if yours reaches the right place, or local BlueTooth, or even Zigbee (with some of the ESP32's). If you need to stretch wireless signals, you could also use ESPNow mesh.

Alternatively, a power adapter to take mains from your remote plug down to 12v - old laptop power bricks are good for this and also cheap and safe.

PS: If thinking about using NTP to correct the RTC from the Internet, remember that you generally have to be within a certain time tolerance for that to work.

I think Dave's is by far the most elegant suggestion:

Plug the 12V PSU for the pump into a smart plug with Tasmota.

Node-red mqtt sends power ON and OFF at the right times.
(Or just send ON and use pulseTime in Tasmota to turn off after 5 minutes or whatever)

No need for the Arduino, nor it's RTC or relays.

I use these Tasmota-MQTT smart plugs for turning things on/off around the house/garage.
https://www.aliexpress.com/item/1005009260021549.html
I'm sure there is a version with an AU style socket.

Well that particular one measures power consumption but it does not have a relay so no use for switching things on/off.

I have a mixed bag of Gosund UP111, JulesV and Localbytes.
China is very good at reselling the same thing under different names.

The localbytes ones, a British company but surely manufactured in China, came with a Tasmota preinstalled, the older ones had to be flashed, but over wifi, no dismantling required.