Rev 1 | Blame | Compare with Previous | Last modification | View Log | Download
"""Domoticz passes information to python scripts through global variables and thedomoticz python moduleThe global variables in the script are:* changed_device: the current device that changed (object of Device)* changed_device_name: name of current device (same as changed_device.name)* is_daytime: boolean, true when it is is daytime* is_nighttime: same for the night* sunrise_in_minutes: integer* sunset_in_minutes: integer* user_variables: dictionary from string to valueA Device has a number of attributes and methodsThe attributes are:* id* name* type* sub_type* switch_type* n_value* n_value_string* s_value* last_update_string* last_update: datetime objectThe methods are:* def last_update_was_ago(self, **kwargs):Arguments can be: days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]* def is_on(self):returns True when device is on* def is_off(self):returns True when device is off* def on(self, after=None, reflect=False):turns device on, after is optional and are the number of seconds after whichto turn the device on.If reflect is True, a next call to is_on will return True, while normallydomoticz will first have to go through possible script before turning it ondef off(self, after=None, reflect=False):simular to on()uservariables and uservariables_lastupdate are arrays for all user variables:uservariables['yourvariablename'] = 'Test Value'uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'other useful details are contained in the following global variables:* is_daytime* is_nighttime* sunrise_in_minutes* sunset_in_minutes* (TODO) securityCompare to Lua, instead of filling a commandArray, you change the status of adevice by calling device.on() or device.off()TODO: setting variablesCalling Python's print function will not print to the domoticz console, see below"""import DomoticzEvents as DEDE.Log("Python: Changed: " + DE.changed_device.Describe())if DE.changed_device_name == "Test":if DE.Devices["Test_Target"].n_value_string == "On":DE.Command("Test_Target", "Off")if DE.Devices["Test_Target"].n_value_string == "Off":DE.Command("Test_Target", "On")DE.Log("Python: Number of user_variables: " + str(len(DE.user_variables)))# All user_variables are treated as strings, convert as necessaryfor key, value in DE.user_variables.items():DE.Log("Python: User-variable '{0}' has value: {1}".format(key, value))