Documentation > nControl > API Reference
Battery Power Tile
nControl™ 2021.0
Battery power tiles allow you to display the remaining battery power.
Introduction
The battery power tile shows the remaining power of the corresponding battery pack. It also allows you to execute operations based on the remaining battery power.
Event Scripts
Battery power tiles support the following event scripts:
  • Activate tile event: is executed when the tile is activated by switching to simulation of operational mode. This event should be used to initialize the tile.
  • Deactivate tile event: is executed when the tile is deactivated by switching to design of configuration mode.
  • Update event: is executed when the battery power tile receives an update of the remaining power level from battery pack. In simulation mode, the update event can be triggered by clicking on the battery power tile.
API Functions
Tile Specific Functions
nBatteryPowerTile.getState()
Returns the battery power status that was received during the last update:
  • nConst.BP_EMPTY
  • nConst.BP_1: 1 bar renaming
  • nConst.BP_2: 2 bars remaining
  • nConst.BP_3: 3 bars remaining
  • nConst.BP_4: 4 bars remaining
  • nConst.BP_5: 5 bars remaining
  • nConst.BP_UNKNOWN: the remaining battery power is not known
nBatteryPowerTile.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nBatteryPowerTile.update()
Sends a request to the controller for an update on the battery power. Returns True if a battery power update was received or False if no update was received. Use the getState() function to get the updated value of the battery power.
Inherited from nTile
nBatteryPowerTile.clearScreen()
Clear all the text in the console window.
nBatteryPowerTile.getTile(label)
Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value.
nBatteryPowerTile.print(text)
Prints text in the console window. If the console window it not yet visible, printing text will make it visible.
nBatteryPowerTile.showConsole(mode)
Shows (mode = True) or hides (mode = False) the console window.
nBatteryPowerTile.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).
nBatteryPowerTile.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.
nBatteryPowerTile.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.
nBatteryPowerTile.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.