Author Topic: Hue Group status  (Read 2948 times)

0 Members and 1 Guest are viewing this topic.

Vin

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Hue Group status
« on: February 02, 2017, 03:50:55 PM »
Hi All,

I have implemented vox using Regex to check Hue light status, so it states if the light is already ON or OFF (Done with 2 commands one, for ON and one for OFF)

Im having problem implementing it on Group. Need some help with RegexSingle or Regex.

This is the code for the Lights which is working.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.2.9-->
<command id="1007" name="Turn {1} light ON" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="80" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Hue.Raw.Get</cmdType>
    <params>
      <param>lights</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>"on":\strue .*? "name":\s"(.*?)"</param>
      <param>:</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.MatchConcat</cmdType>
    <params>
      <param> | </param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;{PF.1}</ifParams>
    <then>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>The {PF.1} is already on</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>Hue.Light</cmdType>
        <params>
          <param>{1}</param>
          <param>"on":true</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>The {PF.1} has been turned on</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Turn</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">huePayloads\lights.xml</payloadFromXML>
  <phrase>ON</phrase>
</command>
« Last Edit: February 02, 2017, 10:56:00 PM by Vin »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Hue Group status
« Reply #1 on: February 02, 2017, 05:15:28 PM »
Hi, welcome to the forum.

The xml you posted isn't valid, which means we can't copy and paste it into our own command trees to see and test the command.

Can you try again to copy and paste the command in question from your command tree?  (See my signature for the link to posting commands on the forum, if you're not yet familiar with how to copy xml to and from the editor window).

Thanks.

That said, if you start with the standard Hue configuration that comes with VC it might be easier, as you'll have a good range of examples to build from.

In that configuration, try adapting the command called "What are my groups called", which I believe is in the Hue Get Status Info command group. You'll see that rather than getting "lights" info from Hue, it's getting "groups" info.

If you replace the RegexSingle action in that command with:
Code: [Select]
name":."(.*?)".*?all_on":.(.*?),
it should show you a list of all group names and whether each group is on ("true") or off ("false").

If that's what you want, the command can then be adapted to the phrasing and response that you want.


« Last Edit: February 02, 2017, 05:17:48 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)

Vin

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Hue Group status
« Reply #2 on: February 02, 2017, 07:31:40 PM »
Thanks for the quick reply, yes I did start with the default hue commands but now im adding these custom ones.

Im trying to filter group "name" that has "action":{"on":true then compare it with the payload if they match the group is already ON and TTS will advise it's already on otherwise it will turn group ON.

I tried the regex you provided but it captures all the the group even with the "on":false

Here's what I have for group

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.2.9-->
<command id="1022" name="Turn {1} ON" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="80" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Hue.Raw.Get</cmdType>
    <params>
      <param>groups</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>"{1}":\s{.*?".*?"all_on":\s(.*?),</param>
      <param>:</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{Match.1.1}&amp;&amp;True</ifParams>
    <then>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>The {PF.1} is already on</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>Hue.Group</cmdType>
        <params>
          <param>{1}</param>
          <param>"on":true</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>The {PF.1} has been turned on</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Turn</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">huePayloads\groups.xml</payloadFromXML>
  <phrase optional="true">lights</phrase>
  <phrase>ON</phrase>
</command>

I tried
Code: [Select]
"name":\s"(.*?)" .*? "on":\s(true)  and picks up the name of group but extends till it finds "on":true
« Last Edit: February 02, 2017, 10:57:05 PM by Vin »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hue Group status
« Reply #3 on: February 02, 2017, 08:59:04 PM »
RegEx works that way.  If you give it a pattern like that it will find the shortest possible match.  By using true in your pattern it will keep looking until it hits true.  The solution is to capture the state of the group in question and then check to see if all_on is true or not.

By the way you are getting close with the XML but it's best to copy the command from the tree editor view so that you get the whole command.  So, not only the actions from the macro but also the input (phrases and payloads and events) for the command as well.

This works for me:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.4-->
<command id="1204" name="is group {1} on" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Hue.Raw.Get</cmdType>
    <params>
      <param>groups</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>"{1}":\s{.*?".*?"all_on":\s(.*?),</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{Match.1.1}&amp;&amp;True</ifParams>
    <then>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Yes, all lights in that group are on.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>No, I'll turn it on for you.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Hue.Group</cmdType>
        <params>
          <param>{1}</param>
          <param>"on":true</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>is group</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">huePayloads\groups.xml</payloadFromXML>
  <phrase>on</phrase>
</command>
« Last Edit: February 02, 2017, 09:10:09 PM by nime5ter »

Vin

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Hue Group status
« Reply #4 on: February 02, 2017, 11:11:15 PM »
Thank you, appreciate it, that works.

If you can kindly can you do some tutorials on RegexSingle, would like to understand a little bit more how it works.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Hue Group status
« Reply #5 on: February 03, 2017, 04:31:12 AM »
Hi Vin,

here it is  ;)



***********  get excited and make things  **********

Vin

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Hue Group status
« Reply #6 on: February 03, 2017, 09:20:43 AM »
Thanks Kalle I already watch those James used RegEx on those, I was hoping James have some time to do tutorials on RegexSingle.
« Last Edit: February 03, 2017, 09:23:59 AM by Vin »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hue Group status
« Reply #7 on: February 03, 2017, 09:25:18 AM »
RegExSingle works exactly the same way as RegEx.

The only difference is that it allows your pattern to match across multiple lines. Another way to look at it is to imagine that all your input text was on a single line.

There is no other difference. All of the normal rules of RegEx apply to both. There are an endless number of resources online for learning how to use RegEx and the RegEx tool in VoxCommando is a great way to experiment and get comfy finding ways to use RegEx.
« Last Edit: February 03, 2017, 10:00:19 AM by nime5ter »

Vin

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Hue Group status
« Reply #8 on: February 04, 2017, 09:03:05 AM »
Thanks James.