Page 4 of 5 FirstFirst 12345 LastLast
Results 31 to 40 of 47

Thread: Voice Control the £20 way

  1. #31
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    112

    Default

    Quote Originally Posted by chris_j_hunter View Post
    shortcuts - now we know how to do them, and can think of many many we might implement, maybe the trick is just to keep an eye, and implement just the few that will help most often ...

    Yes - I think the key to effective usage really is to keep the number of shortcuts to a minimum for the things you need to be most accessible if you're physically pushing the button. If you end up with hundreds of shortcuts sprawled in a UI, you'll likely spend more time searching for the button than is tolerable. Of course, if you're going to use your voice, then you can simply keep all the shortcuts hidden away in the shortcuts app and talk to Siri.


    Quote Originally Posted by chris_j_hunter View Post
    those created on my 'phone, have been transferred also onto my wife's 'phone, without me asking ... not complaining, but how does that happen ?
    Unless both phones are signed in using the same iCloud account, or you've got some kind of Family Sharing setting in play, I'm not sure either: usually you'd need to manually share them. Are they both on separate iCloud accounts?


    Quote Originally Posted by chris_j_hunter View Post
    Cortex update - have now updated, and no change ... ie: GET & POST work via Postman, only GET works via Applescript ... logic implies problem lies in Applescript ...
    Yes, my view is that your issue isn't with Cortex - this inbound route works and is proven by your iOS Shortcuts working, so the issue has to be in the forming of the request in your Applescript. Whack some tracing between the Applescript and Cortex to check where it's going wrong.

  2. #32
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,711

    Default

    the requests in Postman, look like this:

    curl --location --request GET 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213' --header 'Authorization: Basic nnnnnnnnnnnnnnn'

    curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213?6=1' --header 'Authorization: Basic nnnnnnnnnnnnnnn'

    and both work ...

    and in Applescript, they look like this :

    do shell script "curl --location --request GET 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

    do shell script "curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213?6=1' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

    and only the GET works ...

    enclosing a string in single quotes - 'abcdef&/whatever' - is a way of ensuring it's passed-on verbatum, without triggering any response from the application that's handling it / sending it on ...

    but there seems to be a bug in Applescript ...

    Googling a lot, brings up comments pointing to it mishandling things within single quotes within double quotes - as in "abcd 'nhygf' ajyhe" ...

    and comments that say we should use quoted form of in strings containing spaces & other special characters (like & and ?) ...

    eg: quoted form of (gjsfhjfsafjsdfagh?&jsj) ...

    there's also mention of escaping - as in using the \ character to avoid misinterpretation of strings ... as in \" and \\ ...

    some of these comments go back almost twenty years ...

    I found no examples to illustrate any of their use in our situation, but have experimented with what I could imagine ... without success ... my understanding of all this is very limited, though ...

    bottom - line ... Applescript's problem seems to be with the ? character in the POST request, even though it's contained within a string that is enclosed within single quotes ...

    so ...question is - is there an alternative to it, within the ultimate destination - within the Cortex API ... ???


    PS: did have a look at using Wireshark & Fiddler - but we're running OSX 10.11.6, with which they say they are not compatible ...

    references :

    https://curl.se/docs/

    https://macscripter.net/viewtopic.php?id=22970

    https://stackoverflow.com/questions/...in-applescript
    Last edited by chris_j_hunter; 12th December 2020 at 01:43 PM.

  3. #33
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    112

    Default

    I've never used curl before and from 5 minutes of trying powershell and googling, I'm damned if I can get it to work with any header values ... however, if the "?" is your issue, can you encode this value? for example, instead of using 2213?6=1 .. maybe try 2213%F7%3D1 (%F7 being ?, and %3D being =) so that your full curl would be;

    curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213%F7%3D1' --header 'Authorization: Basic nnnnnnnnnnnnnnn'

    ?

    Cliff

  4. #34
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,711

    Default

    thanks again ...

    yes, the cURL write-ups & discussions are not that clear - at least to me, who knows so little ...

    so ... tried them (%F7 and then %3F for ?, and %3D for =) and stiil have the problem - ie: the POST request via Applescript runs & runs without effect or response ...

    to explore further, I added the ?6=1 string to the GET request - and got the response from Cortex that the POST command should be used ...

    true, of course ... but also confirming that Cortex understood the ?6=1 addition ... ditto when I added %3F5%3D1 instead ...

    I also copied the request into Terminal, and sent it from there - worked fine, the light switched off - after I closed Terminal, not before ...

    not sure why I had to close Terminal first - but, anyway, seems to reaffirm the problem is with Applescript (rather than Shell) ...

    so - the POST works from Postman, works from Terminal, but not from Applescript ...

    while the GET request works from all three ...

    the POST instruction was created by editing a copy of the GET instruction - to insure against typo's - ie: POST in place of GET, and ?6=1 added after 2213 ...

    mysteries ! ... and grrrh !
    Last edited by chris_j_hunter; 15th December 2020 at 11:12 PM.

  5. #35
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    112

    Default

    Hmm .. this sort of thing bugs me .. over Xmas where I've got some more time, I'll have a little play with a few things, but not having a Mac I can't really help on the Applescript front.


    On a segway'd subject ... have you ever used the Virtual API object variables in Cortex? This is something I'm struggling to understand too at the minute. I've got 2 things I'm trying to achieve.

    1 - I can successfully fire a POST request into Cortex and get one of the variables to have a Current Value (either True, false, or a value 0-100) but, other than that, I'm struggling to actually use that value anywhere. Do you know how to then reference the variable "Current value" in any logic anywhere (whether that's part of a Macro, or I can trigger an object state based on the variable value)? For example, the Home Assistant mobile app seems pretty reliable at reporting its GPS location in quick time, so I can setup an additional presence indicator to know when "I" (personally) am home, vs anyone else being at home. If Cortex know it's "me", then it can personalise certain things how "I" like them vs how the wife likes them. (I'm considering whether I can also use this in future use-cases for things like automatically disarming alarms, potentially even unlocking certain entry points etc kinda like Keyless entry on a car).

    So I've got it setup that the HA iOS app tells my HA Install that I'm home (I've tested it's reaction times, and it seems reliable so far after a couple of weeks of testing it), and then I can (need to figure out the exact way, but know it's do-able) get that to fire an API request into Cortex to pass on the message.

    I just don't know how to then use this ..


    2 - Kinda similar, but opposite ... I want Cortex to fire a Get Request, parse the response .. and use the value returned in some logical way. For example, to help bake in reliability if I'm using some Wifi Zigbee devices controlled via rest API into HA ... I want to (maybe just at the end of the day) poll their current state using a GET request into HA .. which returns "state=on" ... then have Cortex take that "on" value and align the associated Cortex light object to that state. This'd cover off anyone manually fiddling with the switch locally and so Cortex getting out of sync. (I'll likely have other use-cases, but this is simple one to follow)

    In this one, I appear to be able to follow the Cortex help file and get the "on" value returned to show up in a Noticeboard, but I just don't see how to use it in any logic .. how do I output it "somewhere" and then use it in a comparison with (for example) a current cortex light state?

  6. #36
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,711

    Default

    Cliff -

    interesting - hadn't noticed the Virtual API logic object class (?) before ...

    so, having created one in our DataBase, and (via its Behaviours window) an ON/Off (Boolean) variable within it, I did a GET....Objects on Cortex, to get a complete listing of objects, and it was not among them ...

    tried again, same result - then realised I'd not Web Enabled it !

    then, in Structure list, I double-clicked on the Virtual API, got the drop-down menu, and clicked on Connections (*) ...

    the Connections window then appeared, there were several to choose from ...

    so connected a free DRB button to Toggle input & a Light to the output, and tried it out - worked fine !

    Chris

    (*) I'm working through TeamViewer, and had to go that way - IIRC, on the Cortex PC itself, right clicking the Virtual API icon in PlanView with the mouse would have done the same ...
    Last edited by chris_j_hunter; 16th December 2020 at 06:16 PM.

  7. #37
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,711

    Default

    1- knowing it's you ... strange to say, that's exactly what we're trying to do with our RFID tags through Applescript !

    eg: when someone gets home, they wave their key-fob over the Mir:ror, and Cortex knows who's home ...

    eg: place a Nano:ztag (RFID enabled object) on the Mir:ror, and the kitchen operates one way, place another & it operates another way ...

    a Mir:ror signals to Cortex when an object is placed on it, and again when it's removed ...

    lots of possibilities, because we have nine Nano:ztags, and seventy-two Ztamp:s (small RFID sticker tiles that can be attached to key-fobs, books, mugs, anything) ... and four Mir:rors (though haven't yet tried connecting more than one to our AppleMac') ... plus a Nabaztag:tag, which can be waved at and can also speak ...

    another idea is to use some as a key - wave RFIDs in a particular sequence to unlock something ...

    Chris
    Last edited by chris_j_hunter; 16th December 2020 at 07:51 PM.

  8. #38
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    112

    Default

    Quote Originally Posted by chris_j_hunter View Post
    Cliff -

    interesting - hadn't noticed the Virtual API logic object class (?) before ...

    so, having created one in our DataBase, and (via its Behaviours window) an ON/Off (Boolean) variable within it, I did a GET....Objects on Cortex, to get a complete listing of objects, and it was not among them ...

    tried again, same result - then realised I'd not Web Enabled it !

    then, in Structure list, I double-clicked on the Virtual API, got the drop-down menu, and clicked on Connections (*) ...

    the Connections window then appeared, there were several to choose from ...

    so connected a free DRB button to Toggle input & a Light to the output, and tried it out - worked fine !

    Chris

    (*) I'm working through TeamViewer, and had to go that way - IIRC, on the Cortex PC itself, right clicking the Virtual API icon in PlanView with the mouse would have done the same ...

    OK - so you've got a Virtual API object to now have an On/Off Boolean state based on an input (in our case the DRB button) ... but my question is then, how do you (we) use that Boolean state to drive logic? How are you referencing this to do logic, for example a simple example such as;

    If BooleanState = On
    Then set kitchen lights to 50% bright
    Else set kitchen light to 90%
    End if

    ?

    This is the bit I'm struggling with (I must be missing something obvious I'm sure!)

  9. #39
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,711

    Default

    short answer is via the Virtual API's Connections window ... the last entry of which is the output I connected to a Light ...

    have checked, and the list of possible connections includes Lights & Pumps & General Logic Gates & ... all the usual things ...


    PS: have set up your example here, too, and it works ...

    DRB button => Virtual API / Variable 0 (input Toggle)

    Virtual API / Variable 0 (output) => Gate 1 (Source A) of General Logic object (NOT) => SLD dimmer Scene 1 (To True)
    Virtual API / Variable 0 (output) => Gate 2 (Source A) of General Logic object (OR)...=> SLD dimmer Scene 4 (To True)


    PPS: if you've not used General Logic before - it's up the list from the Virtual API, and you create gates within one by clicking Add, after which it gives you a choice of various digital & analogue types ...
    Last edited by chris_j_hunter; 17th December 2020 at 02:30 PM.

  10. #40
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    112

    Default

    Quote Originally Posted by chris_j_hunter View Post
    short answer is via the Virtual API's Connections window ... the last entry of which is the output I connected to a Light ...

    have checked, and the list of possible connections includes Lights & Pumps & General Logic Gates & ... all the usual things ...


    PS: have set up your example here, too, and it works ...

    DRB button => Virtual API / Variable 0 (input Toggle)

    Virtual API / Variable 0 (output) => Gate 1 (Source A) of General Logic object (NOT) => SLD dimmer Scene 1 (To True)
    Virtual API / Variable 0 (output) => Gate 2 (Source A) of General Logic object (OR)...=> SLD dimmer Scene 4 (To True)


    PPS: if you've not used General Logic before - it's up the list from the Virtual API, and you create gates within one by clicking Add, after which it gives you a choice of various digital & analogue types ...

    Sorry if I'm being a little dense here (I will have a think about this tonight when my brain is less work focussed) .. but in this example, this is basically creating the functionality of;

    IF - "A Value" is 1, then set a scene to 1
    End If.

    No?

    "A Value" in this case, is a GL Object output.

    .. but to get to "A value", we're going through a series of batten passed of data by firing an API to pass the value (True) into a Virtual API object, and then passing this through the GL object to evaluate "= 1" ...

    So the steps are ..

    1) Fire an API to set a value into the Virtual API object
    2) Pass Virtual API Object value into GL
    3) GL evaluate the logical output (1)
    4) Set a specific scene

    Isn't this just a more complex way of either in Step 1, firing the API that sets the SLD Scene direct, or (if you perhaps had multiple outputs so want to facilitate 1 input to several outputs) having the Virtual API object "out" connection set the SLD Scene to 1 direct?

    Likewise, in my scenario of this virtual API object being True/False based on whether the HA app says I'm physically home or not, the above wouldn't then revert when one of us leaves the house right? (ie the Virtual API Object goes to False).

    Maybe I just need to think about it a bit more ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •