Hello,
here is description of stored data from home gas comsumption meter (service SensorFor).
And I don´t know how can be possible implement it to Home Assistant to Energie panel.
Thank you in advance for any help/recommendation.
API (Application Programming Interface)
The API is mainly taught for remote communication between the application itself and the target device in order to transfer the required data. The entire API is made up of several powerful scripts on the server side, some of which are directly accessible from the Internet at www.sensorfor.com/cloud, allowing the user application to communicate with the device. The content of the following chapters will therefore be mainly a description of these scripts.
Download dat - m2m_data_get.php
The m2m_data_get.php script is used for downloading data to the application itself, which has several parameters to determine the specific request. The “DEVID” parameter is a unique identifier of the device from which we want to download data. It can be found externally on each device or in the corresponding user account of the SensorFor Cloud server in which the device is registered. The “LINES” parameter specifies the number of lines or records we want to download in one script run (in one data packet). One such record is equivalent to the data packet of the target module and is always described in the datasheet of the specific module. The maximum number of records corresponds to the maximum number of samples in the data visualization (as of SensorFor Cloud server version 1.037, this is 240 samples). The “ZOOM” parameter allows you to change the overall range and resolution of the timeline. The minimum value is 1 for the highest resolution and smallest range, the maximum value is 20 for the smallest resolution and largest range. The “ZOOM” parameter corresponds to the time ranges from the data visualization.
General rule m2m_data_get.php?id=00 “DEVID”&ln=“LINES”&zm=“ZOOM”
Example for device with DEVID = 00001234, number of rows = 2, range/resolution = 1
www.sensorfor.com/cloud/m2m_data_get.php?id=0000001234&ln=2&zm=1
Example of UNencrypted output of m2m_data_get.php script
Sample encrypted output of the m2m_data_get.php script
Error messages
In addition to data records, the script output can be single-line error messages that have an unchangeable data format. For a complete implementation of the interface, it is recommended that the application be able to handle them. A complete list of these is as follows.
“Device does not exist.” - the only message that is always unencrypted (no device, no key)
“API is not enabled.” - API interface is disabled (default state)
“Wrong number of lines.” - number of requested record lines out of range
“Wrong data zoom.” - requested timeline setting out of range
“File does not exist.” - data record file does not exist
“There is no data.” - no records exist in the file
Data decryption
If you are running the API securely, i.e. encrypted, it is necessary to decrypt the script output directly in your application. One possible way of decryption is shown by the myDecrypt function, which uses the PHP library OpenSSL (PHP: OpenSSL - Manual). The $input variable is the output of the script (encrypted data), the $key variable is the encryption key of the device and finally the $output variable is the decrypted data. To test the correct implementation of the decryption function, it is possible to switch to the unencrypted API.
API key length is 32 characters
//******************************************************************
function myDecrypt($input, $key)
{
$c = base64_decode($input);
$ivlen = openssl_cipher_iv_length($input_par="AES-128-CBC");
$iv = substr($c, 0, $ivlen);
$hmac = substr($c, $ivlen, $sha2len=32);
$input_raw = substr($c, $ivlen+$sha2len);
$output = openssl_decrypt(
$input_raw, $input_par, $key, $options=OPENSSL_RAW_DATA, $iv);
return $output;
}
//******************************************************************