OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Amazon Echo Alexa Skill for Open Sprinkler
Tagged: Alexa
- This topic has 15 replies, 2 voices, and was last updated 3 years, 2 months ago by ajm1.
-
AuthorPosts
-
March 4, 2017 at 11:18 am #45501
WilliamParticipantI have written a skill (Amazon’s term of art for a program) for Alexa which turns on and off existing Open Sprinkler programs. This is not the sort of thing that Amazon would approve for release due to the need to embed a hashed password.
In order for someone to run it, they would need to sign up on Amazon’s Developers site and Amazons Lambda site (the python code lives here). Then they would then need to upload the python files into Lambda and skill settings into the Developers site. It is a lot of work.
If anyone is interested, I can upload the skill to Git. If you have an Echo it may or may not be worth the effort to you. That’s why I am asking before going to the trouble of setting it up in Git for download.
I also have a skill that causes Alexa to recite the weather report for a personal weather station on Weather Underground.
IFTTT is not utilized in either skill.
March 15, 2017 at 9:24 am #45574
RayKeymasterIs this something that each user would have to do, or would you recommend us as the business owner to do this? We’ve never written Amazon skill before so I am not familiar with the process.
March 15, 2017 at 9:54 am #45577
WilliamParticipantSadly, yes. Each user would have to sign up as a Amazon Developer, sign up for the Lambda site (which requires credit card information) and follow a ridiculously long set of instructions to get the code running. OpenSprinkler would have to be mapped to an external IP with Duckdns or something similar. The external address and port would then be mapped to the skill along with the MD5 password. Because of the required mapping, this would never be a skill approvable by Amazon for publication.
Its a lot of work for most users to shut off or turn on the sprinklers orally! If OpenGaragedoor uses JSON strings, that might make more sense. You could open the garage door with your hands full.
Ray, here is a link for setting up a skill for a Kodi media player. I am including it because the instructions are great. Very detailed. The steps apply to any unpublished skill. https://www.howtogeek.com/249336/how-to-control-your-kodi-media-center-with-an-amazon-echo/
All that being said, It would be fairly complex for you guys to incorporate this. There would have to be some sort of phone based “handshake” like NEST uses to get the IP address and MD5 password into the Skill.
March 15, 2017 at 12:37 pm #45589
WilliamParticipantRay, here’s a video of the skill in action.
March 26, 2017 at 3:22 pm #45684
RayKeymasterWow, that’s really cool, and it’s quite a lot of conversations 🙂 So far I’ve only done Alexa integration through IFTTT, and it requires fixed phases (like turn on xxx zone for 10 minutes). Last time I checked, it hasn’t allowed parametrized phrases, so I can’t say water for xx minutes where xx is a variable. Google Home with IFTTT integration seems to allow parametrized phrases. Anyways, the skill you developed seems a lot more powerful, thanks for sharing.
March 26, 2017 at 4:06 pm #45694
WilliamParticipantThanks Ray, if you ever want to continue the development of something in this direction, let me know. I have the python code that is at least a starting point.
My next project with it will be to add the ability to water zones and not just programs. Its not terribly tricky except you would now have three “slots”. “Alexa water {zone, program} for {1,2,3, etc. minutes}”
You
Bill
April 12, 2017 at 11:08 pm #45857
RayKeymasterCool. For that you can make use the manual run (/cm) (or more generally the run-once program (/cr)) API.
April 21, 2017 at 11:14 am #45965
WilliamParticipantRay, I considered using /cr but decided against it. Alexa often gets things wrong. /cr would require a pretty long utterance (Amazon’s term of art for instructions to Alexa) to be heard 100% correctly. “Alexa, water zone six for 3 minutes, 30 seconds” is about the best I can hope for. Even with that fairly short utterance I have her reply. “Watering has started. Zone 6 will be watered for 3 minutes and 30 seconds. Open Sprinkler reported all is well”. The ‘all is well part’ is triggered by a <200> response code from the JSON call.
It would be really nice to make this available to others, but it would be difficult. First off, I doubt many would be interested. Worse yet, somewhere a reliable, secure server would have to ‘broker’ ( I am sure that’s not the right term) everyone’s usernames, passwords, port numbers and globally mapped I.P. addresses to the Amazon Echo skill. That appears to be what Nest is doing with the thermostat and smoke alarms.
May 31, 2017 at 7:12 pm #46487
WilliamParticipantI would like to have my Alexa skill answer the question; “Alexa, are the sprinklers running today?” Looking over the API, I don’t see an easy way to compose a JSON string that will give the skill enough information to determine if before midnight of the current day, the sprinklers will run. Am I missing something? The phone app seems to do this.
Bill
June 13, 2017 at 1:33 am #46707
RayKeymasterHi Bill, this is a bit complicated. First, because there may be dynamic events (such as rain sensor is activated, or watering percentage is nearly 0% when the program is about to run), the program might not run if these dynamic events are encountered.
Ignoring that, what you needed is very much like a simpler version of the program preview feature. That is, you just need to know whether there is a program that’s scheduled to run today or not (while the preview gives you the complete graphical view of how the programs are scheduled during the day). You are right that there is no API that exposes this simple yes or no answer. The preview feature is implemented using Javascript that runs a software simulation of the scheduler, using the program data (i.e. data from /jp). So to make this work, you will have to get JSON from /jp, and then have a short script that checks the program data and reports whether a program is scheduled to run today or not. If you want to proceed, I can point to you the relevant section of Javascript code in the OpenSprinkler app that implements the preview feature.
June 13, 2017 at 8:59 am #46742
WilliamParticipantYes! If you can point me to the relevant code, that would be a big help. I can translate the Javascript into Python and be on my way.
On another topic, I will likely post on the OpenGarage forum, I have been thinking about an Alexa skill for OpenGarage. I am pretty sure that your code and hardware would need modification to make it work. Alexa, depending on where it is in the code, times out in three seconds. This can not be changed. The delay() function, if used, is ignored. My garage door takes about 8 seconds to open. The OpenGarage skill would have timed out before it tripped the rangefinder for confirmation of success. I think, perhaps, the solution is to use an audio sensor (the simple ‘go/no go’ kind) to detect that door is in motion. Immediately after an open/close command is sent the skill could get back a JSON string with ‘sound’ ‘yes/no’ and say something like ‘<pause> good, I can hear it moving <pause>’. This would take up enough time for the door to finish moving before the timeout and confirmation of success could happen with the rangefinder as usual. I have been working with the EPS8266 variants lately and they are pretty nice.
I need to think about this a little more and then I will get something up on the other forum.
June 13, 2017 at 10:11 am #46754
RayKeymasterFirst, about OS program preview code. Here is where the preview is calculated:
https://github.com/OpenSprinkler/OpenSprinkler-App/blob/master/www/js/main.js#L6451
through it’s quite long, what’s most relevant to your need is the checkMatch function. There are a few different versions of it, assuming you have firmware 2.1.6 or above, you should look at the checkMatch216 function:
https://github.com/OpenSprinkler/OpenSprinkler-App/blob/master/www/js/main.js#L7026
this function calculates whether a given time matches any of the start times (including additional start times) of a given program. Since all you need to know is whether there will be any program that runs on a given day, what really matters to you is the checkDayMatch function:
https://github.com/OpenSprinkler/OpenSprinkler-App/blob/master/www/js/main.js#L7041
I know there are still a bunch of details you have to figure out, but hopefully this gets you closer.About OG: I suppose a useful thing to add to the firmware is a variable (or it could be the same door_status variable) that indicates whether an action has been triggered but the door status hasn’t changed. For example, when opening the door, if the action has been triggered but the door status hasn’t changed to open, the variable will report ‘opening’ or something like that. Would this fit your need?
June 13, 2017 at 10:23 am #46761
WilliamParticipantThanks. I will work on the addition to the sprinkler skill.
Yes. Regarding OG, yes, I think that would do it. I was thinking about adding the sound module, but that is probably overkill. The detection of the ‘opening’ variable would result in ‘<2s pause> Good, the door is moving <2s pause>’. That reply would burn up enough time that a timeout inside of my ‘while’ loop would be avoided.
June 17, 2017 at 3:43 pm #46825
WilliamParticipantRegarding a daily preview in my Alexa skill, Got It! The links you sent me were a big help. I know a lot more about binary operators in python than I did 4 hours ago.
There are some limitations to my work. Alexa answers “The sprinklers will <not> run today.” If weather adjustment is TRUE, she adds “Weather adjustment may inhibit them, however.” If there is more than one program, all are tested, however, if there is more than one board the program will terminate cleanly with a status error.
Since I am not using odd/even, I will leave that code for another day. Once I am sure this much works right, I will add that test. Adding odd/even testing will be a bit involved since my code structure is not all it should be.
Thanks again. Now my wife can tell if it is safe to go out in the yard to feed the cat.
If any one needs this Python code, I can post it with my info redacted.
** Edit **
Should others follow in my footsteps, here is an odd problem. If you host your Skill on Amazon’s Lambda site you may run into a time zone problem. The Lamda site apparently runs on UTC, so the datetime.datime() python function will return times and days UTC, not local time. If you test your code on your desktop it may run fine, but the same code uploaded to Lamda gets the date or day of week wrong! Naturally, this could effect things other than Open Sprinkler. I have not noticed this peculiarity documented anywhere. The solution is to use the pytz library to make datetime.datetime() time zone aware. None of this is a problem if you live in Greenwich England!
One other thing. You can not name your skill OpenSprinkler, either with or without the space between open and sprinkler. Open is a ‘reserved’ word.
January 22, 2021 at 6:06 pm #69116
bcolbertParticipantHello all.
A bit of a stale conversation but has this progressed or been made more “public”? I can hack away at both python and js if someone can point me in the right direction.
Thanks!
July 16, 2021 at 9:45 pm #70694
ajm1ParticipantOut of curiosity, why are hashed passwords required? Understand I know nothing about skill development, but could write code to accept network traffic on the Raspberry Pi to authenticate the network traffic / request and pass a command to my custom opensprinkler based design. I think that would be awesome.
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Amazon Echo Alexa Skill for Open Sprinkler