OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › How To: Push notifications for OpenSprinkler
Tagged: qu
- This topic has 54 replies, 1 voice, and was last updated 4 years, 2 months ago by Tygerr.
-
AuthorPosts
-
July 2, 2015 at 12:07 pm #38953
PatParticipantUpdated with the port variable. Feel free to “upgrade” and try it out 🙂
I should probably move all of these settings into an external config file to make it easier to keep track of them.
July 2, 2015 at 1:25 pm #38954
joeParticipantWow , you are fast!
I was thinking of a config option too. That way when new versions come out, it would be easier to deploy.I am new to python and may try a gamble at this myself. If i get it working ill let you know;)
July 2, 2015 at 7:55 pm #38960
PatParticipantI just pushed up to github a rather large update. Broke the script out into a config file, which will make future enhancements a little easier. I also added syslog debugging, which will log messages to /var/log/messages if it’s needed for reference later on.
I’ve been running the new version for most of today and it’s worked great. Try the new version and let me know if there’s any glitches!
Also as part of this update, you’ll need to install the Python YAML library. sudo easy_install pyyaml
https://github.com/drsprite/OpenSprinkler-Push-Notifications
July 2, 2015 at 8:59 pm #38963
joeParticipantNo glitches here. But I didn’t have easy_install for some reason.
I installed it with
sudo apt-get install python-setuptools
then i was good to go.
Thanks for the changes. Wonder what else would be cool to be notified about?
I looked in the API and maybe the water level after a station runs? Could be helpful to know if the stations run quicker than normal..
Water level (i.e. % Watering).July 3, 2015 at 10:54 am #38981
AnonymousInactiveFYI
If you don’t want to use a website to hash, here is what I did on the pi:
echo -n PASSWORD | md5sum
July 3, 2015 at 11:20 am #38982
AnonymousInactiveI think there might be an error in your readme?
9. To start the script on startups and reboots, run sudo update-rc.d ospi_notifications defaults
Shouldn’t it state:
To start the script on startups and reboots, run sudo update-rc.d ospi-notifications defaults
Dash instead of underscore between “ospi” and “notifications”???
July 3, 2015 at 11:26 am #38983
AnonymousInactiveI know NOTHING about python, and am just trying to learn as I go. What could you add to to the ospi_push_notifications.py file to send a notification that a zone has stopped? Maybe say “Zone ‘n’ has stopped and ran for x minutes”?
July 3, 2015 at 1:18 pm #38990
PatParticipantGreat md5 tip, I’ll add it to the README. I’ll also fix my typo, thanks for spotting that!
With the last update I started to think about “Stop” notifications and put a variable in there as a placeholder to get my mind thinking. I think if I set a variable for the current station that’s on, then if a new station comes on, that means the old one is off and send a notification.
Something I’m thinking about.
July 5, 2015 at 10:05 am #39040
PatParticipantI just pushed to github a pretty big update for this little script.
I re-wrote the sprinkler station check so now you can get notifications when the zone starts and stops. I added the water level notification that @jchiar was looking for.
I added more options to the config file, too. You can now select which notification you want to receive, as well as change the notification message from the config file.
Added more syslog logging – never know when it’s needed.
Let me know if you find any bugs!
https://github.com/drsprite/OpenSprinkler-Push-Notifications
July 5, 2015 at 6:00 pm #39049
joeParticipantPat, Its working great! thanks Love the update 🙂
July 5, 2015 at 6:16 pm #39052
PatParticipant@jchiar Interesting. I’m not seeing this error, and the only way I could replicate it was by messing up the YAML spacing. Once I did that, I see that exact error. I’ve learned that YAML can be picky about it’s spacing.
For YAML, the first sub-item is 2 spaces, then 2nd subitem is 4 spaces from the left margin.
There’s 3 things we can try:
1) Re-download the config.yaml from github. This time we can use wget to get an exact copy.
Save a copy of your existing config.yaml and runwget https://raw.githubusercontent.com/drsprite/OpenSprinkler-Push-Notifications/master/config.yaml
from inside /home/pi2) Run this on the command line. It should tell you which line and column is invalid.
python -c "import yaml; yaml.load( open('config.yaml', 'r'), Loader=yaml.Loader )"
For example, if there is an extra space in front of “port”, it’ll return
expected <block end>, but found '<block mapping start>' in "config.yaml", line 3, column 4
3) Lastly, paste your config file into this site to validate it. http://www.yamllint.com/
(You should remove your API keys just in case they track those kinds of things).It should tell you whether it’s OK or if it failed, and where it failed.
July 5, 2015 at 6:19 pm #39055
PatParticipantGlad it’s working! Just curious what the fix was?
I’ll leave those troubleshooting tips up just in case someone needs it in the future.
July 5, 2015 at 6:50 pm #39056
joeParticipantWas a typo I guess in the file. I just recopied the file and re edited it. Weird
July 5, 2015 at 6:51 pm #39057
joeParticipantThanks for the tips though!!
July 6, 2015 at 8:11 pm #39096
nystromParticipantI was able to modify the code so that I can use IFTTT Maker channel for notifications. Also, I have it working on OSBo.
Here is what I added to ospi_push_notifications.py:
# Setup variables from config file .... iftttEventName = config["push"]["ifttt"]["eventName"] iftttUserKey = config["push"]["ifttt"]["userKey"] .... # Send Push Notification .... elif (pushService == "ifttt"): url = "https://maker.ifttt.com/trigger/" + iftttEventName + "/with/key/" + iftttUserKey payload = {'value1': event } #print url #print payload ret = requests.post(url, data = payload) syslog.syslog("Notification sent to %s. Message: %s. Return message %s" % (pushService,event,ret)) #print ret .....
And I added this to the config.yaml file:
push: service: "ifttt" # Acceptable options are "instapush" or "pushover" or "ifttt" ...... ifttt: eventName: "YOUR_IFTTT_EVENT_NAME" userKey: "YOUR_IFTTT_USER_KEY"
July 6, 2015 at 8:37 pm #39097
joeParticipantCool. I use iftt also !
July 6, 2015 at 8:47 pm #39098
PatParticipantLove IFTTT. Great addition. I’ll add it in! Thanks!
July 6, 2015 at 9:10 pm #39100
PatParticipantWorks great! Just pushed it up to github, as well as updated the README to include instructions on how to setup the maker channel and add a new recipe for the event.
https://github.com/drsprite/OpenSprinkler-Push-Notifications
The beauty with IFTTT is you can do whatever you want with this. Doesn’t have to be a push notification. Could be an SMS, an email. So many options! 🙂
Here’s the quick push notification recipe I setup:
July 7, 2015 at 12:45 pm #39119
nystromParticipantThanks for adding the code in. You code was just what I was looking for.
Here are a couple of additions I thought about adding, but didn’t want my code to deviate too much. Maybe add this to the wish list:
1 – Allow the station number to be appended into the IFTTT event name (like is done with the event message.) i.e.’EventName{}’ –> ‘EventName1’, ‘EventName2’, … This would allow different IFTTT actions for different stations. I already tested it, and it does work. Just not sure best way to integrate with existing code.
2 – Retrieve the station names and use them in the event message. Retrieving the names was straight forward, but passing them to the push code was more code deviation. Would be nice to have different replace symbols in the event message to allow different information to be inserted, maybe using regular expression matching and replacement. ( {0} is replaced by station number, {1} is replaced by station name, …) I wrote something, but it is a bit of a hack, as I don’t have much Python experience.
3 – Turn notifications on for only some stations, some actions. My stations are grouped, so that the same stations always run in sequence. I only care when station 1 starts and station 3 ends, and when station 4 starts and station 6 ends. Maybe some kind of data structure in the config that would allow customizing this on a station by station basis. Config data per station would include ‘Push when turns on’ (y/n), ‘Push when turns off’ (y/n), ‘Station name’, ‘IFTTT “value1” format’, ‘IFTTT event name’, …
Just some thoughts for adding to the common code.
Thanks again
July 7, 2015 at 5:38 pm #39122
PatParticipantSome good thoughts. I’ll have to see how to include it – but if you’ve been tinkering already and have the code good to go (and working), feel free to do a pull request on github and I can review it and easily merge it in with the script!
July 8, 2015 at 9:59 am #39125
PatParticipant@nystrom I just pushed to Github an update for part of your request #2 – station name from the OSPi (instead of my old “Zone #” notification).
July 8, 2015 at 1:50 pm #39130
PatParticipantFor those tracking the script for updates, I just updated it again with some bugfixes to the rain sensor and the email error alerting.
July 9, 2015 at 9:51 pm #39172
joeParticipantWill give a whirl at new code tomorrow.
Just wanted to tell you how I am impressed that I was just notified that my sensor detected rain!
How cool is that?July 31, 2015 at 9:14 am #39596
tomParticipantHow about tracking changes to the site configuration, as well? E.g. the water level is set to zero, or whatever?
September 11, 2017 at 9:17 am #47662
wifi75ParticipantHello you can write installation step by step?
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › How To: Push notifications for OpenSprinkler