Documentation > nControl > API Reference
Timer Tile
nControl™ 2021.0
This tile provides a timer that triggers an action when it goes off.

Introduction
The response of the timer when it goes off has to be implemented with trigger event script of the tile.
Each timer also has an integer state variable. The state variable can be used to implement a repetitive timer with a variable interval. For example, a timer with an interval that alternates between 30 and 60 seconds. This can be implemented as follows:
self.nextState(2)
curState = self.getState()
if curState == 1:
   self.setInterval(30)
elif curState == 2:
   self.setInterval(60)
Event Scripts
Timer tiles support the following event scripts:
  • Activate tile event: is executed when the tile is activated by switching to simulation of operational mode.
  • Deactivate tile event: is executed when the tile is deactivated by switching to design of configuration mode.
  • Trigger event: is executed when the timer goes off.
API Functions
Tile Specific Functions
nTimerTile.getSingleShot()
Returns True for a single shot timer and False for a repetitive timer.
nTimerTile.getState()
Returns the current value of the timer's state. The initial state of the timer tile equals 1.
nTimerTile.isRunning()
Returns whether the timer is running or not.
nTimerTile.nextState(maxState)
Switches the timer to the next state; if the timer has reached the last state it will be switched back to the first state. The input variable maxState specifies the number of states of the time.
nTimerTile.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nTimerTile.setInterval()
Defines the countdown time interval of the timer. The time interal is specified in seconds.
nTimerTile.setSingleShot(mode)
Use mode = True to define a single shot timer and mode = False to define a repetitive timer. After it went off and executed the custom action, a repetive timer will automatically reset itself and restart the countdown. A single shot timer will not reset itself and thus executes the custom action only once.
nTimerTile.setState(newState)
Sets the state of the timer to newState.
nTimerTile.start()
Start the timer.
nTimerTile.stop()
Stop the timer.
Inherited from nTile
nTimerTile.clearScreen()
Clear all the text in the console window.
nTimerTile.getTile(label)
Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value.
nTimerTile.print(text)
Prints text in the console window. If the console window it not yet visible, printing text will make it visible.
nTimerTile.showConsole(mode)
Shows (mode = True) or hides (mode = False) the console window.
nTimerTile.sleep(duration)
Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5).
nTimerTile.timestamp()
Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events.
nTimerTile.localVars
Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property.
nTimerTile.globalVars
Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles.