Custom Drivers Command and Utility Methods API
Constants
LIGHT
LIGHT
Used for the function field of deviceSet().
AUTOM
AUTOM
Used for the function field of deviceSet().
DIMMER
DIMMER
Used for the function field of deviceSet().
BINARY
BINARY
Used for the function field of deviceSet().
System Functions
dateSet
boolean dateSet(int year, int month, int day, int hour, int minute, int second)
Sets the HSYCO Server operating system’s clock and hardware clock, in the local time zone.
Parameters:
- year: int - the year, greater than 1900
- month: int - the month, between 1-12
- day: int - the day, between 1-31
- hour: int - the hour, between 0-23
- minute: int - the minute, between 0-59
- second: int - the second, between 0-59.
Returns:
- boolean - true if successful, false if not.
getNextSunrise
long getNextSunrise(long now, boolean withoffset)
Computes the time of the next sunrise after the time set in the now parameter.
The sunrise time is returned in milliseconds since midnight, January 1, 1970 UTC.
Parameters:
- now: long - the reference time in milliseconds
- withoffset: boolean - true to take the sunrise offset into account, as defined with the SunriseOffsetMinutes in hsyco.ini, false to ignore the offset and return the actual sunrise time (Based on civil dawn, begins when the geometric center of the sun is 6° below the horizon).
Returns:
- long - the next sunrise time in milliseconds since midnight, January 1, 1970 UTC.
getNextSunset
long getNextSunset(long now, boolean withoffset)
Computes the time of the next sunset after the time set in the now parameter.
The sunset time is returned in milliseconds since midnight, January 1, 1970 UTC.
Parameters:
- now: long - the reference time in milliseconds
- withoffset: boolean - true to take the sunset offset into account, as defined with the SunriseOffsetMinutes in hsyco.ini, false to ignore the offset and return the actual sunrise time (Based on civil dusk, ends when the geometric center of the sun reaches 6° below the horizon).
Returns:
- long - the next sunset time in milliseconds since midnight, January 1, 1970 UTC.
haActiveState
boolean haActiveState()
When HSYCO is installed in a high availability configuration, this method returns true if the system (master or slave) is active, false if it is not active.
If high availability is not configured, the method returns true.
Returns:
- boolean - high availability current state.
haActive
void haActive(boolean active)
Force a master HSYCO server to become inactive, or return to the active state.
This method should be called on the master only, and has no effect on the slave server.
Parameters:
- active: boolean - set to true to force a master to become inactive, or false to return it to the active state after the master was forced to become inactive.
isVerboseLog
boolean isVerboseLog()
Checks if verbose log is enabled.
Returns:
- boolean - returns true when verbose log is enabled.
sleep
void sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
Parameters:
- millis: long - the length of time to sleep in milliseconds.
varGet
String varGet(String name)
Returns the value of a program variable, or null if no variable with the given name has been defined.
Program variables can be set using varSet() in user.java or in the EVENTS programming environment.
To access a variable used in EVENTS, the name used in varGet() should start with the $ character.
Variables names ending with ! are considered persistent and their values are preserved when HSYCO restarts; normal variables are deleted when HSYCO starts.
Parameters:
- name: String - the variable name. Names are case-insensitive.
Returns:
- String - the current value of the program variable.
varSet
void varSet(String name, String value)
Sets a program variable to the value parameter.
Variables set with varSet() can be read using varGet() and are also available in the EVENTS programming environment, if the variable name starts with $.
If you need to use variables in Java or JavaScript but don’t want these variables to be available in EVENTS, just use names that don’t start with the $ character.
Variables names ending with ! are considered persistent and their values are preserved when HSYCO restarts; normal variables are deleted when HSYCO starts.
Parameters:
- name: String - the variable name. Names are case-insensitive
- value: String - the value to be assigned to the program variable.
Driver Control
init
boolean init(String name)
Must be called once inside the init() callback.
public class Driver extends driverBase {
public boolean init(String name, HashMap<String, String> config) {
super.init(name); // do not remove
return true;
}
}
Parameters:
- name: String - the driver's identifier.
Driver I/O
ioSet
boolean ioSet(String name, String value)
Writes back a command to this driver.
This method should only be used to push back a command to the command queue, to be processed again after all currently pending commands.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
Returns:
- true if the I/O Server command is successfully queued or executed (for synchronous commands), false if the queue is full or command failed for any other reason
ioWrite
void ioWrite(String name, String value)
Writes a new value to a data point.
Events will be triggered only the new value is different from the current one.
Note that, in order to optimise both the driver and HSYCO's overall performance, you should call ioWrite() only when an actual change to a datapoint has happened. Calling ioWrite() when the value has not changed since the previous call will not have any functional effects, as HSYCO checks for changes anyways, but will add some overhead.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
ioWriteNoLog
void ioWriteNoLog(String name, String value)
Writes a new value to a data point.
Events will be triggered only the new value is different from the current one.
The change is not logged.
Note that, in order to optimise both the driver and HSYCO's overall performance, you should call ioWriteNoLog() only when an actual change to a datapoint has happened. Calling ioWriteNoLog() when the value has not changed since the previous call will not have any functional effects, as HSYCO checks for changes anyways, but will add some overhead.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
ioWriteNoEvents
void ioWriteNoEvents(String name, String value)
Writes a new value to a data point.
Events are not triggered.
Note that, in order to optimise both the driver and HSYCO's overall performance, you should call ioWriteNoEvents() only when an actual change to a datapoint has happened. Calling ioWriteNoEvents() when the value has not changed since the previous call will not have any functional effects, as HSYCO checks for changes anyways, but will add some overhead.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
ioWriteNoEventsNoLog
void ioWriteNoEventsNoLog(String name, String value)
Writes a new value to a data point.
Events are not triggered.
The change is not logged.
Note that, in order to optimise both the driver and HSYCO's overall performance, you should call ioWriteNoEventsNoLog() only when an actual change to a datapoint has happened. Calling ioWriteNoEventsNoLog() when the value has not changed since the previous call will not have any functional effects, as HSYCO checks for changes anyways, but will add some overhead.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
ioWriteForced
void ioWriteForced(String name, String value)
Writes a new value to a data point.
Events are always triggered, even if there is no change to the value.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.
ioWriteForcedNoLog
void ioWriteForcedNoLog(String name, String value)
Writes a new value to a data point.
Events are always triggered, even if there is no change to the value.
The change is not logged.
Parameters:
- name: String - the data point name, without the I/O server id prefix
- value: String - the new value.