Author Topic: Regex Results  (Read 10708 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 #30 on: May 04, 2015, 01:34:53 PM »
Apart from the fact that the command 3 I had in mind was specifically for retrieving light device info, your payload XML looks perfectly fine. (And you could certainly just make one command to get the status of any type of device; I just think dividing it up would provide more control over how you handle the returned values.)

Sorry,  Im just not getting it.  I'll review the links when I have more time.

Another video tutorial that might help you is the Vera plugin tutorial, even though you don't have a Vera. It describes the process of building commands for home automation using payload XML, which might help clarify the basic thinking behind how such commands are structured.

I suspect that if you can find some time to just concentrate on exploring the available resources that explain the fundamentals: how payloads work, how variables work, how command testing works, you will ultimately save a TON of time -- and frustration.
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 #31 on: May 10, 2015, 10:52:56 AM »
This weekend I took some time to review this thread, the wiki and the links/videos suggested.  After my review I do have a better understanding of how Regex and payloads work in VC.  That said, I still need a little help with drafting the number 3 command.  First, let me say that after spending hours trying to formulate the correct syntax for the scrape command for getting the requested information from the ISY.  I have learned that the URL http://192.168.1.5/rest/nodes/{1}/ST is not recognized by the ISY as written.  The ISY does not recognize the payload indicator {1} and "ST".  Instead i have used http://192.168.1.5/rest/status.  This url gives me the status of all devices in the ISY.  See the full results below.

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?><nodes><node id="11 B3 8F 1"><property id="ST" value="154" formatted="77.00" uom="degrees" /><property id="CLIMD" value="2" formatted="Cool" uom="n/a" /><property id="CLISPC" value="154" formatted="77.00" uom="degrees" /><property id="CLISPH" value=" " formatted=" " uom="degrees"/><property id="CLIHUM" value="75" formatted="75.00" uom="%" /></node><node id="14 2E B1 1"><property id="ST" value=" " formatted=" " uom="on/off"/></node><node id="14 2E B1 2"><property id="ST" value=" " formatted=" " uom="on/off"/></node><node id="14 2E B1 3"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="17 53 DB 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="17 54 96 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="1B 6E 54 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="1B 71 A0 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="1B 80 D2 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="22 B2 82 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="24 99 A0 1"><property id="ST" value="0" formatted="Off" uom="%/on/off" /></node><node id="29 B9 D 1"><property id="ST" value="0" formatted="Off" uom="%/on/off" /></node><node id="2A 29 97 1"><property id="ST" value="0" formatted="Off" uom="%/on/off" /></node><node id="32 80 D2 1"><property id="ST" value="0" formatted="Off" uom="on/off" /></node><node id="C 7B 80 1"><property id="ST" value="0" formatted="Off" uom="%/on/off" /></node><node id="ZW003_1"><property id="ST" value="100" formatted="Locked" uom="11" /></node><node id="ZW014_1"><property id="ST" value="0" formatted="Off" uom="78" /></node><node id="ZW015_1"><property id="ST" value="0" formatted="Off" uom="78" /></node><node id="ZW016_1"><property id="ST" value="0" formatted="Off" uom="78" /></node></nodes>
To grab the information that I need for VC to report on I used the following Regex code:

Code: [Select]
node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"
At this point everything appears to work ok until I get to my logic block.  The results from the logic block that I have written only reports half of the information correctly.  Here is what i have written so far:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="512" name="Device Status {1}" 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>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>node\sid="(.*?)"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>{Match.1.4}&amp;&amp;{Match.1.4}</ifParams>
    <then>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1.4}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1.4}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <action>
    <cmdType />
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Is the, What is the</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="True" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
  <phrase>On Off , Status</phrase>
</command>

At the end of the day, VC reports the status of the device incorrectly when using the "what is the" kitchen main light (as written in the payload file) command.  It will report back the first device status as indicated by the "{Match.1.4}"

How do I write the logic block so that it reports back the correct status for any device that I request that information for?

Also, while I know that i can write a command for each device individually I was just looking to save time by using a payload as suggestd.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #32 on: May 10, 2015, 11:24:24 AM »
I'll take a look and get back to you.

In the meantime, could you please do the following for me?

Enable VC logging (if it's not already enabled), then run the following command exactly as is, then post your log for me? Thanks.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="766" name="Test status command" 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/11 B3 8F 1/ST</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>System.SetClipboardText</cmdType>
    <params>
      <param>Test 1: {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.5/rest/nodes/11%20B3%208F%201/ST</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>System.SetClipboardText</cmdType>
    <params>
      <param>Test 2: {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Test status command</phrase>
</command>
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 #33 on: May 10, 2015, 11:30:17 AM »
Thank you...

Here is the log as requested.


nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #34 on: May 10, 2015, 11:41:49 AM »
Thank you, that's helpful.

The command that we just tested used the URL that I initially suggested: http://192.168.1.5/rest/nodes/<node id>/ST, and works correctly according the log.

If you look at the Scrape action in that command, you'll see that we used the id for a specific node: 11 B3 8F 1, which is your thermostat.

It returned the following response when you executed the command:

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?><properties><property id="ST" value="154" formatted="77.00" uom="degrees" /></properties>
This result, and now looking at the command you posted above where you're grabbing the status of all devices, indicates to me that you're still not understanding how payloads work. This will be the challenge to overcome, not the regular expression aspect.

You may have already watched this, but can you please watch the following section of the Vera tutorial video again?

&feature=youtu.be&t=5m56s

It gives a step-by-step example of using 2 types of payloads to control dimmable lights. I'm hoping that will give us a better starting point for moving forward.

In the meantime I will work on a follow-up post to discuss your command above.
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 #35 on: May 10, 2015, 11:47:13 AM »
ok, I will watch the video again. 


ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #36 on: May 10, 2015, 12:02:38 PM »
I think I am confused by the Scrape "http://192.168.1.5/rest/nodes/{1}/ST".  My interpretation of this is that VC is scraping the isy and referencing the payload file (not individual node) for the devices state.  The URL" http://192.168.1.5/rest/nodes/{1}/ST" as written is not accepted by the ISY and returns and error.  This is why I used the URL "http://192.168.1.5/rest/status"

In my mind, if after I asking for the status of the kitchen light VC scans the payload list for the device to report its status.  Correct?  If not, that is where my problem is and I can't do what I thought I could do without creating a separate command for each node.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #37 on: May 10, 2015, 12:38:27 PM »
That's not what's happening.

VC cannot scrape ISY if it is not using a valid URL.

http://192.168.1.5/rest/nodes/{1}/ST is certainly not a valid URL.

It becomes a valid URL when you issue the command correctly, so that the node ID *replaces* {1} in your macro, and then VC will scrape that URL.

Your command is not working when you issue it because you are not issuing the command correctly, somehow.

Either there's something wrong with your payloadXML file, or with how you are saying the command.

Or, if you are not saying the command but trying to execute it by clicking "save and execute" then you have not entered a node ID in the Test payload field as demonstrated in the video.

I'm sorry for the following super-long post. I hope it's manageable. I discuss both the command you posted today, as well as the original suggestion.

----

It *is* possible to get the status of a specific device using the method you were trying, but it will be a bit more complicated than the way I originally suggested.

I can't decide if it will be helpful or just confusing to explain why. But here goes.

Your command phrase that you posted is: What is the {ISY Node Name} status?

the {ISY Node Name} refers to the payload XML file you created, in which you have friendly names associated with node IDs.

The only way VoxCommando can then use that node ID that you specify in your voice command is for you to have the equivalent payload value {1} in your command macro.

Using a payload in your command phrase is not enough. You need to pass that to the macro.

Let's look at the original command format that I suggested for a second.

In the *original* command that I suggested, the node ID should have been passed into the URL:

Code: [Select]
http://192.168.1.5/rest/nodes/{1}/ST
So, if you had verbally issued (i.e., said) the command "What is my {thermostat} status", then VC would know to use the node ID associated with that friendly name: 11 B3 8F 1, and it would pass that into the URL in the Scrape action.

Code: [Select]
http://192.168.1.5/rest/nodes/11 B3 8F 1/ST
But if you don't actually say the command but instead just try to "save and execute" without giving the command a payload value, VC would have had no idea what {1} stands for, and it would not have scraped the proper URL. In other words, there is no such URL as: http://192.168.1.5/rest/nodes/{1}/ST. We have to issue the command correctly, passing a proper node ID value to the command.

Now back to the command you're trying to use, which you posted today:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="512" name="Device Status {1}" 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>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>node\sid="(.*?)"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>{Match.1.4}&amp;&amp;{Match.1.4}</ifParams>
    <then>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1.4}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>{PF.1} is currently {Match.1.4}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <action>
    <cmdType />
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Is the, What is the</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="True" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
  <phrase>On Off , Status</phrase>
</command>

If you choose to scrape all devices, then in order to get the status of one specific device, you should tell the command which device you are interested in. That means passing it the node ID as a payload value, so it knows which node to isolate out of all the possible nodes.

But nowhere in that command have you specified the node ID. That is, {1} is missing from your macro. So VC will have no idea which device it should be looking for in the feedback that it receives from ISY.

Your current regular expression is:

Code: [Select]
node\sid="(.*?)"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"
{Match.1.4} will return the formatted value of the very first device listed. In your case, that is always the thermostat.

So how can you find the node you're actually interested in? Instead of using a general pattern that will match for every device you have, you should instead use a pattern that only works for the node you are interested in.

In other words, tell it what node ID to find.

Code: [Select]
node\sid="{1}"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"
So, if you ask for the "motion detector low battery" status, its node ID (14 2E B1 3) is passed into the regular expression.

Code: [Select]
node\sid="14 2E B1 3"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"
Note that now you only have 3 sets of brackets in your regular expression, so the "formatted" value will be {Match.1.3} now (you're not capturing the node id).

Unfortunately, now we get into a complication caused by how regular expressions work. So while the above is correct as a concept, we have more tap-dancing to do because your node IDs have spaces in them, and regular expressions don't like spaces. (This is why you use "\s" in your regex above.)

Here is one way to overcome the problem. What we do is:

1. Pass the payload {1} value into the command and set it to be the {LastResult}
2. Then we replace the spaces with a . character (you could also use \s)
3. We save the node id, now in the format like 14.2E.B1.3 as a variable I call "device".
4. Now you can use the {var.device} variable in the regular expression.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="512" name="Device Status {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>{1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param><![CDATA[ ]]></param>
      <param>.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>device</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <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="{var.device}"&gt;&lt;property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{PF.1} is currently {Match.1.3}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{PF.1} is currently {Match.1.3}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Is the, What is the</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="True" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
  <phrase>On, Off , Status</phrase>
</command>

Personally, I think my original suggestion to use the status URL that specific to each node is a cleaner solution, but this way also works.


« Last Edit: May 10, 2015, 01:04:32 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 #38 on: May 10, 2015, 12:53:48 PM »
There is another possibility for why "http://192.168.1.5/rest/nodes/{1}/ST" hasn't worked.

It may be that this URL doesn't work for all the various types of devices you have. The documentation implies that it should, but who knows.

I know that it works for your thermostat, because we tested that this morning. I'm quite sure it will work for your light switches as well. If you always issued the command asking for the status of a particular device type -- and by chance that device type doesn't support that type of request -- then the command would have failed.

The easiest way to know would probably be to enter different node IDs into the command I had you test earlier, and see what kind of results you get back.
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 #39 on: May 10, 2015, 01:23:25 PM »
Here is the original command 3 that I suggested (basically). I've kept your phrasing. Give it a try.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="512" name="Device Status {1}" 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/{1}/ST</param>
      <param>don</param>
      <param>dond</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>formatted="(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>The status of {PF.1} is {Match.1}.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>The status of {PF.1} is {Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Is the, What is the</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="True" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\ISYNodeNames.xml</payloadFromXML>
  <phrase>On, Off , Status</phrase>
</command>
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 #40 on: May 10, 2015, 01:55:29 PM »
Wow!  I'am getting it. :) This was so helpful!  Thanks so much for the detailed response.  It is without a doubt that I will study and learn from all of it. Thanks again for your patience and prompt attention.  I really appreciate it. 

I will put this to test and report back shortly.