Author Topic: Regex Results  (Read 10771 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #15 on: April 29, 2015, 08:34:42 AM »
Generally, a regex pattern is as short as possible. It will return multiple matches of the same pattern; you don't need to repeat the pattern over and over again in your regular expression.

James gave you the proper pattern earlier in this thread for the regular expression that will capture the following info about each node:

1. node id
2. property id
3. property value
4. property formatted
5. uom (unit of measurement)

It is here: http://voxcommando.com/forum/index.php?topic=2135.msg18535#msg18535

If the first node matched {Match.1} is, for example:
Code: [Select]
node id="11 B3 8F 1"><property id="ST" value="156" formatted="78.00" uom="degrees"
Then {Match.1.1} is 11 B3 8F 1, {Match.1.2} is ST, {Match.1.3} is 156, {Match.1.4} is 78.00, {Match.1.5} is degrees.

The next node will be {Match.2}, and its component parts will be {Match.2.1}, {Match.2.2} etc.

The question is, what does grabbing all of this info at once do for you? What is it that you are trying to accomplish? Do you need all of those values?
« Last Edit: April 29, 2015, 08:40:23 AM 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: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #16 on: April 29, 2015, 04:53:25 PM »
Quote from: ddl
What I am trying to accomplish is:
1. Have VC tell me the total number of devices on my network
2. the total number of active/inactive devices on the network (this is identified by the "formatted" status) and
3. the status of a particular node if requested

After reading through your comment, I'm guessing there is a better way to write this command to achieve the results that I am looking for. I'm just not sure of it yet.

It sounds as though you want a group of commands, rather than a single command. The issue is not just mastering regular expressions, but thinking in terms of how VC works, and what types of ISY queries you can use that make it easier to isolate the values you're interested in, in each case.

There are different ways to parse your objectives, but I would probably break it down into as many as 5 commands -- something like:

Command 1: Scan my devices / (How many devices do I have)

Solution:
Scrape http://YOUR_ISY_URL/rest/status
Simple Results.regex --> node id="(.*?)" [just looking for node ids]
OSD.ShowText Total devices: {#M}
Store this value as a variable to be used in command 2, using Results.SetVar.


Command 2: Triggered automatically by command 1, using an event trigger. (Technically all this could be done in command 1 instead -- this is just my preference.)

Solution:
Scrape http://YOUR_ISY_URL/rest/status
Simple Results.regex --> formatted="\s" [looking ONLY for cases when formatted is blank (which I'm assuming means a device is inactive/disabled?)]

Then I can calculate active devices by subtracting inactive devices from my total. This requires that the Python plugin be enabled. We use it to do the math. Simply, PY.ExecString --> result = {var.devices} - {#M}

Now I can report the number of active ({LastResult}) and inactive ({#M}) devices.

Command 3: Get status info only for my lights.

To make this convenient, I would create a payload XML file associating the node IDs for each light switch device with that device's friendly name.

This way you can ask more naturally, "Is the hall light/living room light/bedroom light on?"

You take advantage of the fact that you can query the status for a specific node ID. You pass in the payload value for that specific device node id.

Solution:
Scrape http://YOUR_ISY_URL/rest/nodes/{1}/ST
Simple Results.regex --> formatted="(.*?)"

Now you can customize the feedback you receive based on whether the regex returns a value of on, off, or a number indicating the dim level of a dimmable light. You can use a logic block for this.
If {Match.1} is either on or off, VC tells you that. [If AcontainsB > On Off > {Match.1}, then "{PF.1} is {Match.1}"]
Otherwise, it tells you the dim level. (Slightly different wording to make this natural-sounding.)

Command 4: Give the thermostat its own special command, because it has various properties apart from its current status (What mode is the thermostat in? What's the humidity reading, etc.).

In this case I'd create a payload XML file that associates each of the 4 property IDs with a convenient phrase for that property ID. Along the lines of:
ST -> temperature
CLIMD -> mode
CLIHUM -> humidity reading
CLISPH -> heat set point

Now you can take advantage of your ability to query specific property types for specific nodes. You can hard code the node ID for the thermostat, and use a payload{1} to pass in the property that you're interested in:

Solution:
Scrape http://YOUR_ISY_URL/rest/nodes/11 B3 8F 1/{1}
Simple Results.regex --> formatted="(.*?)"
You can again customize the response with a logic block, or keep it simple and just report {Match.1} for whatever you asked for.

Command 5: Give your door lock its own command as well. (Basically, I prefer to monitor different types of devices using distinct commands, in part so that I can customize the feedback.

So, same scrape and regex as above but using the lock's node ID, and then you can customize the wording of both the voice command and the feedback so that it makes sense for a door lock.
« Last Edit: April 30, 2015, 12:32:53 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)

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #17 on: April 30, 2015, 10:48:26 AM »
Thank you so much for this information.  I will spend some time this weekend with VC and the information that you all have provided.  I'll report back with my results next week.

Thanks again for the support.

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #18 on: May 03, 2015, 01:37:05 PM »
Having trouble with creating command #2  What am I missing?

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="422" name="Scan my devices" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/status</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>&lt;node\sid="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>devices</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>How many devices do I have</phrase>
</command>

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="527" name="Scan devices 2" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/status</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="\s"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result={var.devices} - {#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

« Last Edit: May 03, 2015, 01:40:09 PM by nime5ter »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #19 on: May 03, 2015, 01:46:10 PM »
Looks like there are a few small things. I'm a bit strapped for time so rather than explaining in detail, pls compare with the following. Hopefully these will work for you. If you have any questions let me/us know.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="686" name="Scan my devices" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/status</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>node\sid="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>Total number of devices: {#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>devices</param>
      <param>{#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.TriggerEvent</cmdType>
    <params>
      <param>check.inactive</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Scan my devices, How many devices do I have</phrase>
</command>

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="668" name="count active/inactive devices" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="You will need to have VC's Python plugin enabled to do the math calculation here.">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/status</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="\s"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>Inactive devices: {#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result={var.devices}-{#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>Active devices: {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>There are currently {LastResult} active devices and {#M} inactive devices on your network.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>check.inactive</event>
</command>
« Last Edit: May 03, 2015, 03:22:11 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)

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #20 on: May 03, 2015, 08:31:23 PM »
Thanks... I have compared the two and I understand what was done.  That said, I'm stuck on command #3 as well.  I can't seem to figure out how I associate the payload file that I have created for the node id's.  Here is what I have done so far.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="492" name="Get Status Info For My Lights" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/nodes/</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="(.*?)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType />
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
</command>
« Last Edit: May 03, 2015, 09:02:09 PM by nime5ter »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #21 on: May 03, 2015, 09:11:52 PM »
In the future, please put always put your command xml in a code box when you post it to the forum. There are two reasons we ask for this: 1) The code boxes have a fixed height, so long code takes up much less space on the page; 2) It makes it much easier for others to select/copy the xml.

Try the URL that I originally suggested you use for Command 3.

If you take another look, you'll see that I include the syntax for a payload value within the URL. If the documentation that I read was correct, that should be the proper url to get status properties for a particular node.

You might also want to take a bit of time to review the wiki documentation on payloads and perhaps watch the second Fireside Chat video. Various users have said they find that video really helpful for understanding how to use payloads. Getting a better grasp of that will save you a lot of time in the long run.

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)

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #22 on: May 03, 2015, 09:34:59 PM »
Will do, thanks.

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #23 on: May 03, 2015, 10:17:56 PM »
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="492" name="Get Status Info For My Lights" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/node/{1}/ST</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
</command>

Not working for me.  I get the following error:

"system.net web exception... 404 not found

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #24 on: May 03, 2015, 10:22:21 PM »
Edit: On first glance, looked like you wrote "node" instead of "nodes" in the URL.
« Last Edit: May 03, 2015, 10:31:10 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)

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #25 on: May 03, 2015, 10:34:29 PM »
Made the correction but still got the error.  The log file is attached.


nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #26 on: May 03, 2015, 10:36:06 PM »
A few things:

The URL should be "nodes" plural: http://192.168.1.5/rest/nodes/{1}/ST

But also: To test this command, you need to properly issue the voice command, not use Save & Execute. Otherwise the command will not know the payload value.

http://voxcommando.com/mediawiki/index.php?title=Payloads#More_on_Payload_XML

And in case it's not clear, your payload xml should have phrases like "kitchen light" associated with a node ID that is in the value column.

The other way to test the command if you can't issue a voice command, is to enter a node ID value in the {1} Test payloads field of the LCB, and then you can use the Save & Execute button.

« Last Edit: May 03, 2015, 10:39: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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #27 on: May 03, 2015, 10:46:37 PM »
I'm about to go to bed, but basically:

The idea behind the 3rd command is that you would be asking for the status of a particular light. I had in mind something like this:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="653" name="Status of light {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Where {1} is the node ID. &#xD;&#xA;The variable {PF.1} is the phrase in your payload xml file associated with the node id.">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://YOUR_ISY_URL/rest/nodes/{1}/ST</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>Off On&amp;&amp;{Match.1}</ifParams>
    <then>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1}.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{PF.1} is on, with a brightness level of {Match.1}%.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>{PF.1} is on, with a brightness level of {Match.1}%</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Is the</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
  <phrase>on, off</phrase>
</command>

I don't have your hardware so I can't say for sure that the URL is correct, but probably it is.
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)

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #28 on: May 03, 2015, 10:54:10 PM »
Sorry,  Im just not getting it.  I'll review the links when I have more time.


ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #29 on: May 03, 2015, 10:56:03 PM »
ok, I'll look at this in the morning with fresh eyes.  Thanks for your help.