Author Topic: Am I doing this right? Scrape and Results.SetVar  (Read 7003 times)

0 Members and 1 Guest are viewing this topic.

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Am I doing this right? Scrape and Results.SetVar
« on: January 08, 2014, 11:07:29 AM »
I have a NetAtmo which allows me to retrieve temperature information for both inside and outside my house.
I have a plugin for my Vera that stores the data locally so I don't have to deal with the NetAtmo cloud service
I'm creating a simple action, when I ask "temperature", I want VC to tell me the temperature inside and outside along with the humidity

So, I started by adding a Scrape action that goes to my Vera to get the OutsideTemperature
I then call Results.SetVar and set OutsideTemp to {LastResult} [I gather if I omit {LastResult} it'll default to that]
I then piece together my TTS.Speak by placing {Var.OutsideTemp}, etc for each variable I've set
Is this the correct way to go?  Or is there a simpler way?


Here's the actual code [this works as expected]:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="393" name="Get Temperature" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://192.168.1.106:3480/data_request?id=variableget&amp;DeviceNum=253&amp;serviceId=urn:upnp-org:serviceId:TemperatureSensor1&amp;Variable=CurrentTemperature</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <cmdString>OutsideTemp&amp;&amp;{LastResult}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <cmdString>It is currently {Var.OutsideTemp} degrees outside.</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>It is currently {Var.OutsideTemp} degrees outside.</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>temperature</phrase>
</command>
« Last Edit: January 08, 2014, 01:07:58 PM by macrho »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #1 on: January 08, 2014, 11:18:06 AM »
Did you have installed the Vera plugin in VC?
If yes, there are some actions for the Vera controller in the command editor available. As example "Vera.Get.Temperature" "Device ID" - I think this is the easiest way  ;)

Here is a list with the actions: http://voxcommando.com/mediawiki/index.php?title=Plugin_Vera
***********  get excited and make things  **********

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #2 on: January 08, 2014, 11:27:48 AM »
I do and I did not know those were exposed, cool, I'm using that to access those properties
Looks like only Temp and Humidity are exposed, the NetAtmo plugin exposes decibel along with pressure and CO2 - I can still access those through the method I was using before
Thanks! Is the method in which I'm building up correct? I now have [still a work in progress]
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="393" name="Get Temperature" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">

  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://192.168.1.106:3480/data_request?id=variableget&amp;DeviceNum=254&amp;serviceId=urn:micasaverde-com:serviceId:HumiditySensor1&amp;Variable=CurrentLevel</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <cmdString>OutsideHumidity1</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Vera.Get.Temperature</cmdType>
    <cmdString>253</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <cmdString>OutsideTemperature</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>It is currently {Var.OutsideTemp} degrees outside with {Var.OutsideHumidity} percent humidity.</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <cmdString>It is currently {Var.OutsideTemp} degrees outside with {Var.OutsideHumidity} percent humidity.</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType />
    <cmdString />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>temperature</phrase>
</command>
« Last Edit: January 08, 2014, 01:08:19 PM by macrho »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #3 on: January 08, 2014, 11:31:40 AM »
Does this command work?
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #4 on: January 08, 2014, 11:41:20 AM »
Please enclose xml in a code block on the forum.

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #5 on: January 08, 2014, 11:41:54 AM »
Does this command work?

Yes, it works. Just wondering if I'm doing this the "correct" way or if there is a simpler/more efficient way.
Stumbling my way through but this is cool.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #6 on: January 08, 2014, 12:48:36 PM »
I do and I did not know those were exposed, cool, I'm using that to access those properties
Looks like only Temp and Humidity are exposed, the NetAtmo plugin exposes decibel along with pressure and CO2 - I can still access those through the method I was using before
Thanks! Is the method in which I'm building up correct? I now have [still a work in progress]

In the Vera plugin there's an action called Vera.Raw that you could use instead of scrape for any Luup requests that aren't already supported via the plugin actions. http://voxcommando.com/mediawiki/index.php?title=Plugin_Vera#Raw

It does the same thing as scrape, as far as I know, so it's not that much of an advantage. Slightly shorter syntax. Maybe James can comment if there's an advantage apart from that.

You might want to investigate how to use Maps in VC so that you don't have to manually look up your device and scene IDs all the time. If you have a lot of devices, it will be more efficient, but otherwise perhaps not a big deal.

Your command looks fine if you're always going to want to ask for the outside temperature. Since you want to access more than one value at a time it makes sense to use Results.SetVar. If you wanted to make the command more flexible (e.g. "What's the temperature outside/in the living room/downstairs" etc.), then you'd want to take a different approach I should think. ... And if you planned to have separate commands for each, then your command phrase "temperature" may cause some confusion. :)

For more on maps: http://voxcommando.com/mediawiki/index.php?title=Maps

Note that apart from the maps that the Vera plugin creates for your scenes and devices, you can also create and edit a map directly within a command and use it store variables more permanently than is possible using "regular" user variables. Not particularly relevant for the command you've shared above, but it's a good thing to keep in mind because it can be a useful distinction depending on what you want to do.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #7 on: January 08, 2014, 12:52:51 PM »
@ macrho

Please edit your posts above and place your xml in code blocks using the '#' button.  Please always do this when posting code to the forum.  This should also be done when posting logs, but I prefer if users upload their entire log file as an attachment.

Code: [Select]
I am
In
- a -
CODE BLOCK!!!
:)

For more information see the wiki post: http://voxcommando.com/mediawiki/index.php?title=XML_on_the_forum#Posting_Your_Code_to_the_Forum
« Last Edit: January 08, 2014, 01:01:06 PM by jitterjames »

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #8 on: January 08, 2014, 01:09:05 PM »
Ok, hangs head low and edits previous posts to have a code block   :(

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #9 on: January 08, 2014, 01:16:14 PM »
I'll look into the maps, thanks for the suggestion

I'm also trying to do some conditional type checks, such as:

What's the status of the front door?

Response 1: It's locked, would you like me to unlock it?

 A: No
 R: Very well

 Answer: Yes
 Response: The front door is unlocked

Response 2: It's unlocked, would you like me to unlock it?

 Answer: No
 Response: Very well

 Answer: Yes
 Response: The front door is now locked.



A general question: Do most folks tend to build their commands in the command builder or simply write the XML and then paste it in?

And a suggestion, perhaps: In the Logical Command Builder, when you type in a command the autocomplete does a match based upon the first character you enter. It would be nice it if filtered based upon finding the character(s) anywhere in the name

Case in point: I know I want to use TTS.Speak but I forgot it is prefixed by TTS, if I type in speak, I'd like to see the list of items that contain speak anywhere in their text


nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #10 on: January 08, 2014, 01:38:19 PM »
A general question: Do most folks tend to build their commands in the command builder or simply write the XML and then paste it in?

... Where's the emoticon for "shudder"?

I can tell you from experience that users who try to write their own xml (usually because they don't know about the LCB or they don't get how to use it) end up wondering why their code isn't working all the time on the forum.   :biglaugh

In the Logical Command Builder, when you type in a command the autocomplete does a match based upon the first character you enter. It would be nice it if filtered based upon finding the character(s) anywhere in the name

Two options apart from auto-complete:
1. Click on the "magic wand" beside the action field to open up the action selection tree so that you can see all available actions. (Sidenote: "command" is the whole macro; the individual methods within a command are called "actions", which can be useful to know when you're looking at documentation.)
2. Bookmark the Actions page of the wiki: http://voxcommando.com/mediawiki/index.php?title=Actions, where you could certainly search by "speak" to find the action you're looking for. There's also a button "View Help on Wiki" in the action selection tree window, which takes you directly to the Actions page.

 ... if you're looking for plugin-specific actions, be sure to look in the plugin actions tab not the core actions tab of the action selection tree (same with the wiki--plugin actions are listed separately).

Part of it is just getting familiar and comfortable using the program -- having time to poke around and also exploring the documentation, since it is a pretty unique piece of software and has so much functionality that isn't always self-evident. It takes me very little time to use the LCB now, but when I was learning the ropes there was definitely a curve.
« Last Edit: January 08, 2014, 01:47:04 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #11 on: January 08, 2014, 02:20:23 PM »
Response 1: It's locked, would you like me to unlock it?

 A: No
 R: Very well

 Answer: Yes
 Response: The front door is locked

Response 2: It's unlocked, would you like me to lock it?

 Answer: No
 Response: Very well

 Answer: Yes
 Response: The front door is now locked.

This will be fun, but it will be tricky to do it exactly as described. The easiest approach is probably more along the lines of:

Command 1: What's the status of the front door?

        VC conditional response 1: The front door is locked

        VC conditional response 2: It's unlocked, would you like me to lock it?

Command 2: (optional phrases "Yes"/"yes please") > lock the front door > (optional phrase "please")

       VC response: The front door is now locked.

Command 3: "No" > "don't bother|thanks|nevermind"

      VC response: Very well|As you wish|Whatever you like|OK, no problem.
        

---
Note:

Command 3 in this case doesn't do anything "practical", it's just conversational fluff; but now you have a more flexible conversational fluff command that can work for multiple scenarios, not just this situation. However, you don't want the command phrase to be just "No" because then you'll be setting off the command constantly. As a general rule, it's best to avoid one-word commands in VC.

Command 2 in this case can now be used not just in the scenario you mention, but any time you want to lock your front door. Because you've added the optional yes/yes please in front of the phrasing, it will work for the script you describe as long as you also say "lock the front door," but it means that you don't have to use VC.TellVox with an "always confirm" door-locking command to make your script work (maybe you prefer to always have that command require confirmation, though?).

Again, it's best to avoid one word commands like "Yes", although it's true that you could use "yes" as your command confirmation phrase. Personally, I keep even my confirmation phrases a bit more unique to avoid headaches. The confirmation phrases that I have set in my Options are: "Yes please" "Affirmative" and "Go ahead".
« Last Edit: January 08, 2014, 02:37:49 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #12 on: January 08, 2014, 03:15:34 PM »

A general question: Do most folks tend to build their commands in the command builder or simply write the XML and then paste it in?

I can't think of any reason to create XML by hand.  The only reason to edit it by hand would be to ( very carefully ) use find/replace.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #13 on: January 09, 2014, 10:14:08 AM »
Why not use Vera.Get.Humidity action?

Your command as posted will not really work because the variable names you use are inconsistent.

If it does come down to a Vera command that is not provided by the plugin, you should probably use the Vera.Raw action rather than scrape, simply because you might later need to change the IP address of your Vera and then you can simply change the IP in the plugin settings and all will continue to work.  If you used scrape then you would need to edit every scrape command to use the new IP.  Also it makes reading and editing the macro easier.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Am I doing this right? Scrape and Results.SetVar
« Reply #14 on: January 09, 2014, 10:45:13 AM »
Your command as posted will not really work because the variable names you use are inconsistent.

Ha. You and your eagle eye. Good catch.

Thanks for chiming in about the benefits of Vera.Raw over Scrape, jitterjames. Makes sense!

My impression was that macrho initially sought feedback before he had reviewed the complete list of Vera actions. Kalle posted a link to those above, so hopefully now macrho's aware of all the options, including Vera.Get.Humidity. (Right? ;))
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)