Skip to content

Rules Engine

Aymeric edited this page Jan 13, 2015 · 28 revisions

The official documentation has been moved to http://wiki.sarah.encausse.net/

.
.
.
.
.
.
.
.

"Modules" rule

You can add a rule which execute itself when a specific plugin is launched, and after execution, the rule run another specific plugin, with options.

  • Open web interface (http://127.0.0.1:8080)
  • Go to 'Règles' (left menu)
  • In the "Modules" section, you can modify the existing empty rule or create a new one by pressing "Ajouter une règle" button.
  • First select the plugin (or module) which will shutter the rule ("If...")
  • type the code you want execute by clicking on the "do" (then do)
  • select the plugin you want the rule to run after each execution of the executing plugin (if)

NOTE : plugins needs arguments to run. If you have a look on the xml file of the "XBMC" plugin, you can see these arguments (in bold in code below)

	<rule id="ruleXBMC_Telecommande" scope="public">
		<example>SARAH musique suivante</example>
		<tag>out.action=new Object(); </tag>
		<one-of>
			<item>met en pause la série<tag>out.*action.action="playvideo"*</tag><tag>out.*action.xbmc="video*" </tag></item>
			<item>remet la série<tag>out.action.action="playvideo"</tag><tag>out.action.xbmc="video" </tag></item>
			<item>met la musique sur pause<tag>out.action.action="play"</tag><tag>out.action.xbmc="music" </tag></item>
			<item>reprends la musique<tag>out.action.action="play"</tag><tag>out.action.xbmc="music" </tag></item>

In the rule code (remember : under the "do" button!), theses arguments are all passed in an object named options. So you can do 2 things in the rule code :

  • test the arguments from the "If" module
  • set the arguments of the "then" module (mandatory) ###Exemple 1 you have a module which can turn on and off the light and that this module need 2 actions to run : "light" and "status".
	<tag>out.action=new Object(); </tag>
	<one-of>
		<item>allume la lumière<tag>out.action.light=true</tag><tag>out.action.status="on"</tag></item>
		<item>éteins la lumière<tag>out.action.light=true</tag><tag>out.action.status="off"</tag></item></item>
	</one-of>

magine you want to turn the light on when you pause the video in xbmc :

if((options.xbmc=="video") && (options.action=="play")){
	options.light=true;
	options.status="on";
}

NOTE : currently, the xbmc plugin cannot make difference between a "play" and a "pause" order. You need to add these order by changing the out.action.action="playvideo" and out.action.action="play" tags in the XBM. XML file AND in the XBMC.js file : just duplicate this lines :

	case 'play':
            doAction(play, xbmc_api_url, callback);
            break;
	case 'playvideo':
            doAction(playvideo, xbmc_api_url, callback);
            break;

to :

	case 'play':
            doAction(play, xbmc_api_url, callback);
            break;
	case 'playvideo':
            doAction(playvideo, xbmc_api_url, callback);
            break;
	case 'pause':
            doAction(play, xbmc_api_url, callback);
            break;
	case 'pausevideo':
            doAction(playvideo, xbmc_api_url, callback);
            break;

###Exemple 2 You want SARAH say "Goodby" (plugin "parle") when you tell her to quit (plugin "byebye")

if(options.soundValue="veille"){ options.phrase="Goodby"; }

That's all Folks! :)

NOTE : Take care about current tts. If Sarah is currently speaking (because of the "If" plugin), she cannot speak (tts of the "then" plugin) during the same time. Tweak : Use SARAH.shutUp() in your code to stop SARAH for speaking.

"Filtres" rule

You can execute a rule before or after each plugin execution. That's exactly the same that the "Modules" rules system, except you don't have to select a starting module.

Clone this wiki locally