VoxCommando Forum

Help and Support (Using VoxCommando) => VoxCommando Basics and Core Features => Topic started by: Haddood on March 04, 2015, 05:40:42 PM

Title: Command with 2 optional payloads
Post by: Haddood on March 04, 2015, 05:40:42 PM
I have weather command (based on nime5ter command  http://voxcommando.com/forum/index.php?topic=1755.msg15262#msg15262 ) with 2 payloads, the second is the location and is optional. So if I say what is the weather forecast for today, it will give me that of my city and if I say what is the weather forecast for today in Buenos Aires it will give that of Buenos Aires ...

I would like to make the first payload optional (to avoid saying for today), however a complication arises, if I say what is the weather forecast for Buenos Aires, it will take Buenos Aires as payload 1  and the command won't function properly.

is there a way to determine which payload was passed to the command, or any other approach to tackle problem of this type?


<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.8-->
<command id="384" name="Weather forecast" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>ProcessRunning</ifType>
    <ifParams>Kodi&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>XJson.Connect</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <params>
          <param>Kodi.Cmd.Weather</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{#P}&amp;&amp;2</ifParams>
    <then>
      <action>
        <cmdType>WUnder.Change</cmdType>
        <params>
          <param>{2}</param>
          <param>en</param>
          <param>c.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>WethLoc</param>
          <param>in {PF.2}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>WethLoc</param>
          <param><![CDATA[ ]]></param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>weather({1})</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>Weather {var.WethLoc} for {{var.day}.weekday}: {{var.day}.conditions}, with high of {{var.day}.high} degrees Celsius and a low of {{var.day}.low} degrees. There's a {{var.day}.pop}% chance of precipitation, with winds averaging {{var.day}.avewind} km/h.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.TriggerEvent</cmdType>
    <params>
      <param>feedback</param>
      <param>{LastResult}</param>
      <param>2</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>WUnder.Change</cmdType>
    <params>
      <param>Montreal, Quebec</param>
      <param>en</param>
      <param>c.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>WethLoc</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>Weather.Info</event>
  <phrase>What is the</phrase>
  <phrase>weather, forecast, weather forcast</phrase>
  <phrase>for</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\weather_day.xml</payloadFromXML>
  <phrase optional="true">in</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\Weather Locations.xml</payloadFromXML>
  <phrase optional="true">?</phrase>
</command>
Title: Re: Command with 2 optional payloads
Post by: jitterjames on March 04, 2015, 05:47:10 PM
Unfortunately you can only know the number of payloads by using {#P}.

My original solution to this problem was to simply make optional payloads "not an option" to avoid confusion, but I did not want to impose that limitation.

In your case where you might have one or another payload, so a count of 1 payload doesn't tell you which one you are getting is tricky.  The two possible solutions that spring to mind are:

- Create two different commands, instead of using two optional payloads.  This is probably the best and safest solution and would only be a problem if you are using a payloadXML with a large number of items, in which case duplicating the command would be a bit wasteful.

or

- Look at the payload values and see if there is some pattern you can exploit to determine which type of payload you are getting, then apply some logic.
Title: Re: Command with 2 optional payloads
Post by: jitterjames on March 04, 2015, 06:12:06 PM
btw, I think you can ditch the optional "?" at the end... ;)
Title: Re: Command with 2 optional payloads
Post by: nime5ter on March 04, 2015, 06:30:54 PM
@Haddood -- the following works for me in the way you describe.

I was able to ask for just the forecast of a city, or else specify a day of the week for a forecast in a particular city. In the first case, it will use today's forecast.

Or if you just ask for the generic "weather forecast" it gives today's local forecast.

I would recommend that you test it in its current form. If it works as is, then you can change it back to using your own phrasing and event trigger system.

... Be careful with your phrasing though.

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="384" name="Weather forecast" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <if ifBlockDisabled="True" ifNot="False">
    <ifType>ProcessRunning</ifType>
    <ifParams>Kodi&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>XJson.Connect</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <params>
          <param>Kodi.Cmd.Weather</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{#P}&amp;&amp;0</ifParams>
    <then>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>day</param>
          <param>D0</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>WUnder.GetCustom</cmdType>
        <params>
          <param>Weather in Montreal for {{var.day}.weekday}: {{var.day}.conditions}, with high of {{var.day}.high} degrees Celsius and a low of {{var.day}.low} degrees. There's a {{var.day}.pop}% chance of precipitation, with winds averaging {{var.day}.avewind} km/h.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.StopMacro</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>0,1,2,3,4,5,6,7,'today','tomorrow',&amp;&amp;{1}</ifParams>
    <then>
      <action>
        <cmdType>PY.ExecString</cmdType>
        <params>
          <param>weather({1})</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>WUnder.Change</cmdType>
        <params>
          <param>{2}</param>
          <param>en</param>
          <param>c.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>WethLoc</param>
          <param>in {PF.2}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>WUnder.Change</cmdType>
        <params>
          <param>{1}</param>
          <param>en</param>
          <param>c.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>WethLoc</param>
          <param>in {PF.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>day</param>
          <param>D0</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>Weather {var.WethLoc} for {{var.day}.weekday}: {{var.day}.conditions}, with high of {{var.day}.high} degrees Celsius and a low of {{var.day}.low} degrees. There's a {{var.day}.pop}% chance of precipitation, with winds averaging {{var.day}.avewind} km/h.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>WUnder.Change</cmdType>
    <params>
      <param>Montreal, Quebec</param>
      <param>en</param>
      <param>c.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>WethLoc</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>weather forecast</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\weather_day.xml</payloadFromXML>
  <phrase optional="true">in</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\Weather Locations.xml</payloadFromXML>
</command>
Title: Re: Command with 2 optional payloads
Post by: Haddood on March 05, 2015, 11:30:25 AM
Quote from: nime5ter on March 04, 2015, 06:30:54 PM
@Haddood -- the following works for me in the way you describe.

I was able to ask for just the forecast of a city, or else specify a day of the week for a forecast in a particular city. In the first case, it will use today's forecast.

Or if you just ask for the generic "weather forecast" it gives today's local forecast.

I would recommend that you test it in its current form. If it works as is, then you can change it back to using your own phrasing and event trigger system.

... Be careful with your phrasing though.


thank you nime5ter. I thought this approach, which works for this context since payload 1 is a small list... however I was hoping for a solution that works in any situation ...

Quote from: jitterjames on March 04, 2015, 06:12:06 PM
btw, I think you can ditch the optional "?" at the end... ;)

James, I put these as I find myself often using tellvox to test VC commands I am working on late at night ... and often I type those at end of a question

thank you guys for all the support ... you are the best
Title: Re: Command with 2 optional payloads
Post by: nime5ter on March 05, 2015, 11:54:04 AM
Quote from: Haddood on March 05, 2015, 11:30:25 AM
however I was hoping for a solution that works in any situation ...

Ah, I see.

I tend to think of each VC challenge as having its own best resolution (as with most of life's Special Problems ;-)).

In my experience, generalizability only applies when variables are severely limited -- but maybe that's just me!