Under the Events menu you find functionality to automate things like switching on lights when it becomes dark.
Things are architectured such that an event is executed when it is triggered and (optional) condition(s) are met and resulting in one or more action(s) to be executed.

The list of Events can be accessed through the Events icon in the Main menu bar on the left, using the Events menu (Events --> List Events).

The sub-menus can be accessed through the Events menu or when you have that open, through the Events, Triggers and Actions buttons under the main tab row.


An event is something that links an trigger and (optional) conditions to one or more action(s) to be executed.

You can list the current defined events using the Events button under the main tab row.
You can add an event using Events -> Add Event.

Event Main tab
Event Options tab


An trigger is what starts an event.
For triggers you can think of:

You can list the current defined triggers using the Triggers button under the main tab row or by pressing the drop down arrow in the Create/Edit Event window.

You can add a trigger using Events -> Add Trigger or pressing the Create button when in the Event window.

Time Now triggers

Time Now triggers utilize cron, and entries therefore comply with crontab entries

For a trigger that happens every 5 minutes:

*/5 * * * *

*/5 means the minute count needs to be divisible by 5

For a trigger that occurs every 15 minutes between 06-22 on Monday-Friday use:

*/15 6-22 * * 1-5

You can also specify minute-intervals manually, for example, 6min interval

0,6,12,18,24,30,36,42,48,54 * * * *

Time Now triggers are only checked once a minutes so if you want a trigger that fires 24x7 each minute, use:

* * * * *

You can "or" multiple cron entries using a multi-trigger.

Sunrise and Sunset

The Sunrise and Sunset Time Now triggers are special in the sense that Time Now CronTab string are updated by the Astro module at startup and the begin of every new day.

The triggers having the name "Time is Sunset" and "Time is Sunrise" are the ones that are updated, so if you want to use them, make sure the name is exactly this.

The "41 16 * * *" value you see above is updated the begin of every new day, 16:41 is the sun set time in Rotterdam for 2 January.

Variable triggers

With a Variable trigger you can trigger an event when a "global variable" becomes a certain value, for example:

Var_Dark = TRUE

Device Status

This Device Status trigger will fire when a value from a device becomes equal to/larger than/smaller than/not equal to a given Compare Value.

So to get a notification (E-mail, Prowl, Notify My Android, Pushover etc.) when the temperature outside becomes near to the freezing point:

This trigger will fire every time the temperature is measured and the condition is met.

The Compare value does not support only plain values. For the use of more advanced formulas, "Dev_X_Value_Y values" or global variables, use a Device Lastseen trigger in combination with a condition.


Device Lastseen

This trigger will fire whenever (one of the values of) a device is updated.

This is the type of trigger you likely want to use if you want to do something with the values of a device.

To test things you can create the trigger, use it as IF of an event and add a Write Log action that writes the value to the log. Then check the main log to see if the trigger triggers when you want it to trigger.


This trigger type can be used to trigger on a combination ("or") of conditions.

As input to the or you can use "cron entries", global variables and devices values including LastSeen, LastChanged and BatteryStatus.

See also Battery-status under Tricks.


Conditions differ from triggers in the sense that they are never directly triggered. An event must always be first triggered before a condition is checked. If this is a problem, in most cases a trigger based on the same condition can be created or you create a condition that triggers every minute, 24x7, see above.

Conditions are evaluated as Boolean expressions meaning they should return True or False.

You can list the current defined conditions using the Conditions button under the main tab row or by pressing the drop down arrow in the Create/Edit Event window.

You can add a trigger using Events -> Add Condition or pressing the Create button when in the Event window.

Check device value

To check for example if the TV is turned off the power usage of the device need to be changed to a floating point ("CFloat") to check the value correctly:

CFloat(Dev_1_Value2) < 5

The CFloat() or Val() is needed as otherwise the value is interpreted as string meaning for example that "6.4" is higher then "16.4".

Time Range

To create a condition that is only valid within a time-range (06-22)

(Hour(Now()) < 22) AND (Hour(Now()) > 6)

Check if any device is down

For this you want to check if the device "lastseen" was longer than a certain timeout.
To check if device 67 was last seen more than 30 minutes ago:

DateDiff(Dev_67_LastSeen, Now(), gb.Minute) > 30

Device last changed in the last N minutes

To check if a device (84) was changed in the last 30 minutes and it´s current value is anything but "on" (useful for motion detection etc.):

    Hour(Now()) = Hour(Dev_84_LastChanged) AND  Minute(Now()) > Minute(Dev_84_LastChanged) + 30
  ) OR (
    Hour(Now()) > Hour(Dev_84_LastChanged) AND (Minute(Now()) + 60 - Minute(Dev_84_LastChanged)) > 30)
) AND (Dev_84_Value1 <> "On")

Alternatively, and much more concisely, try:

(Now() > Dateadd(Dev_84_LastChanged, gb.minute, 30)) AND (Dev_84_Value1 <> "On")

... and set it so the event doesn't trigger again in the next 30 minutes.

Switching before or after Sunrise/Sunset

Apart from the special Sunrise-and-Sunset you can also use a condition: make a Time-Now trigger that triggers every minute and add a condition that checks:

Var_Sunset = Format(hour(now()),"0#") & ":" & Format(minute(now()),"0#")

Var_Sunset is the Sunset global variable that is updated every day based on your location by the Astro module. Apart from Sunset there is also Sunrise, Sunrise_Twilight and Sunset_Twilight.

If Sunrise/Sunrise_Twilight and Sunset/Sunset_Twilight is not exactly the right time, you can offset things.
By adding (30 in example) minutes to minute(Now()) the event is raised sooner:

Var_Sunset = Format(hour(DateAdd(now(), gb.Minute, 30)),"0#") & ":" & Format(minute(DateAdd(now(), gb.Minute, 30)),"0#")

Or subtract time (15 min), it will be later:

Var_Sunset = Format(hour(DateAdd(now(), gb.Minute, -15)),"0#") & ":" & Format(minute(DateAdd(now(), gb.Minute, -15)),"0#")

Comparing device values

To set Device 15, Value 1 to "Off" when Device 7, Value 1 is greater than Device 18, Value 2 and otherwise "On":

Dev_15_Value1 = IIf(Val(Dev_7_Value1) <= Val(Dev_18_Value2), "On", "Off")


Actions make things happen, from switching a lamp on, sending an email or updating an variable to whatever you can think of.

You can list the current defined actions using the Actions button under the main tab row or by pressing the drop down arrow in the Create/Edit Event window.

You can add an action using Events -> Add Action or pressing the Create button when in the Event window.


For sending notifications you can insert templates inside action text, just like you can use templates in device values. The templates are replaced with their values upon executing.
Current implemented templates:

<%global var%>          - insert globalvar value
<$device id|field$>     - insert value field number 'field' from device with 'device id'

The field can be, 'value1' or just 1,'value2' or 2, 'value3' or 3,'value4' or 4, 'lastseen', 'lastchanged' or 'batterystatus'

See below Write Log action for an example.

Write Log action

This action can be handy to debug things. Just create a script to dump the values that you want to know, see also Events above.

Set device value

Setting a device value can be handy for virtual devices and to "override" other values.

For the value you can use templates.


Only Value1 is set, other values are updated.

The current implementation of DomotiGa is so that only Value1 is really set to the external device (Devices.SetDevice), for the other values the internal value is updated (Devices.ValueUpdate) but no command is send to the external device.

See RE: ArduinIO thread - A generic(ish) arduino IO module fo... for more detail including a code snippet.


The delay action can be used to add a delay between actions


The json action can be used to get or post json to a given url.

When using the get method the flowing json expected to parse and update the device. Also is this format posted to the given url if you are using the post method.

{"values":[{"valuenum":1,"value":18.1},{"valuenum":2, "value": 21.2}, ....]}



Actions are limited to one action only but in the event editor you can add multiple actions to one event.

An alternative approach is to add more commands to an "action script" or macro by doing this:

action1() &
action2() &

This action script/macro can then be called by from an action, set Action Type to Script and select the script.

You can add a script by creating an action with Action Type to Script and then pressing the Editor button right under or by selecting Events -> Edit Macro and pressing the Add button.

You can list and edit scripts/macros by selecting Events -> Edit Macro. If you select a macro, the contents of the macro will be displayed and if you press the Eval button, the macro will be executed and the result displayed.

Script contents

You can get a reasonable complete list of the things a script can consist of by opening the script editor. Open the Macro Editor (Events -> Edit Macro), select a Macro and press the Edit button:

Script testing

You can test your complete script by pressing the "Run" button and check the script result output. However if you want to debug your script you can also make a selection of a part of your script and press the "Run" button and only that portion of the script will be evaluated.

Script example actions

Some typical examples you can use in the script editor are:

If Actions
Be careful using the If(<Cond>, <TrueExpr>, <FalseExpr>) with an "action" in the False or True Expression. When the If-function is used in the script editor it will actually evaluate both the True and False Expression of the If-statement irrespective of the Condition. So you should prevent using any "real actions" in the true/false expressions. As an example, contrary maybe to your initial expectation, the following piece of script will always result in a device 12 being first being turned "on" and then turned "off" as both true and false expression are evaluated:

If(Var_Dark, Devices.SetDevice(12, "On"), Devices.SetDevice(12, "Off")) <== !!! Don't do this !!!

See also the Gambas documentation on this and A "genuine" IF-statement for the Event Script Editor (onl... for an alternative way.


Timer event

While there is (currently) no support for a timer event you can do timed events using the Delay action and alternatively using the Time Now trigger.

Suppose you have a controlled toilet light with switch that can control the light but people forget to put off the light and you want to automatically turn it off after 15 minutes.

The "problem" here is that there seems to be no way to trigger an event after 15 minutes the light was switched on.

One possible work-around is to have a time-now event triggering every 5 five minutes and checking if the light is (still) on and if the TimeNow - LastChanged for the switch is 15 minutes or longer and if so switch of the light. That will work but the drawback is that the time-now event will be triggering every five minutes also when it is not needed.

The better approach is to use a Delay action in the list of actions for a "switch on" event and have an action after the delay switching the light off.

If you also want to cover the situation that somebody goes to the toilet, switches the light off but after 14 minutes the light is switched on again you might want to add a condition to to check the TimeNow - LastChanged for the switch is 15 minutes or longer.


If you want to count pulses or to sum the samples you get from a device value you can use an unused value of the device (for example Value5) and have a formula like:

Val5[New] = Val5[Old] + Val1[New]

Implemented (for the device with id 17) using a script like:

Devices.ValueUpdate(17, 5, Dev_17_Value5 + Dev_17_Value1)

If you trigger this script every valueupdate of Dev_17_Value1, Value5 will give the summed/integrated value of Value1.

Send a "On" command even if the device is already "On"

Create a trigger like this

if [deviceNAME][LastSeen] <> " " 

Create two events for setting your device(s) "On" or "Off"

"On" uses the trigger above and a condition like Dev_XX_Value1="On" (where XX is your device ID that triggers the event)
"Off" uses the trigger above and a condition like Dev_XX_Value1="Off"

Battery status

You can have a script that mails the battery status for all devices using the "Action Script" with "Devices.MailBatteryStatus(["all"|"empty"])" in it which you can find under the script editor -> Actions -> Status:

Updated by: jessekerkhoven, Updated almost 4 years ago
Access count: 59197 since 2014-08-02

Attached Files