Voice Control the £20 way

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • tizwaz
    Automated Home Sr Member
    • Aug 2007
    • 58

    Voice Control the £20 way

    I’m fascinated by voice control and the possibilities around using a smart speaker, in my case an Alexa. It would be very easy to buy a bunch of smart plugs & bulbs etc, but then I’d have two systems, and I love the reliability of Cortex (I still run mine on a Win XP, it’s been going over a decade).

    Not having a clue how to integrate the two in a programming way, I’ve gone down the hardware route which I thought I’d share in case you were interested. (forgive me if you do this already!)

    For £20 I can now control 4 ‘things’ with my voice! I bought this off Amazon:



    module.jpg

    It’s basically 4 relays that you can control via Wi-Fi. Except you can also control it via an Alexa skill, which means you can set up routines with Alexa and say any words you like to set the routine going. It's powered by an old phone charger.

    I’ve connected the 4 relays to some spare inputs I had on a QRI Din module, told Cortex they are buttons, and anything you can control via a button I can know control with my voice. If I want more than 4 actions, I may buy another, I still have some spare inputs!

    Chris
    Attached Files
  • cliffwright
    Automated Home Guru
    • Mar 2007
    • 117

    #2
    Pre-Context: I'm a cynical bugger when it comes to Voice Assistants ..

    a) I don't like the privacy side of them (yes, go on, take the piss out of my tin-foil hat wearing ways - I'm used to it )
    b) I don't like how Alexa (other voice assistants are available) isn't "that" reliable I find personally (I asked for "Dance Music" the other day, and I got "Dog Music". Did you even know Spotify had a "Dog" playlist FFS?!)
    c) I find that any use-case I've come up with, actually takes longer to say "Alexa, Alexa ... ALEXA ... turn the thing on please" takes longer than simply pushing a button, even if that means walking across the room or pressing a button on my phone.

    So short of when I'm cooking and happen to have my hands caked in oil or something, I can't bring myself to care about Voice assistants too much .. that said, I do use them to some degree ... and I'm interested in what you're using it for though ... what use-cases are you using it for? What devices / automations are you triggering with it?


    How I use voice, and if you wanted to integrate more than just a few things, you'd be better off using Software rather than more and more hardware. Are you an Android (Boo, hiss) or iOS user?

    If you have iOS devices and are willing to use Siri, then you can leverage the newish iOS "Shortcuts" feature, which you can very easily setup any shortcut to call a Cortex Web API and control a device. For example, my main use case is that I have a shortcut called "Garage Door" ... which fires a Cortex Web API .. which in turn presses a button on a 1 button module connected to my garage door controller. This means;

    a) I have a button on my iPhone "home" screen that when pressed, opens the garage door. (I now leave the door key-fob in a drawer, I just use my phone).
    b) I can say "Hey Siri, Garage door" ... and she'll open it for me

    This way, you've got Zero hardware to buy .. unless you want to buy an Apple voice assistant speaker .. and can control ANY module (or modules... you could fire several web requests in the 1 automation) in Cortex .. plus setup a load of logic or routine around it too
    www.clifford-wright.co.uk/blog

    Comment

    • tizwaz
      Automated Home Sr Member
      • Aug 2007
      • 58

      #3
      The thing is I read the words Cortex Web API, and my brain translates that to blah blah blah….

      All I’ve achieved is the ability to sit in front of the fire with a large glass turn the telly on and say “Alexa, TV lights”, which starts a macro that turns some lights off, and dims a few more etc.

      Or I can say “Alex, close the blinds” or “Alexa, open the blinds” and the blinds on our Velux roof windows do their thing.

      Likewise “Alexa, open the roof”, and again the Velux’s respond. Like I said anything is possible, as long as it can be controlled via a digital input on Cortex.

      I'm stilling working on "Alexa, top my glass up"

      There’s nothing wrong with a bit of voice assistant cynicism, but not sure how asking you phone to do something via a voice request is much different to asking a smart speaker….?

      Comment

      • cliffwright
        Automated Home Guru
        • Mar 2007
        • 117

        #4
        Sounds good - if it works for you - then why not ... but for every "feature" you want to add, you're going to have to have 1 relay from these boards, plus an input on a QRI (or any other module with Digital input). With the web API, you don't need either - you can have hundreds of voice commands, and need no additional hardware (assuming you've got an iOS device)

        The Web API basically allows you to in effect, "press" any button / input through a web-request (basically set any state of any object). So pretty much all is happening is you're hitting a URL of "https://yourcortexserveraddress/api/v1/Objects/123?0=1" which is the digital equivalent of your pressing button 1 on your module, or pulsing the digital input on your QRI - it's just a software equivalent.

        How have you got your Velux control hooked up btw? I've got wireless electric Velux and the wireless protocol is Velux's own and encrypted, so you can't mimic the remote .. is yours a wired system rather than wireless? I'd love to get mine hooked up ..


        but not sure how asking you phone to do something via a voice request is much different to asking a smart speaker….?

        It's not ... I just don't have a Siri based speaker (yet), so I can "only" use my phone / iPad. In my use-case, the phone is good because I use it for opening the garage door as I drive up to the house where clearly a smart speaker sat in the house won't hear me
        www.clifford-wright.co.uk/blog

        Comment

        • chris_j_hunter
          Automated Home Legend
          • Dec 2007
          • 1713

          #5
          very interesting thread ... !

          Cliff, when I try your :

          "https://yourcortexserveraddress/api/v1/Objects/123?0=1"

          with my codes substituted, of course

          the response is "Invalid user or password" ...

          so, should there be more in the string ??

          NB: to try it out, I was using Applescript (as an extreme novice), including the line :

          do shell script "open -a Safari 'https://yourcortexserveraddress/api/v1/Objects/123?0=1'"

          Chris
          Last edited by chris_j_hunter; 26 November 2020, 07:32 PM.
          Our self-build - going further with HA...

          Comment

          • tizwaz
            Automated Home Sr Member
            • Aug 2007
            • 58

            #6
            In response to your Velux question, I too have wireless windows/blinds. I control mine via a Velux KLF 200 interface that provides open & close control via 3 pins. Open/Common/Close which I've hooked up to a relay in a DRH-002. Here's a pic
            klf.jpg

            They are not hugely cheap, but solves the problem and has never failed. It doesn't give you the fine or individual control like a Velux control pad, but I've never needed to do anything other than to open and close them.
            Last edited by tizwaz; 26 November 2020, 07:59 PM.

            Comment

            • cliffwright
              Automated Home Guru
              • Mar 2007
              • 117

              #7
              Originally posted by chris_j_hunter View Post
              very interesting thread ... !

              Cliff, when I try your :

              "https://yourcortexserveraddress/api/v1/Objects/123?0=1"

              with my codes substituted, of course

              the response is "Invalid user or password" ...

              so, should there be more in the string ??

              NB: to try it out, I was using Applescript (as an extreme novice), including the line :

              do shell script "open -a Safari 'https://yourcortexserveraddress/api/v1/Objects/123?0=1'"

              Chris
              I'm not sure about Applescript, but however you make the request, you need to set a header key-value pair in the API request of "Authorization" "Basic <your base64 encoded value that represents your Cortex username / password>"

              You can generate the encoded value of your username / password combination by either;

              1) Use this website (or any other like it - there's a few) - https://www.blitter.se/utils/basic-a...der-generator/
              2) Download Postman, setup the API call you're trying to fire in here (which has the added benefit that you can test if from here too), set "Basic Auth" in the Authorization tab, enter your username / password, then view the "Code" that Postman will fire - this is your encoded value.


              Shout if screenshots of anything would help :-)
              www.clifford-wright.co.uk/blog

              Comment

              • cliffwright
                Automated Home Guru
                • Mar 2007
                • 117

                #8
                Originally posted by tizwaz View Post
                In response to your Velux question, I too have wireless windows/blinds. I control mine via a Velux KLF 200 interface that provides open & close control via 3 pins. Open/Common/Close which I've hooked up to a relay in a DRH-002. Here's a pic
                [ATTACH=CONFIG]1687[/ATTACH]

                They are not hugely cheap, but solves the problem and has never failed. It doesn't give you the fine or individual control like a Velux control pad, but I've never needed to do anything other than to open and close them.
                Very interesting - thanks .. Like you, 99.9% of the time it's either Open or Close ... not 50% open etc so this'd work fine. I'll look into it :-)
                www.clifford-wright.co.uk/blog

                Comment

                • chris_j_hunter
                  Automated Home Legend
                  • Dec 2007
                  • 1713

                  #9
                  Cliff - many thanks ...

                  have tried & tried, but still having trouble !

                  successfully got the encoded value, but can't work out how exactly to include it in the request - have tried everything I can think, without luck !

                  sending this :

                  http://xyz.ab.cd.efg:hijkl

                  of course results in the Cortex log-on window, waiting for User Name & Password to be entered manually ...

                  and sending this :

                  http://xyz.ab.cd.efg:hijkl/api/v1/Objects/123?0=1

                  results in the message Invalid user or password

                  which seems to give a clue, but no matter how I then add in (have tried a dozen ways)

                  Authorisation & Basic <abcdefghijklmnopqrstuvwxyz12345=>

                  I get the same message - Invalid User or password
                  Our self-build - going further with HA...

                  Comment

                  • cliffwright
                    Automated Home Guru
                    • Mar 2007
                    • 117

                    #10
                    Originally posted by chris_j_hunter View Post
                    Cliff - many thanks ...

                    have tried & tried, but still having trouble !

                    successfully got the encoded value, but can't work out how exactly to include it in the request - have tried everything I can think, without luck !

                    sending this :

                    http://xyz.ab.cd.efg:hijkl

                    of course results in the Cortex log-on window, waiting for User Name & Password to be entered manually ...

                    and sending this :

                    http://xyz.ab.cd.efg:hijkl/api/v1/Objects/123?0=1

                    results in the message Invalid user or password

                    which seems to give a clue, but no matter how I then add in (have tried a dozen ways)

                    Authorisation & Basic <abcdefghijklmnopqrstuvwxyz12345=>

                    I get the same message - Invalid User or password

                    OK - hopefully the following helps - sorry if the detail is too low, but will hopefully cover off any detail that might be missing / tripping you up;

                    1. Make sure the Cortex object you're trying to control here is "Web enabled" and you've granted "Web API" permissions to your user in the Web server options of the object. (Clearly here, make sure you know the valid username / password too ... sometimes it's the simple things that trip us up the most!)
                    2. Install Postman or an equivalent - and setup a GET request as follows;

                    a) Select the Request Type as GET
                    b) Set the URI as http://<yourcortexIP>:<yourcortexPort>/api/v1/Objects
                    c) On the Authorization tab, select "Basic Auth" as the auth type, and enter your username / password

                    This should give you a request such as follows;



                    If you can hit this and get a successful response, you know your Auth is sorted.

                    From the JSON body you get back, you can find the object you're interested in controlling and either use the FriendlyName value, or the IDNumber (which I prefer in case you ever rename an object).

                    Using the same GET request above, append the object IDNumber or friendly name as a query param in the URI so you have;

                    ...api/v1/Objects/504
                    or
                    ...api/v1/Objects/My Lounge Light

                    ... and fire this. The JSON you'll get back will give you a Port array, within which you'll see;

                    {
                    "PortNumber": "5",
                    "Description": "Turn On",
                    "Type": "In"
                    },

                    Using this, you know that Portnumber 5 is what you'll need to use to Turn this light object on.


                    Using this, construct a POST request similar to the above, such that you've got;




                    which gives you a request of;

                    POST /api/v1/Objects/504?5=1 HTTP/1.1
                    Host: 192.168.1.254:9083
                    Authorization: Basic Q2xpZmZTYW1wbGVVc2VyTmFtZTpNeVNhbXBsZVBhc3N3b3Jk

                    ... which also gives you the base64 encoded value of your username/password combo.

                    Firing this, will then instruct Cortex to "Turn On" this light object

                    You can then reconstruct this request into whatever application you're going to use to command Cortex from (In my case an iOS Shortcut).

                    Shout if you need anything else or have more questions
                    www.clifford-wright.co.uk/blog

                    Comment

                    • chris_j_hunter
                      Automated Home Legend
                      • Dec 2007
                      • 1713

                      #11
                      Cliff -

                      many thanks, much appreciated ...

                      will find a quiet moment later, and get stuck in ...

                      Chris
                      Our self-build - going further with HA...

                      Comment

                      • chris_j_hunter
                        Automated Home Legend
                        • Dec 2007
                        • 1713

                        #12
                        Cliff ...

                        many thanks, did get it to respond, but did not get useful information ...

                        tried all sorts, left it a day or two, and tried again - still no joy !

                        eg:
                        Attached Files
                        Our self-build - going further with HA...

                        Comment

                        • cliffwright
                          Automated Home Guru
                          • Mar 2007
                          • 117

                          #13
                          Ah OK .. this is good, it means you've sorted your Authentication out ... 1 last thing to do then; if you go to the "Tools" menu in Cortex, then to the "Cortex API" option, select the "Options" tab at the bottom and change the "Default API Syntax" drop-down to be "JSON" (or XML if you'd prefer) .. I assume yours is currently set to "Synapse" instead judging by your screenshot.


                          e655fd3e-bb7c-44e0-a374-433a67f8f8f2.jpg
                          www.clifford-wright.co.uk/blog

                          Comment

                          • chris_j_hunter
                            Automated Home Legend
                            • Dec 2007
                            • 1713

                            #14
                            Cliff -

                            magic ...

                            26660 lines of useful info' - 5.65s to produce, 883.38KB

                            many thanks !

                            Chris
                            Our self-build - going further with HA...

                            Comment

                            • chris_j_hunter
                              Automated Home Legend
                              • Dec 2007
                              • 1713

                              #15
                              Cliff -

                              OK, I can now (eg) switch lights on & off by sending POST requests from POSTMAN ...

                              but it does this without making the request it actually posts visible ...

                              ie: without showing the equivalent of the example you posted - which was

                              POST /api/v1/Objects/504?5=1 HTTP/1.1
                              Host: 192.168.1.254:9083
                              Authorization: Basic Q2xpZmZTYW1wbGVVc2VyTmFtZTpNeVNhbXBsZVBhc3N3b3Jk

                              I've tried all sorts, but again drawn a blank ! ... ?

                              PS: ah,found it - cllcking Code does it ... sorry !

                              So, almost there ... have downloaded the Shortcuts app onto my iPhone, and have created a URL Shortcut, which is now showing in the Library ...

                              but it doesn't work - because I don't know how to include Authorisation in the URL ... have tried a few ideas, but no joy ! ??
                              Last edited by chris_j_hunter; 6 December 2020, 07:05 PM.
                              Our self-build - going further with HA...

                              Comment

                              Working...
                              X