Module development + logging

I am trying to develop an arbitrary module that, among others, creates various variables during creation. Ideally, these variables should be logged as well.

This can be set using the AC_SetLoggingStatus, but this function returns an error in the example below. The $this->GetIDForIdent(‚consumptionT1‘) returns an object ID, which indicates it exists, but AC_SetLoggingStatus returns an error stating that the object does not exist. I can imagine that this happens when this function is called in the Create() part of the module, but I do not expect this to happen in the ApplyChanges() part.

What would be the proper way of creating a variable and setting variable properties such as logging?


<?
	
	class P1SmartMeter extends IPSModule
	{
		
		public function Create()
		{
			//Never delete this line!
			parent::Create();
			
			// Requires a Serialport I/O as parent.
			$this->RequireParent("{6DC3D946-0D31-450F-A8C6-C42DB8D7D4F1}");	
	
			// Set variables used for settings.
			$this->RegisterPropertyInteger("DaysToKeep", "10");
				
			$this->RegisterVariableFloat("consumptionT1", "Electricity consumption low", "Electricity", 10);
			
			// Set timer for automatic data removal for historic data
			$this->RegisterTimer("DataRemoval", 0, 'P1_PurgeOldData');
		}
	
		public function ApplyChanges()
		{
			//Never delete this line!
			parent::ApplyChanges();
			
			$this->SetTimerInterval("DataRemoval", $this->ReadPropertyInteger("DaysToKeep")*24*60*60*1000);
			
			// Set variables for smart meter data
			// Get ObjectID for first archive
			$archives = IPS_GetInstanceListByModuleID("{43192F0B-135B-4CE7-A0A7-1475603F3060}");
 
			AC_SetLoggingStatus($this->GetIDForIdent('consumptionT1'), $archives[0], true);
	
			
		
		}
		


	}
?>

The order of arguments is wrong. The Archive ID first, the variable ID second.

Please note, that the decision if a variable should be logged should be made by the user, especially if you intend to publish your module. It’s fine to provide a shortcut, but it should be obvious to the user that the newly created variables are logged. This could be realized by an according toggle box or similar.