jeroenterheerdt / HAsmartirrigation

Smart Irrigation custom component for Home Assistant
MIT License
308 stars 48 forks source link

[REQ] the delta returned by all calculate() calls should be multiplied by the time that has passed between the first weather data and the last weather data (1 = 24 hours). #289

Closed GiorgioUghini closed 7 months ago

GiorgioUghini commented 8 months ago

I'm struggling about the configuration of the module if I would like to irrigate twice per day, since the calculation of run time is made once per day (i.e. at 11PM). How it is possible to configure the irrigation twice per day? Would it be okay if I configure an automation that is triggered based on a time pattern, call the service calculate_zone(), wait a small delay in order to finish calculations, and check if the zone requires irrigations?

gatonero commented 8 months ago

The integration just calculates the daily duration for irrigation per zone. All the rest happens in your automation. For example you could divide duration by 0.5, stop the irrigation, wait for some time and start irrigation again.

Or run it twice per day and reset the bucket at second time.

{{states("sensor.smart_irrigation_standard_zone_1")|float * 0.5}}

jeroenterheerdt commented 8 months ago

Yes, you could absolutely do that. Call calculate when you want and reset bucket. Just make sure that there is weather data to calculate with before.

GiorgioUghini commented 8 months ago

Thank you both. But then I have a question. @gatonero said it "calculates the daily duration for irrigation per zone". So if I irrigate the first time, I am giving the water for the full day, so the second irrigation, what would it do? The second calculate() call, will report the water missing until 11PM or for the subsequent 24h? I am missing the meaning of the word 'daily' here: "calculates the daily duration for irrigation per zone".

jeroenterheerdt commented 8 months ago

@gatonero is not entirely correct 😂. It calculates the irrigation required based on the data you feed it. So if you do it once per day it takes a days worth of data so calculates essentially for the day. If you calculated every 4 hours would be taking the data for that 4 hours and calculate how much irrigation you need to make up for moisture lost in the 4 hours. Hope that helps.

GiorgioUghini commented 8 months ago

Thank you VERY much, much clearer now. It computes the amount of water required to compensate for the water left in the previous weather data. If you give 24h of history, it is the water required to re-integrate the water lost in the previous 24h. If you give only the last 12h, it does so for 12h. Thank you

GiorgioUghini commented 8 months ago

I'm sorry to reopen this. But I'm still struggling with this setup. The thing that I can't understand is HOW does this integration keep track of the time passed?

Let me explain with a real example:

Time = 9:59 AM
Bucket = 8 L
Weather data = 10 (collected automatically during the last 10 hours)

I do calculate the bucket.
Time = 10 AM
Bucket = 10 L
Weather data = 0

I do call Update weather 10 times, once every minute.
Time = 10:10 AM
Bucket = 10 L
Weather data = 10 (now those have been collected during the last 10 minutes)

I do calculate the bucket, but this time the weather data have been collected in the last 10 minutes,
so I do expect a very small increase in the bucket... At the end, it should compensate for the water
lost in the previous 10 minutes, not 10 hours, instead I got a super increase, like +1.5L.
Time = 10 AM
Bucket = 11.5 L
Weather data = 0

So now let me ask again, HOW does this integration keep track of the time passed when you force calculate (and you need to force calculate if you want to irrigate twice per day, as per this issue response.

gatonero commented 8 months ago

@jeroenterheerdt couldn't this been covered by https://github.com/jeroenterheerdt/HAsmartirrigation/wiki/Automation-examples#example-automation-4-one-valve-with-extra-check-on-todays-forecast-to-avoid-over-irrigation

This example has to be updated to v2.0.

jeroenterheerdt commented 8 months ago

without a diag file created just before each calculate there is no way to tell you what is happening here. But... one thing: the bucket is mm or inch, not L.

GiorgioUghini commented 8 months ago

home-assistant_smart_irrigation_2023-09-28T15-38-27.166Z.log

I dont' know if this is the diag file you were looking for... But the behavior is easily reproducible, please, take a look at this video.

Here, the bucket increases from 4.3mm to 5mm to 5.6mm, in less than a minute. The behavior only applies when you "force calculate". I would have expected that the PyETO takes in consideration the elapsed time since the last calculation to recompute the bucket...

https://github.com/jeroenterheerdt/HAsmartirrigation/assets/23707134/180bd962-4ced-4418-9a5d-fb26f553616a

gatonero commented 8 months ago

Under Settings -> Integrations -> Device you will find the button for the diagnostic file.

grafik

GiorgioUghini commented 8 months ago

Under Settings -> Integrations -> Device you will find the button for the diagnostic file.

The log file I posted is from that exact location. However, having looked inside, I think the video is more auto-explanatory (but you will find both in my post above)...

jeroenterheerdt commented 8 months ago

home-assistant_smart_irrigation_2023-09-28T15-38-27.166Z.log

I dont' know if this is the diag file you were looking for... But the behavior is easily reproducible, please, take a look at this video.

Here, the bucket increases from 4.3mm to 5mm to 5.6mm, in less than a minute. The behavior only applies when you "force calculate". I would have expected that the PyETO takes in consideration the elapsed time since the last calculation to recompute the bucket...

Media1.1.mp4

pyeto has no notion of that. If you calculate, we take the data that you have collected since the last calculate. If the calculation is successful, we delete the data used. So the second time around it's just taking whatever you collected since the last time.

GiorgioUghini commented 8 months ago

The calculation mechanism is fine. The thing that I don't understand is (referring to the video), how is that possible that if I call calculate() twice per minute, forcing 3 weather data manual updates in the meanwhile, the bucket decreases by 1.3mm. It is impossible to lost 1.3mm in 1 minute, no matter what, even if I live in the desert... This is reinforced also by the fact that if I let the software automatically calculate (with both automatic weather updates and automatic calculate() calls), I approximatly lose 2.5mm PER DAY during those days.

GiorgioUghini commented 8 months ago

Ok, so... When you call the service to calculate the delta to be added to the bucket, it goes on until reaching this function: https://github.com/jeroenterheerdt/HAsmartirrigation/blob/ada3224c8166e8aae728ae788c591320338496fb/custom_components/smart_irrigation/calcmodules/pyeto/__init__.py#L75 According to the name of the function "per_day" and to the documentation of PyETO (https://pyeto.readthedocs.io/en/latest/api.html#evapotranspiration), the result is in [mm day^-1]. Thus, if you calculate once per day, this is fine (you multiply by 1day that does not change the result), you can directly add the delta to the bucket. If instead you want to irrigate twice per day, as per this issue, you need to multiply the delta value by 0.5 days (which halves the result!).

Generalizing, in my opinion, the delta returned by all PyETO calculate() calls should be multplied by the time that has passed between the first weather data and the last weather data. This would fix, but let's discuss.

jeroenterheerdt commented 8 months ago

Right, we can definitely add that. The reason why it is not there is that I expect you to calculate once per day. Anyway just great addition!

jeroenterheerdt commented 8 months ago

But how about Passthrough and static modules? How would be handle those? The same logic as proposed for pyeto?

GiorgioUghini commented 8 months ago

The unit of measure for evapotranspiration is millimeters (mm) per unit time.

PyETO states their "unit time" is a day, in fact the output is mm/day.

Static and Passthrough should rely on some kind of ET value set by the user. So the question is: which unit time do we want the user to use? I suggest forcing the user to convert ET values in mm/day so that each module could have the same rescaling function.

If you remember, this is what we did in v1. I remember looking for ET values that some value should be divided by 30 because it was in mm/month. That was a still valid value for ET, but not for Smart Irrigation, which have always expected a "daily" unit time.

jeroenterheerdt commented 8 months ago

right, so that makes sense. Then all calc modules will return values in mm/day (or inch/day) and we apply the same logic to all.

GiorgioUghini commented 7 months ago

Thank you very much for your work.

juacas commented 7 months ago

HI @jeroenterheerdt, thanks for addressing this issue. I've noticed that the hour_multiplier is missing in the calculation of the bucket: https://github.com/jeroenterheerdt/HAsmartirrigation/blob/10e46c3379c88968b7259de8b456699a34e2a9fd/custom_components/smart_irrigation/__init__.py#L615

should be something like:

  hour_multiplier = weatherdata.get(const.MAPPING_DATA_MULTIPLIER,1.0)
  data[const.ZONE_DELTA] = delta*hour_multiplier
  data[const.ZONE_BUCKET] = bucket+delta*hour_multiplier

Regards.

jeroenterheerdt commented 7 months ago

Glad I made this change only in beta 😂