Author Topic: Command with 2 optional payloads  (Read 2132 times)

0 Members and 1 Guest are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Command with 2 optional payloads
« 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?

Code: [Select]
<?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>
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Command with 2 optional payloads
« Reply #1 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.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Command with 2 optional payloads
« Reply #2 on: March 04, 2015, 06:12:06 PM »
btw, I think you can ditch the optional "?" at the end... ;)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Command with 2 optional payloads
« Reply #3 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.

Code: [Select]
<?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>
« Last Edit: March 04, 2015, 07:03:09 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)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Command with 2 optional payloads
« Reply #4 on: March 05, 2015, 11:30:25 AM »
@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 ...

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
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Command with 2 optional payloads
« Reply #5 on: March 05, 2015, 11:54:04 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!
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)