Author Topic: MultiSwitch  (Read 4432 times)

0 Members and 1 Guest are viewing this topic.

AgileHumor

  • Contributor
  • ***
  • Posts: 62
  • Karma: 3
    • View Profile
MultiSwitch
« on: March 04, 2015, 08:55:41 PM »
Hello,

Could you consider adding support for the MultiSwitch plugin (as 8 separate switches in one)

Actions

When you select one of the MultiSwitch buttons as a scene or PLEG action, the default action will be a toggle of the switch state - on to off, off to on. If you open the scene or PLEG action Advanced tab, you will see that the newStatusN value is -1 which means toggle. To set the switch off, use a value of 0. To set the switch on, use a value of 1.

The following actions are provided for use by scenes and other plugins:

Code: [Select]
urn:dcineco-com:serviceId:MSwitch1 SetStatus1 newStatus1 = <0, 1 or -1>

..

urn:dcineco-com:serviceId:MSwitch1 SetStatus8 newStatus8 = <0, 1 or -1>

Most other apps that support MultiSwich show it as 8 individual On/Off switches in their interface.

Thanks so much if you could make this happen!  I'd gladly ship you a new Vera Edge (with UI7) for your trouble.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: MultiSwitch
« Reply #1 on: March 04, 2015, 10:30:26 PM »
Sure, I'm happy to take a look.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: MultiSwitch
« Reply #2 on: March 05, 2015, 12:35:11 PM »
Here's something to get you started.  I haven't decided yet if this should go into the actual plugin, mostly because I'm not sure what the best way to do that is yet.



Here is the group XML that I use in the video

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<commandGroup open="True" name="Vera multiswitch" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="317" name="multi switch initialize" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="You must set the ID for your multiswitch in the 1st action and then run this command.&#xD;&#xA;The command will always run when VC starts.  It will set the variable and scan your multi-switch button names.">
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>MltSwtchID</param>
        <param>79</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>File.MakeDir</cmdType>
      <params>
        <param>Vera1</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PayloadXML.Clear</cmdType>
      <params>
        <param>Vera1\multiswitches.xml</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Vera.Raw</cmdType>
      <params>
        <param>data_request?id=lu_variableget&amp;serviceId=urn:dcineco-com:serviceId:MSwitch1&amp;Variable=BtnNames&amp;DeviceNum={Var.MltSwtchID}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>"(.*?)"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PayloadXML.AddPair</cmdType>
      <params>
        <param>Vera1\multiswitches.xml</param>
        <param>{i}</param>
        <param>{Match.{i}}</param>
      </params>
      <cmdRepeat>{#M}</cmdRepeat>
    </action>
    <action>
      <cmdType>Group.Rebuild</cmdType>
      <params>
        <param>Vera multiswitch</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="1132" name="toggle multi switch {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Vera.Raw</cmdType>
      <params>
        <param>data_request?id=action&amp;output_format=xml&amp;DeviceNum={Var.MltSwtchID}&amp;serviceId=urn:dcineco-com:serviceId:MSwitch1&amp;action=SetStatus{1}&amp;newStatus{1}=-1</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>toggle multi switch</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">Vera1\multiswitches.xml</payloadFromXML>
  </command>
  <command id="1161" name="set multi switch {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{2}&amp;&amp;on</ifParams>
      <then>
        <action>
          <cmdType>Vera.Raw</cmdType>
          <params>
            <param>data_request?id=action&amp;output_format=xml&amp;DeviceNum={Var.MltSwtchID}&amp;serviceId=urn:dcineco-com:serviceId:MSwitch1&amp;action=SetStatus{1}&amp;newStatus{1}=1</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Vera.Raw</cmdType>
          <params>
            <param>data_request?id=action&amp;output_format=xml&amp;DeviceNum={Var.MltSwtchID}&amp;serviceId=urn:dcineco-com:serviceId:MSwitch1&amp;action=SetStatus{1}&amp;newStatus{1}=0</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>turn multi switch</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">Vera1\multiswitches.xml</payloadFromXML>
    <payloadList>on, off</payloadList>
  </command>
  <command id="1222" name="Is multi switch {1} on" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Vera.Raw</cmdType>
      <params>
        <param>data_request?id=lu_variableget&amp;serviceId=urn:dcineco-com:serviceId:MSwitch1&amp;Variable=Status{1}&amp;DeviceNum={Var.MltSwtchID}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{LastResult}&amp;&amp;1</ifParams>
      <then>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Multi switch {PF.1} is on</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Multi switch {PF.1} is off</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>is multi switch</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">Vera1\multiswitches.xml</payloadFromXML>
    <phrase>on</phrase>
  </command>
</commandGroup>

AgileHumor

  • Contributor
  • ***
  • Posts: 62
  • Karma: 3
    • View Profile
Re: MultiSwitch
« Reply #3 on: March 08, 2015, 12:24:46 AM »
Thanks man!  Your quick on the code sir.

paulcusick3

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: MultiSwitch
« Reply #4 on: April 03, 2015, 06:09:19 PM »
Thank you for this.  The code works well for VC voice triggers.  However, I do not seen the Vera triggers coming through the log to have them trigger VC actions.

My use case is to use PLEG for logic; the action turns on a MultiSwith, and then have VC trigger an action.  I can do this via a scene or a tradition switch.... but not multi-switch.

Any advice?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: MultiSwitch
« Reply #5 on: April 03, 2015, 06:26:40 PM »
The next version of VoxCommando will have a new version of the Vera plugin with a revised event engine that will support multi-switch.

In the meantime you can have PLEG send events to VC using luup if you want.