Script plugin

Plugin allowing to execute scripts (shell, php, ruby…), http requests, to retrieve information in XML or JSON.

Plugin configuration

The configuration is very simple, after downloading the plugin, you just need to activate it and that’s it.

configuration

The only option is where jeedom puts the scripts by default, it is advised not to touch them.

Equipment configuration

The configuration of Script equipment is accessible from the plugin / Programming menu

This is what the Script plugin page looks like (here already with equipment) :

liste des équipements

Here is the list of your Scripts. Once you click on a piece of equipment you get :

équipement

Here you find all the configuration of your equipment :

commandes Here you find the list of orders :

Important

Special characters should be avoided in the script path or in its parameters as much as possible. The allowed characters being : numbers, letters (upper or lower case)

exemple

Used to call a url or retrieve the return of a URL.

The HTML choice

script HTML

Allows you to pass a web page (HTML file) to retrieve a value above. The syntax is the same as for jquery.

The option field has a “HTML file URL” field” : this field therefore contains the link to the machine hosting the HTML file in question.

The XML choice

script XML

Allows you to recover xml and specifically look for a value in it.

The option field has a “URL of the XML file” field” : this field therefore contains the link to the machine hosting the XML file in question.

Important

Only values can be retrieved, attributes cannot be retrieved.

The JSON choice

script JSON

Allows to recover json and to specifically look for a value in it.

The option field has a “JSON file URL” field” : this field therefore contains the link to the machine hosting the JSON file in question.

HTTP example : Piloting a Vera

The example is based on a Vera and consists of driving a dimmable bulb. I’m not going to dwell on how to control a Vera by http request, the TLD forum is full of answers. In addition, the example corresponds to my type of material and will have to be adapted to yours.

Tip

A method for those who grope for writing http requests, first validate the syntax in your browser and only then go to the configuration under Jeedom. When an Action script does not work, switching to the Info / Other script allows you to see the error returned.

Let's go :

Explanations :

''` http://<IP_VERA>:3480/data_request?id=lu_action&output_format=json&DeviceNum=12&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=100 ‘’`

Tip

the “100” at the end of the request corresponds to the percentage of power to be assigned so putting “0” at the end of the request corresponds to switching off the bulb.

The “test” button allows you to test your order !

You can therefore multiply orders in the same equipment, for example by placing an order at 60% for dim light, creating a third at 30% for night trips to be combined in a scenario, etc

It is also possible to create a slider type command by putting the tag #slider# in the request :

''` http://<IP_VERA>:3480/data_request?id=lu_action&output_format=json&DeviceNum=12&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=#slider# ‘’`

Tip

If your order is of message type you can use the tags #message# and #title#, ditto for a color order with the tag #color#, or slider type with #slider# or list with #select#

HTTP example : Send notification to XBMC

Goal : Send a notification to XBMC when opening a front door.

''` http://IP_DE_XBMC:8080/jsonrpc?request={ %22jsonrpc%22:%222.0%22,%22method%22:%22GUI.ShowNotification%22,%22params%22:{ %22title%22:%22Mouvement% 20Detecté%22,%22message%22:%22Porte% 20Entrée%22},%22id%22:1} ‘’`

It's up to you to test this in a scenario for example !

XBMC API here (only the fields marked “required” are mandatory)

Goal : Send a notification to XBMC when the temperature drops below a certain threshold

Take the example above :

Test on a scenario \ [OUTSIDE ] \ [OUTSIDE ] \ [TEMPERATURE ] < 15 par exemple

Action : Launch the script, via virtual equipment, linked to your script !

SCRIPT example

The nicest but not the easiest to explain.

Prerequisites : know how to develop a script in php, python, perl or ruby.

Important

The extension of your script must absolutely match its type. Indeed Jeedom is based on the extension of the script for the executable to launch

If your file name does not contain :

  • .php .py .pl .rb

The script plugin will launch a shell which will execute it based on the directive of the 1st line (shebang ). Example :

'' #!/ bin / csh -f #!/ bin / ksh #!/ usr / bin / env python3 #!/ usr / bin / env php #!/ usr / bin / env node Etc. ... ‘’

The Raspberry temperature monitoring script will serve as an example for using the script type : Script

After downloading the script, the “Browse” button allows you to select the temp_rasp.php file.

Out of curiosity, you can go and see the contents of the file by pressing the “Edit” button, you should get the following code :

This is a php script that can be reused outside Jeedom !

''` <?php $temp = shell_exec("cat /sys/class/thermal/thermal_zone0/temp"); $temp = $temp / 1000; $temp = round($temp,1); echo $temp; ?> ‘’`

NOTE : concretely, it is the php “echo” function which will give the value to Jeedom

The settings

Get Jeedom’s info to use it in a script. Recovery depends on the type of script used :

Recommendation to test the parameters in the php script :

''` if (isset($argv)) { foreach ($argv as $arg) { $argList = explode('=', $arg); if (isset($argList[0]) && isset($argList[1])) { $_GET[$argList[0]] = $argList[1]; } } } ‘’`

Simple XML example

Here is the format of the standard XML :

`` ‘’`

1 toto

`` ‘’`

If you want the value of led0 in query you put led0. Si vous voulez la valeur de la led1 qui est le fils de leds vous mettez leds > led1.

Notez que l’élément racine <root> n’est pas à préciser dans le champ Request.

Complex XML example

`` ‘’`

1 toto tata

`` ‘’`

The syntax is :

leds > 1 > led1 qui donne en réponse tata, 1 étant le numéro de rang du tableau !

More complex XML example

`` ‘’`

Tresa - Ponte Tresa, Rocchetta 01.05.2017 18:50 268.56 268.51 0.051 268.52 268.56 268.50 Inn - Tarasp 01.05.2017 18:50 4.85 7.98 -3.130 6.15 7.98 4.85 Doubs - Combe des Sarrasins 01.05.2017 18:00 500.65 500.65 0.000 500.65 500.65 500.64

`` ‘’`

To retrieve information from the Wert field of the 1st block:

MesPar>0>Wert>0 qui retourne donc "268.56 "

To return the next element in the Wert “structure”, you just have to indicate the order number in the structure. Ce qui donne pour l’élément ‘<Wert Typ=”delta24”>0.051</Wert>’ le code suivant :

MesPar>1>Wert>2

To move to the next “MyPar” block, you must therefore change the index accordingly : the 1 by 2, for example.

Be careful : If the order changes in the XML file, the request no longer works. It will be necessary to readjust the request according to the returned order.

JSON example

Like the XML type, it is possible to read information from a JSON return.

To explain, I am going to base myself on JSON information with the Sickbeard application (bouh… cpasbien) but here only the technique is prime, not the tool !

Access to this file is possible using the following URL :

http://<IP_DELAMACHINEQUIEBERGESICKBEARD>:8083/api/XXXX/?cmd=history&limit=3

NOTE : XXXX is the API key number specific to each SICKBEARD.

First of all, before launching into the configuration of the JSON script plugin, it is a question of correctly identifying the infos to recover., because here we are going to integrate a notion of array in the returns.

Validate the display of information from your browser (test in Chrome).

Example of return :

''` { "data": [ { "date": "2014-09-10 01:37", "episode": 4, "provider": "RNT", "quality": "SD TV", "resource": "XXX", "resource_path": "XXXX", "season": 2, "show_name": "Totovaalaplage S2E4", "status": "Downloaded", "tvdbid": XXXXX }, { "date": "2014-09-10 01:36", "episode": 3, "provider": "RNT", "quality": "SD TV", "resource": "XXXX", "resource_path": "XXX", "season": 2, "show_name": "Totovaalaplage S2E3", "status": "Downloaded", "tvdbid": XXXXX }, { "date": "2014-09-10 01:21", "episode": 1, "provider": "Cpasbien", "quality": "SD TV", "resource": "XXXX", "resource_path": "XXXX", "season": 1, ICI --> "show_name": "Totovaplusauski mais Totovaalaplage S1E1", "status": "Snatched", "tvdbid": XXXX } ], "message": "", "result": "success" } ‘’`

In the hypothesis where we would like to return the show_name of the 3rd element in php (marked HERE), we would have to do : data> 2> show_name, the return array index starting at Zero.

In this example, the “Test” button will return “Totovaplusauski but Totovaalaplage S1E1”.

Clarifications :

Note the syntax of the Query command, it is of type element0> array index> element1

Disadvantages :

HTML example

Here we will try to retrieve the last FML.

First you need to configure the url :

http://www.viedemerde.fr

Then you have to find the “path” of the last FML. To do this, go to the site then right click on the desired item then inspect the item, you get :

HTML example 1

This is the most complex part and requires a little analysis. Here my text is in an “a” tag which is in a p type element which is a class div “post article”. So I have to select the first div element of class “post” and “article” then the first element p and I get everything in the “a” tags it contains. So I have : “div.post.article:first p:first a”.

So we get :

HTML example VDM

For an update in real time, it is possible to put an update cron.

Tip

When installing an update cron, Jeedom will automatically check the Event box, this is completely normal.

Here then you can imagine a scenario which sends you by SMS the last FML.

Nous utilisons des cookies pour vous garantir la meilleure expérience sur notre site web. Si vous continuez à utiliser ce site, nous supposerons que vous en êtes satisfait.