OpenSprinkler Forums OpenSprinkler Unified Firmware Amazon Echo Alexa Skill for Open Sprinkler

Tagged: 

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #45501

    William
    Participant

    I 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.

    #45574

    Ray
    Keymaster

    Is 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.

    #45577

    William
    Participant

    Sadly, 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.

    #45589

    William
    Participant

    Ray, here’s a video of the skill in action.

    https://1drv.ms/f/s!AmXKqAwyCrbxhq9Y6SGGk4MUOMVvxg

    #45684

    Ray
    Keymaster

    Wow, 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.

    #45694

    William
    Participant

    Thanks 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

    #45857

    Ray
    Keymaster

    Cool. For that you can make use the manual run (/cm) (or more generally the run-once program (/cr)) API.

    #45965

    William
    Participant

    Ray, 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.

    #46487

    William
    Participant

    I 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

    #46707

    Ray
    Keymaster

    Hi 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.

    #46742

    William
    Participant

    Yes! 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.

    #46754

    Ray
    Keymaster

    First, 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?

    #46761

    William
    Participant

    Thanks. 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.

    #46825

    William
    Participant

    Regarding 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.

    #69116

    bcolbert
    Participant

    Hello 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!

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums OpenSprinkler Unified Firmware Amazon Echo Alexa Skill for Open Sprinkler