Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow Alerts #252

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Flow Alerts #252

wants to merge 6 commits into from

Conversation

bb09961
Copy link

@bb09961 bb09961 commented Sep 25, 2023

This code change adds optional Flow Alerts to the OpenSprinkler firmware with no required code changes to the OpenSprinkler UI.

Flow Alerts will be sent via Email, IFTTT or through an MQTT message after a station run is complete if the flow rate exceeds a station's set point.

The station flow rate is calculated by pre-existing firmware logic that divides total volume by total duration in minutes after a station runs for 2.5 minutes or longer.

A station's flow rate set point must be stored as a suffix to the station's name.

**** Station Flow Rates and Flow Rate Alerts are meant for sequential stations ONLY.
**** Station Flow Rates and Flow Rate Alerts will not work for stations running in parallel.
**** Station Flow Rates and Flow Rate Alerts WILL work correctly with stations that are tied to a Master Station controlling a master valve or pump.

Steps to Enable Flow Alerts:

  • A flow meter should be configured on Sensor 1 in the OpenSprinkler UI with the correct Flow Pulse Rate factor.
  • Assign flow rate set points in gallons(or liters) per minute by appending the set point value to the END of each station's name.
  • Station set points must consist of a 5 character number including a decimal point with no trailing spaces. It can be any combination of digits, but must be a total of 5 characters. (For example: 15.10, 05.10, 5.100, 510.0 or 0.000)
  • If a set point is not found or not formatted correctly, flow alerts will be turned off for that station.
  • Use the OpenSprinkler user manual to configure OpenSprinkler for Email notificiations, IFTTT integration or configuring and enabling MQTT correctly.
  • Flow Alerts are not linked to a specific notification event type in the OpenSprinkler UI. Instead, Flow Alerts through Email, IFTTT or MQTT will be enabled for each station individually whenever:
    -- Email notifications are enabled, an IFTTT key is found or MQTT is enabled
    -- a flow meter is configured
    -- a valid numerical set point is found at the END of the station name

Testing Flow Alerts:

  • Assign all station set points to 0.000 and run each station for 3-4 minutes to test the flow alerts and obtain the current flow rate for each station.
  • Pre-existing OpenSprinkler logic requires a station to run for at least 2.5 minutes to calculate the flow rate.
  • It is recommended to run stations for their full normally scheduled durations to determine the most accurate baseline flow rates.
  • Flow rates can vary somewhat with city water pressure or after very short run times, so determining an optimal set point may be an iterative process.

Leak Detection:

  • Flow Alerts can also be used for system leak detection:
    -- Configure an unused\non-wired station with a set point of 0.000
    -- Run the station once a day for 1 hour. If any flow is detected an alert will be sent.

.

Example of station name with Flow Alert Set Point suffix:

image

.

Example of Flow Alert Email Notification:

example_email

.

Example of Flow Alert through IFTTT Email:

image

.
.

Example of Flow Alert MQTT Message format where "+" is the station index number:

opensprinkler/station/+/alert/flow{"flow_rate":5.00,"duration":60,"alert_setpoint":1.00}

Copy link

@booboodoguy booboodoguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good changes.

@booboodoguy
Copy link

I was hoping these changes would be included in your forked repository but unfortunately they are not. Could you please include them. Also since ifttt is no longer free could you finalize the mqtt additions.

@bb09961
Copy link
Author

bb09961 commented Mar 4, 2024

I've now added MQTT message support and all changes are in my forked repository under the Flow-Alerts branch.

MQTT Flow Alert format where "+" is the station index number:

opensprinkler/station/+/alert/flow{"flow_rate":0.00,"duration":0,"alert_setpoint":0.00}

MQTT Message format:   

opensprinkler/station/+/alert/flow{"flow_rate":0.00,"duration":0,"alert_setpoint":0.00}
@booboodoguy
Copy link

I noticed in your current git hub Flow Alerts repository the following "comment code" "flow_gallons=0;" is missing in:

`void turn_on_station(byte sid, ulong duration) {

// RAH implementation of flow sensor
flow_start=0;
flow_gallons=0;

`

`

@bb09961
Copy link
Author

bb09961 commented Apr 21, 2024

I separated that into a separate pull request as I believe it is a bug that should be fixed even if the Flow Alerts Pull Request is not implemented.

Check Pull Request #251 Added flow_gallons reset to Station Turn On

In my repository, that bug fix is in the master branch. I should have created a separate branch to make it clear.

Copy link

@booboodoguy booboodoguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been using this code for a few months now. But made changes to send email messages.

@booboodoguy
Copy link

I have been using your implementation of OpenSprinkler on a Raspberry pi for a few months now. However, the key feature I need is for an excessive flow rate beyond the threshold set point is to stop the station (zone) when this situation occurs. I have made changes to the code to send email messages for all the push notification messages instead of ifttt. I have been studying the code to determine how to add the "stop" upon flow rate error condition. Have you looked into this?

@bb09961
Copy link
Author

bb09961 commented Jun 23, 2024

I'm glad its working for you, that's good to hear.

So, instead of using IFTTT to send emails, you are sending them directly from a web client on the Raspberry pi? That's better because IFTTT is now charging a subscription fee to use Webhooks to send emails for OpensSprinkler.

I would prefer that method as well, but I am using OpenSprinkler hardware and I don't know how to add an email server on the device. I wish they would include that as a feature in the firmware.

Regarding the feature to stop a running station after a flow alert:
Currently, the preexisting firmware logic that the flow alerts were built on calculates the flow rate after the station run is complete. By using this logic, we are unable to stop the station because the alert is only triggered at the end of the run. This was the least intrusive way to implement flow alerts in the existing firmware in hopes Ray would approve the pull request for everyone to use.

However, there is a feature in the OpenSprinkler phone app where it shows the current flow rate in the bottom status bar. This is a real-time rate that is calculated from the last 30ish seconds of water flow. That value is not tied to a specific station, so it would be more complicated to access and constantly compare it against a set point for the running station without interrupting the main logic flow. Also, you would need to think about spikes in flow rates due to initial air pockets and other fluctuations during the run. I think other manufactures like Rachio had to implement some logic to prevent shutting down stations needlessly.

@bb09961
Copy link
Author

bb09961 commented Jun 23, 2024

Also, can you post in your repository the changes to send emails directly from the Raspberry Pi? I'd be interested in looking at them.

@booboodoguy
Copy link

booboodoguy commented Jun 23, 2024

Included is my main.ccp and a shell script that actually sends the mail message. The shell script is activated by a cron schedule. This not the most elegant solution but it does work and never misses a message. Here are the changes I made. They are at the end of the Push Notification function just before the Logging functions. I made a tempfs folder named ostemp to store the message files.

` //char postBuffer[1500];
// BufferFiller bf = ether_buffer;
// bf.emit_p(PSTR("POST /trigger/sprinkler/with/key/$O HTTP/1.0\r\nAlarm Alert Message"
// "Host: $S\r\n"
// "Accept: /\r\n"
// "Content-Length: $D\r\n"
// "Content-Type: Harvey/json\r\n\r\n$S"),
// SOPT_IFTTT_KEY, DEFAULT_IFTTT_URL, strlen(postval), postval);

	//Create file name and location for  mail message
	strcat_P(postval, PSTR("\r\n"));	
	string s = to_string(type);
	string t = ( "sudo mv /ostemp/temporary /ostemp/alert" + s);
	const char* const rename = (t).c_str();					
	
	// Create file with the  postval buffer content for email message
	FILE *file;
	if (NULL==(file = fopen( "/ostemp/temporary" , "w"))) {return;}		
	fwrite(postval, 1, strlen(postval), file);
	fclose(file);		
	
	// Once the file is closed rename it to alert number			
	system(rename);					

my_OS.zip
`

@booboodoguy
Copy link

Some thoughts on how to implement a stop station on excessive water flow.

  1. In the push message "notify_station_on" function add the code to extract the station name flow rate number. Convert the number into gpm *4 as an integer, taking into account the adjustment value, and assign it to a variable "MaxRate"

  2. In the void flow_poll function, right after the "flow_gallons==1" test, add code to capture the "flow_gallons" count during 4 minute periods. Test this value against the MaxRate and if excessive lock a "stop" state in a variable. This will repeat throughout the station run time.

  3. In the "turn off a station" function, in the "// check if the current time is past the scheduled start time" code, add an additional test to see if the "stop"variable state is set to stop. Cause the station to turn off either upon time expiration or a "stop" state.

The 4 minutes could be less but the lower the number the more chance of a false alarm.
I know I'm missing several parameter conversions and some initialization but how does the logic sound to you?

@booboodoguy
Copy link

One other thing to realize is that the running flow count in the app is not accurate as a result of several delays in the do_loop causing miss counts in the flow_poll routine when the app in connected. I have done extensive testing on this and found that the running flow count is not very useful when the app is running and the flow rate is around greater than 4hz. During my station run time the flow sensor frequency ranges from 7 to 15hz.

@booboodoguy
Copy link

booboodoguy commented Jul 27, 2024 via email

@bb09961
Copy link
Author

bb09961 commented Jul 27, 2024

Yes, once the new android app version is released, I'll dig into the firmware code and start testing the Flow Alerts. I may need to make additional changes in order to incorporate the new Email Notifications.

On a side note, I'm not sure why Issue #248 and corresponding pull request #251 wasn't incorporated into the new firmware.
It looks like Ray fixed the flow rate bug you identified. Let him know you also need pull request 251 for a reliable flow rate as well.

@rayshobby
Copy link
Member

Sorry we didn't have time to get this merged into firmware 2.2.1(0) but I will take a look at this for the next release. There are a lot of testing we had to do before releasing a firmware. We have to test it for AVR, ESP8266, Linux, Raspberry Pi, and in fact for Raspberry Pi itself we have to test it under all the cross combinations of hardware (Rpi 0, 4, 5) and Raspbian version (Bullseye, Bookworm) etc. So some PRs will take longer to review. Sorry about that, but it's on our list so it won't be missed.

@bb09961
Copy link
Author

bb09961 commented Jul 27, 2024

I totally understand. Looks like you guys had lots of stuff to test and I'm really glad you were able to add in email notifications. That was a bigger priority for me as well.

I didn't see any comments acknowledging issue #248, so I thought the bug and PR was overlooked. I'm glad to hear it's still on the list to be considered.

Thanks again.

@booboodoguy
Copy link

booboodoguy commented Jul 29, 2024 via email

@bb09961
Copy link
Author

bb09961 commented Jul 29, 2024

Good point, I'll test that out. I don't think I tested all 3 notifications enabled with IFTTT email either.

@rayshobby
Copy link
Member

It should be relatively easy to implement a simple email query to consolidate multiple messages into one email. Is there any reason to have IFTTT and email on both at the same time? The main purpose of email notification is to address the issue that IFTTT requires paid subscription now. If you already have IFTTT enabled, I don't see why you want to enable email as well separately.

@bb09961
Copy link
Author

bb09961 commented Jul 29, 2024

No, I will not use IFTTT and the new Email feature at the same time. I quit using IFTTT and started using MQTT when they started charging for webhooks. But now that email notifications have been added to OpenSprinkler, I intend to switch over to that instead as it will simplify my setup.

My comment before was saying I haven't tested how each of the following alert methods will behave with multiple quick alerts triggered in succession:
IFTTT
MQTT
New OpenSprinkler email feature

I'll test each method individually and report back what I observe.

@bb09961
Copy link
Author

bb09961 commented Aug 11, 2024

I've merged my pull request with the latest firmware. The flow alerts can now be sent via Email, IFTTT or MQTT.

Also, I tested thee notifications types with all of three sending methods turned on at once and they were sent with no problems.

All three of these were sent:
NOTIFY_STATION_OFF
NOTIFY_FLOW_ALERT
NOTIFY_FLOWSENSOR

using these three methods at the same time:
Email
IFTTT
MQTT

@booboodoguy
Copy link

booboodoguy commented Aug 13, 2024

Did you test using the email system on a raspberry pi? If so what was the OS running on the pi?

@bb09961
Copy link
Author

bb09961 commented Aug 13, 2024 via email

@booboodoguy
Copy link

What email service provider did you test the email performance on. I wonder if the email service will effect the probability of missing an email message.

@bb09961
Copy link
Author

bb09961 commented Aug 14, 2024

I'm currently using gmail. I tested it again today with the notifications enabled plus MQTT and I received all three email alerts within 15 seconds.

Wed, 14 Aug 2024 12:24:38
Wed, 14 Aug 2024 12:24:30
Wed, 14 Aug 2024 12:24:25

@opensprinklershop
Copy link
Contributor

Hi, I merged this pull request to the OpenSprinklerShop firmware and also added the "flow alerts" option to the notification options.
https://github.com/opensprinklershop/OpenSprinkler-Firmware
https://github.com/opensprinklershop/OpenSprinkler-App
Android app is also available here: www.opensprinklershop.de/firmware/app-release.apk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants