Tools → Scenarios
Real brain of home automation, the scenarios allow to interact with the real world in a way intelligent.
You will find there the list of scenarios of your Jeedom, as well as functionalities to manage them at best :
You will find in this part list of scenarios that you created. They are classified according to their band, possibly defined for each of them. Each scenario is displayed with its name and his parent object. THE grayed out scenarios are the ones that are disabled.
Advice
You can open a scenario by doing :
- Click on one of them.
- Ctrl Clic or Clic Center to open it in a new browser tab.
You have a search engine to filter the display of scenarios. The Escape key cancels the search. To the right of the search field, three buttons found in several places in Jeedom :
Once on the configuration of a scenario, you have a contextual menu with the Right Click on the tabs of the scenario. You can also use a Ctrl Click or Click Center to directly open another scenario in a new browser tab.
After clicking on Add, you must choose the name of your scenario. You are then redirected to the page of its general parameters. Before that, at the top of the page, there are some useful functions to manage this scenario :
Tips
Two tools will also be invaluable to you in setting up scenarios : > - The variables, visible in Tools → Variables > - The expression tester, accessible by Tools → Expression tester
A Ctrl Click on the execute button allows you to directly save, execute and display the scenario log (if the log level is not None).
In the tab General, we find the main parameters of the scenario :
IMPORTANT
The multi launch works per second, that is to say that if you have 2 launches in the same second without the box checked, there will still be 2 launches of the scenario (although it should not). Likewise, during several launches in the same second, some launches may lose the tags. Conclusion it is ABSOLUTELY necessary to avoid multiple launches in the same second.
Advice
Conditions can now be entered in triggered mode. Eg :
#[Garage][Open Garage][Ouverture]# == 1
Attention : you can have a maximum of 28 triggers / programming for a scenario.
Tip mode programmed
Scheduled mode uses syntax Cron. For example, you can run a scenario every 20 minutes with
*/20 * * * *
, or at 5am to sort out a multitude of things for the day with0 5 * * *
. THE ? to the right of a program allows you to set it without being a specialist in Cron syntax. It is also possible to put a launch time in the formGi
(hour without initial zero and minute, example for09h15
=>915
or for23h40
=>2340
). This time can be the result of a calculation (using a command or a tag), for example :#sunset# +10
for a launch 10 minutes after sunset. Note that for a launch 1h30 after sunset you must put#sunset# + 130
. Please note that when using a syntax other than a cron, Jeedom will not be able to give you the dates of the previous or following launches.
This is where you will build your scenario. After creating the scenario, its content is empty, so it will do … nothing. You have to start with Add block, with the button on the right. Once a block has been created, you can add another block or a action.
For more convenience and not having to constantly reorder the blocks in the scenario, adding a block is done after the field in which the mouse cursor is located. For example, if you have ten blocks, and you click in the IF condition of the first block, the added block will be added after this block, at the same level. If no field is active, it will be added at the end of the scenario.
Advice
In conditions and actions, it is better to favor single quotes (‘) instead of double (“).
Advice
A Ctrl Shift Z or Ctrl Shift Y allows you to’Cancel or from redo a modification (addition of action, block…).
Here are the different types of blocks available :
Each block has its options to better handle them :
For the conditions, Jeedom tries to make it possible to write them as much as possible in natural language while remaining flexible.
DO NOT use [] in condition tests, only parentheses () are possible.
Three buttons are available on the right of this type of block to select an item to test :
Note
On blocks of type If / Then / Otherwise, circular arrows to the left of the condition field allow to activate or not the repetition of actions if the evaluation of the condition gives the same result as during the previous evaluation. IF expression != 0 is equivalent to IF expression and IF expression == 0 is equivalent to IF not expression
Advice
There is a list of tags allowing access to variables from the scenario or another, or by the time, the date, a random number,… See below the chapters on commands and tags.
Once the condition is completed, you must use the "add" button on the left to add a new block or a action in the current block.
The Code block allows you to execute php code. It is therefore very powerful but requires a good knowledge of the php language.
cmd::byString($string);
: Returns the corresponding command object.
$string
: Link to the desired command : #[objet][equipment][commande]#
(Ex : #[Appartement][Alarme][Active]#
)cmd::byId($id);
: Returns the corresponding command object.
$id
: Command ID.$cmd->execCmd($options = null);
: Execute the command and return the result.
$options
: Options for the execution of the command (can be specific to the plugin). Basic options (command subtype) :
message
: $option = array('title' => 'titre du message , 'message' => 'Mon message');
color
: $option = array('color' => 'couleur en hexadécimal');
slider
: $option = array('slider' => 'valeur voulue de 0 à 100');
log::add('filename','level','message');
filename
: Log file name.level
: [debug], [info], [error], [event].message
: Message to write in the logs.$scenario->getName();
: Returns the name of the current scenario.$scenario->getGroup();
: Returns the scenario group.$scenario->getIsActive();
: Returns the state of the scenario.$scenario->setIsActive($active);
: Allows you to activate or not the scenario.
$active
: 1 active, 0 not active.$scenario->running();
: Used to find out if the scenario is running or not (true / false).$scenario->save();
: Save changes.$scenario->setData($key, $value);
: Save a data (variable).
$key
: value key (int or string).$value
: value to store (int
, string
, array
Or object
).$scenario->getData($key);
: Get data (variable).
$key => 1
: value key (int or string).$scenario->removeData($key);
: Delete data.$scenario->setLog($message);
: Write a message in the script log.$scenario->persistLog();
: Force the writing of the log (otherwise it is written only at the end of the scenario). Be careful, this can slow the scenario down a bit.Advice
Addition of a search function in the Code block : To research : Ctrl + F then Enter, Next result : Ctrl + G, Previous result : Ctrl+Shift+G
Scenarios : Little codes with friends
Comment block acts differently when it is hidden. Its buttons on the left disappear as well as the title of the block, and reappear on hover. Similarly, the first line of the comment is displayed in bold type. This allows this block to be used as a purely visual separation within the scenario.
Actions added to blocks have several options :
Advice
Depending on the command selected, different additional fields may be displayed.
There are specific triggers (other than those provided by commands) :
#start#
: Triggered at (re) start of Jeedom.#begin_backup#
: Event sent at the start of a backup.#end_backup#
: Event sent at the end of a backup.#begin_update#
: Event sent at the start of an update.#end_update#
: Event sent at the end of an update.#begin_restore#
: Event sent at the start of a restoration.#end_restore#
: Event sent at the end of a restoration.#user_connect#
: User login#variable(nom_variable)#
: Changing the value of the variable name_name.#genericType (GENERIC, #[Object]#)#
: Change of a Generic GENERIC type info command, in the Object object.#new_eqLogic#
: Event sent when creating new equipment, you have in the tags id (id of the equipment created), name (name of the equipment created) and eqType (type/plugin of the equipment created)You can also trigger a scenario using the HTTP API described here.
You can use any of the following symbols for comparisons under conditions :
==
: Equal to.>
: Strictly greater than.>=
: Greater than or equal to.<
: Strictly less than.<=
: Less than or equal to.!=
: Different from, is not equal to.matches
: Contains. Ex : [Salle de bain][Hydrometrie][etat] matches "/humide/"
.not(… matches …)
: Does not contain. Ex : not([Salle de bain][Hydrometrie][etat] matches "/humide/")
.You can combine any comparison with the following operators :
Whether you are combining comparisons on different equipment or on the same one, it is always necessary to indicate the equipment.
[Salle de bain][Hydrometrie][température] >= 18 && [Salle de bain][Hydrometrie][température] <= 22
&&
: And. Attention, the use of : ET
/ et
/ AND
/ and
is not recommended, in some cases it may work but with some php functions it will not work.||
: Or. Attention, the use of : OU
/ ou
/ OR
/ or
is not recommended, in some cases it may work but with some php functions it will not work.xor
: or exclusive. Attention, the use of : XOR
/ ^
is not recommended, in some cases it may work but with some php functions it will not work.A tag is replaced during the execution of the scenario by its value. You can use the following tags :
Advice
To have the leading zeros displayed, use the Date () function. See here.
#seconde#
: Current second (without leading zeros, ex : 6 for 08:07:06).#hour#
: Current time in 24h format (without leading zeros). Ex : 8 for 08:07:06 or 17 for 17:15.#hour12#
: Current time in 12-hour format (without leading zeros). Ex : 8 for 08:07:06.#minute#
: Current minute (without leading zeros). Ex : 7 for 08:07:06.#day#
: Current day (without leading zeros). Ex : 6 for 06/07/2017.#month#
: Current month (without leading zeros). Ex : 7 for 06/07/2017.#year#
: Current year.#time#
: Current hour and minute. Ex : 1715 for 5.15 p.m.#timestamp#
: Number of seconds since January 1, 1970.#date#
: Day and month. Attention, the first number is the month. Ex : 1215 for December 15.#week#
: Week number.#sday#
: Name of day of week. Ex : SATURDAY.#nday#
: Day number from 0 (Sunday) to 6 (Saturday).#smonth#
: Name of the month. Ex : January.#IP#
: Jeedom's internal IP.#hostname#
: Jeedom machine name.#jeedomName#
: Name of Jeedom.#trigger#
: Maybe :
api
if the launch was triggered by the API,TYPEcmd
if the launch was triggered by a command, with TYPE replaced the plugin id (ex virtualCmd),schedule
if it was started by programming,user
if it was started manually,start
for a launch at startup of Jeedom.#trigger_id#
: If it is a command which triggered the scenario then this tag has the value of the id of the command which triggered it. Example : #trigger_id# == 19
#trigger_name#
: If it is a command which triggered the scenario then this tag has the value of the name of the command (in the form [object][equipment][command]). Example : #trigger_name# == '[cuisine][lumiere][etat]'
#trigger_value#
: If it is a command which triggered the scenario then this tag has the value of the command which triggered the scenario. Tip if you want the current value of the command which triggered the scenario (and not its value at triggering) you can use : ##trigger_id##
(double #)#latitude#
: Allows you to retrieve the latitude information put in the jeedom configuration#longitude#
: Allows you to retrieve the longitude information put in the jeedom configuration#altitude#
: Allows you to retrieve the altitude information put in the jeedom configuration#sunrise#
: Allows you to retrieve the sunrise time provided that the latitude and longitude are entered in the jeedom configuration#sunset#
: Allows you to retrieve the sunset time provided that the latitude and longitude are entered in the jeedom configurationYou also have the following additional tags if your scenario was triggered by an interaction :
IMPORTANT
When a scenario is triggered by an interaction, it is necessarily executed in fast mode. So in the interaction thread and not in a separate thread.
Several functions are available for the equipment :
average(commande,période)
& averageBetween(commande,start,end)
: Give the average of the commandover the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
averageTemporal(commande,période)
& averageTemporalBetween(commande,start,end)
: Give the average of the values of the order weighted by their duration of existence over the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
min(commande,période)
& minBetween(commande,start,end)
: Give the minimum command over the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
max(commande,période)
& maxBetween(commande,start,end)
: Give the maximum of the commandover the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
duration(commande, valeur, période)
& durationbetween(commande,valeur,start,end)
: Give the duration in minutes during which the equipment had the chosen value over the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
statistics(commande,calcul,période)
& statisticsBetween(commande,calcul,start,end)
: Give the result of different statistical calculations (sum, count, std, variance, avg, min, max) over the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
tendance(commande,période,seuil)
: Gives the trend of the command over the period (period=[month, day, hour, min] or PHP expression).
stateDuration(commande)
: Gives the duration in seconds since the last change in value.
-1 : No history exists or value does not exist in history.
-2 : The command is not historized.
lastChangeStateDuration(commande,valeur)
: Gives the duration in seconds since the last change of state to the value passed in parameter.
-1 : No history exists or value does not exist in history.
-2 The command is not historized
lastStateDuration(commande,valeur)
: Gives the duration in seconds during which the equipment has last had the chosen value.
-1 : No history exists or value does not exist in history.
-2 : The command is not historized.
age(commande)
: Gives the age in seconds of the value of the command (collecDate
)
-1 : The command does not exist or it is not of type info.
stateChanges(commande,[valeur], période)
& stateChangesBetween(commande, [valeur], start, end)
: Give the number of changes of state (towards a certain value if indicated, or if not indicated compared to its current value) over the period (period=[month, day, hour, min] or PHP expression) or between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
lastBetween(commande,start,end)
: Gives the last value recorded for the device between the 2 requested terminals (in the form Y-m-d H:i:s
Or PHP expression).
variable(mavariable,valeur par défaut)
: Retrieves the value of a variable or the desired value by default.
genericType (GENERIC, #[Object]#)
: Retrieves the sum of the GENERIC Generic Type information in the Object object.
scenario(scenario)
: Returns the status of the scenario.
1 : In progress,
0 : Stopped,
-1 : Disabled,
-2 : The scenario does not exist,
-3 : State is not consistent.
To have the "human" name of the scenario, you can use the dedicated button to the right of the scenario search.
lastScenarioExecution(scenario)
: Gives the duration in seconds since the last launch of the scenario.
0 : The scenario does not exist
collectDate(cmd,[format])
: Returns the date of the last data collection for the command placed as a parameter, the 2nd optional parameter is used to specify the return format (details here).
-1 : The command could not be found,
-2 : The command is not of type info.
valueDate(cmd,[format])
: Returns the date of the last known value for the command placed as a parameter, the 2nd optional parameter is used to specify the return format (details here).
-1 : The command could not be found,
-2 : The command is not of type info.
eqEnable(equipement)
: Returns the status of the equipment.
-2 : The equipment cannot be found,
1 : Equipment is active,
0 : The equipment is inactive.
value(cmd)
: Returns the value of an order if it is not automatically given by Jeedom (case when storing the name of the order in a variable)
tag(montag,[defaut])
: Used to retrieve the value of a tag or the default value if it does not exist.
name(type,commande)
: Used to retrieve the name of the command, equipment or object. Kind : cmd, eqLogic or object.
lastCommunication(equipment,[format])
: Returns the date of the last information feedback for the equipment given in parameter, the 2nd optional parameter is used to specify the return format (details here). A return of -1 means that the equipment cannot be found. The date of last information is calculated in relation to the information type order and their date of collection.
color_gradient(couleur_debut,couleur_fin,valuer_min,valeur_max,valeur)
: Returns a color calculated relative to a value in the interval color_start / color_end. The value must be between min_value and max_value.
The periods and intervals of these functions can also be used with PHP expressions For example :
Now
: NOW.Today
: 00:00 today (allows for example to obtain results for the day if between Today
And Now
).Last Monday
: last Monday at 00:00.5 days ago
: 5 days ago.Yesterday noon
: yesterday afternoon.Here are practical examples to understand the values returned by these different functions :
Socket with values : | 000 (for 10 minutes) 11 (for 1 hour) 000 (for 10 minutes) |
---|---|
average(prise,période) |
Returns the average of 0 and 1 (can |
be influenced by polling) | |
averageBetween(#[Salle de bain][Hydrometrie][Humidité]#,2015-01-01 00:00:00,2015-01-15 00:00:00) |
Returns the average of the command between January 1, 2015 and January 15, 2015 |
min(prise,période) |
Returns 0 : the plug was extinguished during the period |
minBetween(#[Salle de bain][Hydrometrie][Humidité]#,2015-01-01 00:00:00,2015-01-15 00:00:00) |
Returns the minimum command between January 1, 2015 and January 15, 2015 |
max(prise,période) |
Returns 1 : the plug was well lit in the period |
maxBetween(#[Salle de bain][Hydrometrie][Humidité]#,2015-01-01 00:00:00,2015-01-15 00:00:00) |
Returns the maximum of the command between January 1, 2015 and January 15, 2015 |
duration(prise,1,période) |
Returns 60 : the plug was on (at 1) for 60 minutes in the period |
durationBetween(#[Salon][Prise][Etat]#,0,Last Monday,Now) |
Returns the duration in minutes during which the socket was off since last Monday. |
statistics(prise,count,période) |
Returns 8 : there were 8 escalations in the period |
tendance(prise,période,0.1) |
Returns -1 : downward trend |
stateDuration(prise) |
Returns 600 : the plug has been in its current state for 600 seconds (10 minutes) |
lastChangeStateDuration(prise,0) |
Returns 600 : the socket went out (change to 0) for the last time 600 seconds ago (10 minutes) |
lastChangeStateDuration(prise,1) |
Returns 4200 : the socket turned on (switch to 1) for the last time 4200 seconds ago (1h10) |
lastStateDuration(prise,0) |
Returns 600 : the socket has been off for 600 seconds (10 minutes) |
lastStateDuration(prise,1) |
Returns 3600 : the socket was last switched on for 3600 seconds (1h) |
stateChanges(prise,période) |
Returns 3 : the socket has changed state 3 times during the period (if the info command is of binary type) |
stateChanges(prise,0,période) |
Returns 2 : the socket has extinguished (going to 0) twice during the period |
stateChanges(prise,1,période) |
Returns 1 : the plug is lit (change to 1) once during the period |
lastBetween(#[Salle de bain][Hydrometrie][Température]#,Yesterday,Today) |
Returns the last temperature recorded yesterday. |
variable(plop,10) |
Returns the value of the variable plop or 10 if it is empty or does not exist |
scenario(#[Salle de bain][Lumière][Auto]#) |
Returns 1 in progress, 0 if stopped and -1 if deactivated, -2 if the scenario does not exist and -3 if the state is not consistent |
lastScenarioExecution(#[Salle de bain][Lumière][Auto]#) |
Returns 300 if the scenario was started for the last time 5 min ago |
collectDate(#[Salle de bain][Hydrometrie][Humidité]#) |
Returns 2021-02-14 17:50:12 |
valueDate(#[Salle de bain][Hydrometrie][Humidité]#) |
Returns 2021-02-14 17:45:12 |
eqEnable(#[Aucun][Basilique]#) |
Returns -2 if the equipment is not found, 1 if the equipment is active and 0 if it is inactive |
tag(montag,toto) |
Returns the value of “montag” if it exists otherwise returns the value “toto” |
name(eqLogic,#[Salle de bain][Hydrometrie][Humidité]#) |
Returns Hydrometry |
A generic function toolbox can also be used to perform conversions or calculations :
rand(1,10)
: Give a random number from 1 to 10.randText(texte1;texte2;texte…..)
: Allows you to return one of the texts randomly (separate the texts by one; ). There is no limit in the number of texts.randomColor(min,max)
: Gives a random color between 2 bounds (0 => red, 50 => green, 100 => blue).trigger(commande)
: Enables you to find out the trigger for the scenario or to know whether it is the command passed as a parameter that triggered the scenario. => Deprecated it is better to use the tag #trigger#triggerValue()
: Used to find out the value of the scenario trigger. => Deprecated it is better to use the tag #triggerValue#round(valeur,[decimal])
: Rounds above, [decimal] number of decimal places after the decimal point.odd(valeur)
: Lets you know if a number is odd or not. Returns 1 if odd 0 otherwise.median(commande1,commande2….commandeN)
: Returns the median of the values.avg(commande1,commande2….commandeN)
: Returns the average of the values.time_op(time,value)
: Allows you to perform operations on time, with time = time (ex : 1530) and value = value to add or subtract in minutes.time_between(time,start,end)
: Used to test if a time is between two values with time=temps
(Ex : 1530), start=temps
, end=temps
. Start and end values can be straddling midnight.time_diff(date1,date2[,format, round])
: Used to find out the difference between two dates (the dates must be in the format YYYY / MM / DD HH:MM:SS). By default, the method returns the difference in day (s). You can ask it in seconds (s), minutes (m), hours (h). Example in seconds time_diff(2019-02-02 14:55:00,2019-02-25 14:55:00,s)
. The difference is returned in absolute, unless you specify f
(sf
, mf
, hf
, df
). You can also use dhms
who will not return example 7j 2h 5min 46s
. The optional round parameter rounds to x decimal places (2 by default). Ex: time_diff(2020-02-21 20:55:28,2020-02-28 23:01:14,df, 4)
.formatTime(time)
: Formats the return of a chain #time#
.floor(time/60)
: Convert seconds to minutes, or minutes to hours (floor(time/3600)
for seconds to hours).convertDuration(secondes)
: Converts seconds to d / h / min / s.And practical examples :
Example of function | Returned result |
---|---|
randText(il fait #[salon][oeil][température]#;La température est de #[salon][oeil][température]#;Actuellement on a #[salon][oeil][température]#) |
the function will return one of these texts randomly at each execution. |
randomColor(40,60) |
Returns a random color close to green. |
round(#[Salle de bain][Hydrometrie][Humidité]# / 10) |
Returns 9 if the humidity percentage and 85 |
odd(3) |
Returns 1 |
median(15,25,20) |
Returns 20 |
avg(10,15,18) |
Returns 14.3 |
time_op(#time#, -90) |
if it is 4:50 p.m., return : 1 650 - 1 130 = 1520 |
formatTime(1650) |
Returns 4:50 p.m |
floor(130/60) |
Returns 2 (minutes if 130s, or hours if 130m) |
convertDuration(3600) |
Returns 1h 0min 0s |
convertDuration(duration(#[Chauffage][Module chaudière][Etat]#,1, first day of this month)*60) |
Returns the ignition time in Days / Hours / minutes of the time of transition to state 1 of the module since the 1st day of the month |
sun(elevation)
: Gives in ° the elevation of the sun (be careful, you must have entered your geographical coordinates in the configuration of jeedom)sun(azimuth)
: Gives in ° the azimuth of the sun (be careful, you must have entered your geographical coordinates in the configuration of jeedom)In addition to home automation commands, you have access to the following actions :
This functionality allows you to transform a scenario into a template to, for example, apply it to another Jeedom.
By clicking on the button Template at the top of the page, you open the template management window.
From there, you have the possibility :
By clicking on a template, you can :
Below, you have the part to apply your template to the current scenario.
Given that from one Jeedom to another or from one installation to another, the commands can be different, Jeedom asks you for the correspondence of the commands between those present during the creation of the template and those present at home. You just have to fill in the correspondence of the commands then to apply.
IMPORTANT
Adding PHP function is reserved for advanced users. The slightest error can be fatal for your Jeedom.
Go to the Jeedom configuration, then OS / DB and launch the file editor.
Go to the data folder then php and click on the user.function.class.php file.
It is in this class that you can add your functions, there you will find an example of a basic function.
IMPORTANT
If you have a concern, you can always revert to the original file by copying the contents of
user.function.class.sample.php
Inuser.function.class.php