Author Topic: Regex Results  (Read 10757 times)

0 Members and 1 Guest are viewing this topic.

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Regex Results
« on: April 27, 2015, 11:20:04 PM »
Having trouble writing the Regex code to produce results from my ISY994i home automation device.  Can someone help?

Here is what I would like to do.  I would like to pull status information from devices in my ISY.  Here is what I have so far

formatted="Off" uom="%/on/off" /></node><node id="32 80 D2 1"><property id="ST" value="0"

I would like to pull the "Off" state for the node id "32 80 D2 1"
__________________________

formatted="78.00" uom="degrees" /><property id="CLIMD" value="1" formatted="Heat" uom="n/a" />

I would like to pull the degree status "78", the thermostat mode "Heat"

Any help would be appreciated


Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Regex Results
« Reply #1 on: April 28, 2015, 12:08:21 AM »
You can use the VC regexTool which will you help a lot.


for - Off
formatted="(.*?)"


and for 78
formatted=\W(\d+)


if you need 78.0
formatted=\W(\d+\W\d) and this will give you the same result: (\d+\W\d)


so you can see, there are many options - the following picture will show you how it looks in the VC- RegExTool



« Last Edit: April 28, 2015, 01:41:41 AM by Kalle »
***********  get excited and make things  **********

PegLegTV

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: Regex Results
« Reply #2 on: April 28, 2015, 12:21:48 AM »
I'm guessing that you are looking for the "off" listed after formatted= if so the first command in the group below should do it, the second command should work for retrieving the "78"

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.8-->
<commandGroup open="True" name="regex examples " enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="625" name="regex for off status" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>formatted="(.*?)"\Wuom="%/on/off"\W/&gt;&lt;/node&gt;&lt;node\Wid="32\W80\WD2\W1"&gt;&lt;property\Wid="ST"\Wvalue="0"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
  <command id="626" name="regex for 78  " enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>formatted="(.*?)"\Wuom="degrees"\W/&gt;&lt;property\Wid="CLIMD"\Wvalue="1"\Wformatted="Heat"\Wuom="n/a"\W/&gt;</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
</commandGroup>

if you look at the two commands you will see that where the info you where trying to grab ( "off" and "78") there is
Code: [Select]
(.*?) this will capture everything in the defined area,

you will also see there are several
Code: [Select]
\W this is used to define "any nonword character" which in this case was "spaces"

and you can do like kalle shows above, he posted while I was typing mine out




jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Results
« Reply #3 on: April 28, 2015, 08:49:03 AM »
It will only be possible to give you reliable regex patterns if you show us the complete string you are trying to analyse. If possible, give us several complete examples from different devices or events.

Otherwise there is too much guesswork and you will end up with actions that only work some of the time, or simply return incorrect values.

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #4 on: April 28, 2015, 09:11:22 AM »
All, thanks much.  This helps a lot.  Also, from the same result above, I'd like to pull the thermostat mode status(heat or cool) and the node id (14 2E B1 1).  Using the regex tool in VC I get all tangled up when trying to pull multiple things. 

@Jitterjames... will do.  Following is the complete results that i pulled from my isy.

Thermostat Results

<node id="11 B3 8F 1"><property id="ST" value="156" formatted="78.00" uom="degrees"/><property id="CLIMD" value="1" formatted="Heat" uom="n/a"/><property id="CLISPC" value=" " formatted=" " uom="degrees"/><property id="CLISPH" value="140" formatted="70.00" uom="degrees"/><property id="CLIHUM" value="73" formatted="73.00" uom="%"/></node>

Light switch result
<node id="14 2E B1 3"><property id="ST" value="0" formatted="Off" uom="on/off"/>

Door Lock result
<node id="ZW003_1"><property id="ST" value="100" formatted="Locked" uom="11"/></node>




jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Results
« Reply #5 on: April 28, 2015, 09:18:35 AM »
Do these messages all arrive together or separately?

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #6 on: April 28, 2015, 11:03:56 AM »
It depends on how I query the isy.  In this particular case I have formatted the query to pull the status of all devices in the isy.  I broke them out (thermostat, Light Switch and Door Lock) below to give examples of what I am trying to pull from the results. 

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Results
« Reply #7 on: April 28, 2015, 11:11:10 AM »
It will only be possible to give you reliable regex patterns if you show us the complete string you are trying to analyse.

Whatever string you get back and are trying to apply the RegEx to, show us the complete string that is returned from your query, unedited, unspliced, no lines added, not broken up, etc.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Results
« Reply #8 on: April 28, 2015, 11:20:15 AM »
Assuming you can ask for information on one specific node at a time, then you will know which node these values are for and you can break up all the properties and values returned for that node as follows.

I am using the pattern \s for spaces since it is the most precise and clear method, I think.

Code: [Select]
<property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"
Try it with the RegEx tool to see what you get.
« Last Edit: April 29, 2015, 08:48:09 AM by nime5ter »

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #9 on: April 28, 2015, 11:23:21 AM »
ok, will do going forward.  At the moment I am away from my ISY.  I will resubmit this evening.


ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #10 on: April 28, 2015, 11:29:13 AM »
Yes, However, if I wanted to find all of the nodes with a specific status and have VC report the total number of devices that are"ON"  how does that look in the Regex tool.  I will play more with it tonight.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Results
« Reply #11 on: April 28, 2015, 11:57:16 AM »
Yes, However, if I wanted to find all of the nodes with a specific status and have VC report the total number of devices that are"ON"  how does that look in the Regex tool.  I will play more with it tonight.

If all you want to know is the total number of devices that are "on" at a given moment -- without knowing which specific devices are on -- then you can query the status of all devices at once looking for the regex pattern:

Code: [Select]
formatted="(On)"
Each time the pattern in the brackets is captured it counts as 1 match (first match = {Match.1}, second match = {Match.2} etc.).

Therefore {#M} tells you how many devices are on.

Of course, this will only work for devices that report their on/off state in this format.

The regex tool will show you a list of all the matches. It also provides the total number of matches in the label on the left.
It will not tell you the standard VC syntax for different variables, though. You'll need to know that {#M} refers to the total number of matches, or look in your parameter helper window in VC, or review the wiki page that lists all the standard VC variables.



« Last Edit: April 28, 2015, 12:20:41 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 #12 on: April 28, 2015, 12:51:56 PM »
Got it, thanks.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Results
« Reply #13 on: April 28, 2015, 09:22:39 PM »
Why all the \ in front of property?

ddl

  • Sr. Member
  • ****
  • Posts: 118
  • Karma: 0
    • View Profile
Re: Regex Results
« Reply #14 on: April 29, 2015, 12:58:35 AM »
ok, i think I figured it out.  However, the results from the query above has spaces in it.  When i place the regex code in the regex tester it crashes at the point where it is a space.  How do I get pass that?  The "\s" does not work.

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?><nodes><node id="11 B3 8F 1"><property id="ST" value="156" formatted="78.00" uom="degrees" /><property id="CLIMD" value="1" formatted="Heat" uom="n/a" /><property id="CLISPC" value=" " formatted=" " uom="degrees"/><property id="CLISPH" value="150" formatted="75.00" uom="degrees" /><property id="CLIHUM" value="73" formatted="73.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="255" formatted="On" 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" [b]uom="%/on/off" />[/b]</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>
Code: [Select]
<node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"\ /><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/ ><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"\sformatted="(.*?)"\suom="(.*?)"/></node><node\sid="(.*?)"><property\sid="(.*?)"\svalue="(.*?)"