Page 5 of 5 FirstFirst 12345
Results 41 to 47 of 47

Thread: Voice Control the £20 way

  1. #41
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,713

    Default

    have now tried it here direct - Virtual API / Variable 0 toggled by a DRB button & connected direct to the Light ...

    doesn't work ... do need to go through the GL object ... with the output set to To True ... which maybe is a clue as to why ... though it may also be that Scenes don't toggle (as it were) ... and that Scenes set levels, not on or off ...

    having the GL object might be advantageous, too, because can incorporate other interlocks, for more context-sensitivity ...

    ===

    btw ... just half an hour ago, I solved (thanks to an after-thought suggestion from my nephew) the POST problem ... the trick is to include - only for the Applescript / Shell situation (not Postman or Terminal, etc) a null data element ... ie: the problem was that the cURL was waiting on data that never arrived ...

    ie: include -d'' (the '' being two single quotes) as follows :

    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' -d'' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

    simple, when you know !!
    Last edited by chris_j_hunter; 17th December 2020 at 06:47 PM.

  2. #42
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    117

    Default

    Quote Originally Posted by chris_j_hunter View Post
    have now tried it here direct - Virtual API / Variable 0 toggled by a DRB button & connected direct to the Light ...

    doesn't work ... do need to go through the GL object ... with the output set to To True ... which maybe is a clue as to why ... though it may also be that Scenes don't toggle (as it were) ... and that Scenes set levels, not on or off ...

    having the GL object might be advantageous, too, because can incorporate other interlocks, for more context-sensitivity ...

    OK .. I think I just needed play with it more actually

    You can more simply just toggle a scene based on an API direct though right? .. rather that via a Virtual API object?

    To be more specific than a random example ... one use-case I'm looking to control here is that in my office, I have 2 desks - 1 for each of myself and my wife. Each desk has external monitors that consume enough power that I don't leave them powered on full time, plus some aesthetic LED lighting on each desk. So, what I want is to vary the room activity based on "who" is at home during working-day hours.

    If someone enters the office - I want each 'desk' to only power on only based on whether each individual is at home and clearly still obey the lights being controlled by room occupancy.

    So with this, I suppose 1 GL Object Output could set each light / 'PC monitor' object to be active when that person is "home", and another GL Inactive when they leave the house, however, why wouldn't I just set the light / 'PC Monitor' active and inactive via the API that would otherwise have set the API Variable, direct, cutting out the middle man (the GL object)?


    That said, I have just looked at what you said and (contrary to what I "think" you describe, maybe I'm mis-interpreting what you mean), I do appear to be able to control a light object using the Virtual API Variable state directly ... I've connected a test light object so that the "Turn On" connection = "Virtual API Object On True" and the the "Turn Off" connection = "Virtual API Object On False" ... with this, changing the state of the Virtual API object turns the light on/off depending the API value being True/False ..

    Likewise I setup an 'Analogue (Real)' Virtual API variable, and I've connected the "Brightness (Dimmer Control)" connection of a Dimmer object to be "Virtual API Variable-Out Value" and with this, whatever value 0-100 I set the Virtual API variable to be, sets the brightness of the dimmer.


    So .. I think this gives me scope to do what I need ... will certainly have more time to tinker over Xmas once tomorrow is out of the way


    Quote Originally Posted by chris_j_hunter View Post

    ===

    btw ... just half an hour ago, I solved (thanks to an after-thought suggestion from my nephew) the POST problem ... the trick is to include - only for the Applescript / Shell situation (not Postman or Terminal, etc) a null data element ... ie: the problem was that the cURL was waiting on data that never arrived ...

    ie: include -d'' (the '' being two single quotes) as follows :

    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' -d'' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"
    Ahh! Brilliant! Well done! ... these things are usually something simple enough, but without someone explicitly stating this is a mandatory "option" in a curl, ya wouldn't have known to find it without experimentation like this ..

    Not that I've spent ages on it, but for the life of me I can't get curl working in PowerShell in Windows .. even for a basic GET I just get this in Powershell;


    PS C:\Users\me> curl -X GET http://192.111.1.111:1111/api/v1/Objects/522 -H 'Authorization: Basic Y2xpZmZhcGk6Q2wxZmABbbse'

    Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Authorization: Basic
    Y2xpZmZhcGk6Q2wxZmABbbse" value of type "System.String" to type "System.Collections.IDictionary".
    At line:1 char:61
    + ... api/v1/Objects/522 -H 'Authorization: Basic Y2xpZmZhcGk6Q2wxZmABbbse'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (: ) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShel l.Commands.InvokeWebRequestCommand

  3. #43
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,713

    Default

    no expert, but ...

    my guess would be, after the GET ... you need enclose the http ... 522 in single quotes ...

    also ... do please change your user-name & password, after posting what you posted !

    Chris

  4. #44
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    117

    Default

    Quote Originally Posted by chris_j_hunter View Post
    no expert, but ...

    my guess would be, after the GET ... you need enclose the http ... 522 in single quotes ...

    I've tried all sorts of combinations of quotes etc .. nothing;

    PS C:\Users\me> curl -X GET 'http://111.111.1.111:1111/api/v1/Objects/522' -H 'Authorization: Basic Y2xpZmZhcGk6Q2wxZmABbbse'
    Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Authorization: Basic
    Y2xpZmZhcGk6Q2wxZmABbbse" value of type "System.String" to type "System.Collections.IDictionary".
    At line:1 char:63
    + ... pi/v1/Objects/522' -H 'Authorization: Basic Y2xpZmZhcGk6Q2wxZmABbbse'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (: ) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShel l.Commands.InvokeWebRequestCommand


    Quote Originally Posted by chris_j_hunter View Post

    also ... do please change your user-name & password, after posting what you posted !

    Chris
    That's not my actual username, nor IP, nor Bearer Token ... all very obfuscated

    ~~~~~~~~~

    Edit - I've just stumbled across a glint of genius by searching through a code base at work of all things ... if I try this;

    curl 'http://111.111.1.111:1111/api/v1/Objects/522' -H @{Authorization = "Basic Y2xpZmZhcGk6Q2wxZmABbbse"}

    It works ... so the answer was that I was enclosing the whole header K/V pair in the quotes, but only needed to enclose the Value part ..


    StatusCode : 200
    StatusDescription : OK
    Content : {123, 13, 10, 32...}
    RawContent : HTTP/1.1 200 OK
    Connection: close
    Content-Length: 3554
    Content-Type: Content-Type: application/JSON

    {
    "CortexAPI":{
    "CortexObject":{
    "ControlObjectType":"TestLight",
    "F...
    Headers : {[Connection, close], [Content-Length, 3554], [Content-Type, Content-Type: application/JSON]}
    RawContentLength : 3554


    Hoorah!
    Last edited by cliffwright; 18th December 2020 at 10:22 AM. Reason: Answered my own question :)

  5. #45
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,713

    Default

    >> You can more simply just toggle a scene based on an API direct though right? .. rather that via a Virtual API object?

    >> looked at what you said and (contrary to what I "think" you describe, maybe I'm mis-interpreting what you mean), I do appear to be able to control a light object using the Virtual API Variable state directly ...

    yes, you're right ... I tried it again, and this time it worked (*) ... though after turning the light on & off, I found I had to wait a few seconds before it could be turned on again ... which maybe is what confused me, last time ...

    (*) both from a button press to toggle, and from an Applescript (!) ...


    >> one use-case I'm looking to control here is that in my office ...

    yes, why not do it without the GL ... assuming the desks are in a room separate from others, so presence is simply reliable ...


    >> I setup an 'Analogue (Real)' Virtual API variable, and I've connected the "Brightness (Dimmer Control)" connection of a Dimmer object ...

    ah, great - saves me the trouble of trying it out !


    >>That's not my actual username, nor IP, nor Bearer Token ... all very obfuscated

    ah good, sorry, but had to play safe !


    good luck with the GPS link into HA ...wonder if that could also be done from iPhone ?


    potentially very powerful, all this ... and so simple to do - now we've got to the bottom of it all ... interesting times !
    Last edited by chris_j_hunter; 18th December 2020 at 02:28 PM.

  6. #46
    Automated Home Guru cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    117

    Default

    Quote Originally Posted by chris_j_hunter View Post
    >>That's not my actual username, nor IP, nor Bearer Token ... all very obfuscated

    ah good, sorry, but had to play safe !
    No worries - It never fails to amaze me how many people don't think about security stuff like this ... so good to point it out in case


    Quote Originally Posted by chris_j_hunter View Post

    good luck with the GPS link into HA ...wonder if that could also be done from iPhone ?


    potentially very powerful, all this ... and so simple to do - now we've got to the bottom of it all ... interesting times !

    You can indeed do it direct from your iPhone .. and it seems to work well too (have been experimenting the last few days, but because of Covid I hardly ever go out to be able to test it ) ... You set it up as an "Automation" rather than a "Shortcut" which basically just allows you to attach an Event trigger to what you created as a "Shortcut" ... so it's as simple as 2 steps When "I arrive at <location>" Do "Get Contents or URL" (same setup as in the shortcuts we've talked about) or a When "I leave <location>" event.

    It seems pretty reliable actually (have maybe seen it work 5 times at most though) so if it carries on, I'll use this instead of HA ... the only thing I've not yet figured (which is actually nice whilst testing it), is when the automation triggers, it gives you a notification on your phone ... nice whilst testing, but I don't want this long term as it'd be annoying. I'm sure you can turn it off though.

    Something else I was thinking about actually too off the back of you talking about your "Mir:ror" stuff ... (which is a bit 'after the horse has bolted' given we've just fathomed the curl point out, but ..) you 'could', assuming you and your wife / any other house user have iOS Devices that have NFC chips - which I think started in the iPhone 6 - is use NFC tags / stickers instead combined with an iOS Shortcut and the Cortex API's. This would eliminate your need for a macbook connected up or any applescript.

    It's really easy to setup an "Automation" in iOS Shortcuts that is invoked when you tap your phone next to a specific NFC tag ... and these are cheap (there's loads on Amazon / eBay, but no more than £1 each).

    With this, you can stick an NFC sticker to a "thing" (including behind it, if it's thin and not metallic) and when you place your device near it, it can fire a Cortex API and therefore set something up, personalise it etc. Plus, the tags have a small amount of memory too to store info on that can be passed to the device that taps it (whoever that is) .. I've got some NFC tags waiting on my desk to play, but I'm planning on having one on my wireless charger next to my bedside, so that (given I'm always the last one in bed), by virtue of me always putting my phone on charge overnight, I can automatically tell Cortex to turn things off, check / warn me if Door lock states aren't secure etc

    Lots of scope

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

    Default

    magic ...

    some Googling suggests our iPhone 6+ can do NFC, but so far I've failed to find it in Settings, to turn it on ...

    more Googling suggests, though, that it can't read NFC tags, which seem to have come later ...

    ISTR Googling told me Shortcuts worked only on iPhone 7 & later, and yet we have it working seemingly perfectly, so will not be leaving it at that !

    in our Shortcuts, though, Automation doesn't appear - MyShortCuts is called Library on ours, and to the right of it there's only Gallery ...

    more Googling, though, suggests there's Automation in the Home app ... which have yet to open & explore ... so all may not be lost !

    Chris

Posting Permissions

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