abbrechen
Suchergebnisse werden angezeigt für 
Anzeigen  nur  | Stattdessen suchen nach 
Meintest du: 

Some code to receive info from the Viessmann boiler v0.2

Here is some code I have put together in order to receive basic info from an Viessmann boiler. The code represents an improvement from a former post here on the forum and thus it has been highlighted as version 0.2. Only HTML and PHP. it is used.

 

In order to work you will have first to receive the following variables:

$autorizationTOKEN
$installationId
$gatewaySerial
$deviceId

 

For this preliminary steps, documentation is available here:

https://developer.viessmann.com/en/doc/getting-started

and with more details, after you login, here:

https://developer.viessmann.com/en/doc/authentication

 

Also you can take a lock at this post:

https://www.viessmann-community.com/t5/Getting-started-programming-with/To-help-get-started/td-p/181...

 

As soon as the above requirements are fulfilled here is the code:

 

 

<html> 
 <title>Viessmann</title>
 <body>

 
<?php

//Get all boiler features
//$getURL='https://api.viessmann.com/iot/v1/equipment/installations/'.$installationId.'/gateways/'.$gatewaySerial.'/devices/'.$deviceId.'/features';

//Get all boiler features required by the present project
$getURL='https://api.viessmann.com/iot/v1/equipment/installations/'.$installationId.'/gateways/'.$gatewaySerial.'/devices/'.$deviceId.'/features?regex='
		.'heating.burners.0'.'%7C'
		.'heating.burners.0.statistics'.'%7C'
		.'heating.boiler.sensors.temperature.commonSupply'.'%7C'
		.'heating.dhw.temperature.main'.'%7C'
		.'heating.dhw.sensors.temperature.hotWaterStorage'.'%7C'
		.'heating.circuits.0.operating.programs.normal'.'%7C'
		.'heating.circuits.0.sensors.temperature.room';

$headerRequest = array(
		"Content-Type: application/x-www-form-urlencoded",
		"Authorization: Bearer $autorizationTOKEN"
);

  
$cURLConnection = curl_init();
curl_setopt($cURLConnection, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)");
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER,true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headerRequest); 
curl_setopt($cURLConnection, CURLOPT_CONNECTTIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_TIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_URL,$getURL);

$apiResponse = curl_exec($cURLConnection);
$apiErr = curl_error($cURLConnection);

curl_close($cURLConnection);

$jsonResponse = json_decode($apiResponse, true);

 
usort($jsonResponse['data'], function($a,$b){
	return $a["feature"]>$b["feature"];
});

//echo "<br><br><br>";
//print_r($jsonResponse);
//print_r($apiErr);
//echo "<br><br><br>";

$BurnerStatus = $jsonResponse['data']['1']['properties']['active']['value']; // heating.burners.0
echo "BurnerStatus: ".$BurnerStatus."<br>"; 
if ($BurnerStatus == "1") {
		$BurnerStatus = "<span style='vertical-align:middle; '>On</span><img src='viessmann_burner_on.png' alt='burner_on' width='20%' style='vertical-align:middle; '>";
	} else {
		$BurnerStatus = "<span style='vertical-align:middle; '>Off</span><img src='viessmann_burner_off.png' alt='burner_off' width='20%' style='vertical-align:middle; '>";
	}

$BurnerHours = $jsonResponse['data']['2']['properties']['hours']['value']; //heating.burners.0.statistics
echo "BurnerHours: ".$BurnerHours."<br>";
$MaxEnergyConsumption = $BurnerHours*160/1000;
echo "MaxEnergyConsumption (160W/h): ".$EnergyConsumption." kWh<br>";


$BurnerStarts = $jsonResponse['data']['2']['properties']['starts']['value']; //heating.burners.0.statistics
echo "BurnerStarts: ".$BurnerStarts."<br>";


$MeasureUnit = $jsonResponse['data']['0']['properties']['value']['unit']; //heating.boiler.sensors.temperature.commonSupply
if ($MeasureUnit == "celsius") {
		$MU = " &deg;C ";
	} else {
		$MU = " &deg;F ";
	}


$TemperatureCommon = $jsonResponse['data']['0']['properties']['value']['value']; //heating.boiler.sensors.temperature.commonSupply
echo "TemperatureCommon: ".$TemperatureCommon." ".$MU."<br>";

$HotWaterSet = $jsonResponse['data']['6']['properties']['value']['value']; //heating.dhw.temperature.main
$HotWater = $jsonResponse['data']['5']['properties']['value']['value']; //heating.dhw.sensors.temperature.hotWaterStorage
echo "HotWater: ".$HotWaterSet." / ".$HotWater." ".$MU."<br>";

$RadiatorsSet = $jsonResponse['data']['3']['properties']['temperature']['value']; //heating.circuits.0.operating.programs.normal
$TemperatureRoom = $jsonResponse['data']['4']['properties']['value']['value']; //heating.circuits.0.sensors.temperature.room
echo "Radiators: ".$RadiatorsSet ." / ".$TemperatureRoom." ".$MU."<br>";


?>

<div style="position:relative; ">
			<img src="viessmann_map.png" alt="map" style="display:block; margin-left:auto; margin-right:auto; "> 
	<div style="position:absolute; top: 12%; left:52%; font-size:150%; ">
		<?php echo "Boiler<br>".
			"TemperatureCommon: ".number_format($TemperatureCommon,0).$MU."<br>".
			"BurnerHours: ".$BurnerHours."<br>".
			"BurnerStarts: ".$BurnerStarts."<br>".
			"MaxEnergyConsumption (160W/h): ".$MaxEnergyConsumption." kWh";?>
	</div>
	<div style="position:absolute; top: 53%; left:27%; font-size:150%; text-align:right; ">
		<?php echo "Water heating<br>".
			"Set: ".number_format($HotWaterSet,0).$MU."<br>".
			"Current: ".number_format($HotWater,0).$MU."<br>";?>
	</div>
	<div style="position:absolute; top: 53%; left:50%; font-size:150%; ">
		<?php echo "Radiators<br>".
			"Set: ".number_format($RadiatorsSet,0).$MU."<br>".
			"TemperatureRoom: ".number_format($TemperatureRoom,0).$MU."<br>";?>
	</div>
	<div style="position:absolute; top: 37%; left:41%; font-size:120%; ">
		<?php echo $BurnerStatus; ?>
	</div>	
</div>

</body>
 </html>

 

 

Since the boiler I have used does not provide any consumption statistics I have worked something around:

$MaxEnergyConsumption = $BurnerHours*160/1000;

where 160 is the maximum boiler energy consumption as provided by Viessmann in the product manual. If you are not sure you can uncomment the appropriate $getURL to see all the features and data points reported by your boiler.

 

The result is available in the attached screenshot.

Also the used PNGs have been attached.

2021-10-26 09_10_48-Viessmann - Brave.png
viessmann_burner_off.png
viessmann_burner_on.png
viessmann_map.png
9 ANTWORTEN 9

Hi @SorinB ,

 

it would be nice if you can provide some code to get the installationId, gatewaySerial and deviceId as well.

 

Currently I'm stuck at that to get these 3 magic numbers.

 

Cheers

Hi @MrAnderson 

 

Should be quite straight forward: 

Step 1: Authorization request (that is for login)

Step 2: get access token and insert the required code to refresh the token so you will not have to authorize  each time you send a command to the server

Step 3: get installationId

Step 4: get gatewaySerial

Step 5: get deviceId

 

Step 1 and 2 are covered here

https://developer.viessmann.com/en/doc/authentication

Step 3 to 4 are covered here

https://developer.viessmann.com/en/doc/iot/overview

 

Where did you get stack?

Share some code.

 

Regards

 

Hi @SorinB 

I read the documentation but may be I have to get some new glasses because I don't see mistake or the documentation is a bit incomplete at that point.

 

The authorization is working fine and I can request my user profile.

 

 

I created another thread https://www.viessmann-community.com/t5/The-Viessmann-API/Cannot-get-installationId-gatewaySerial-and... where you can see my code a bit nicer than in this answer:

 

<?php

// Initialization
//
$client_id = "client_id"; // API Key
$code_challenge = "code_challenge";
$user = "username"; // The same as used for Vicare
$pwd = "password"; // The same as used for Vicare
$token = "access_token";
$refresh_token = "refresh_token";

/* */
// Code parameters
//
$url = "$authorizeURL?client_id=$client_id&code_challenge=$code_challenge&scope=IoT%20User%20offline_access&redirect_uri=$callback_uri&response_type=code";
$header = array("Content-Type: application/x-www-form-urlencoded");

$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => "$user:$pwd",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
);

// Call Curl Code
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

// Code Extraction
//
$matches = array();
$pattern = '/code=(.*)"/';
if (preg_match_all($pattern, $response, $matches)) {
$code = $matches[1][0];
} else {
exit("Erreur"."\n");
}

// Token Settings
//
$url = "$tokenURL?grant_type=authorization_code&code_verifier=$code_challenge&client_id=$client_id&redirect_uri=$callback_uri&code=$code";
$header = array("Content-Type: application/x-www-form-urlencoded");

$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
);

// Call Curl Token
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

// Token extraction
//
$json = json_decode($response, true);
echo($response);
echo("\n");
$token = $json['access_token'];
/**/

// Read user data
//
$header = array("Authorization: Bearer $token");

$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
);

// Data Curl Call
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

echo($response);
echo("\n");

// get Installations-Id
//

$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false
);

// Data Curl Call
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

echo($response);
echo("\n");

// get Gateway-Id
//

$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
//CURLOPT_RETURNTRANSFER => true,
//CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
);

// Data Curl Call
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

echo($response);
echo("\n");

?>
 
Cheers and thanks
Andreas

Looks confusing at the first view 🙂

Take it step by step. 

Step 1: Authorization request (that is for login)

Have you been successful to pass trough authentication?

https://developer.viessmann.com/en/doc/authentication

 

If the answer is YES and the problem remains only to receive installationId, gatewaySerial and deviceId, then from your posted code you are missing the authorizationTOKEN. Something like this:

 

Your code:

 

$url = "https://api.viessmann.com/iot/v1/equipment/installations/";

$curloptions = array(
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true,
    //CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
);

// Data Curl Call 
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

echo($response);

 

should be:

 

$getURL='https://api.viessmann.com/iot/v1/equipment/installations';

$headerRequest = array(
		"Content-Type: application/x-www-form-urlencoded",
		"Authorization: Bearer $autorizationTOKEN" //put here the name you have used for the AuthorizationTOKEN variable
);

  
$cURLConnection = curl_init();
curl_setopt($cURLConnection, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)");
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER,true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headerRequest); 
curl_setopt($cURLConnection, CURLOPT_CONNECTTIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_TIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_URL,$getURL);

$apiResponse = curl_exec($cURLConnection);
$apiErr = curl_error($cURLConnection);

curl_close($cURLConnection);

$jsonResponse = json_decode($apiResponse, true);

print_r($jsonResponse);
print_r($apiErr);


$installationId = $jsonResponse['data']['0']['id'];
echo "installationId: ".$installationId."<br>";	

 

Hi @SorinB 

may be you can try my code below.

As I said

  • authorization is working fine
  • getting the access token is working fine
  • showing my profile is working fine
  • everything else is not working

 

<?php

// Initialization 
//
$authorizeURL = "https://iam.viessmann.com/idp/v2/authorize";
$tokenURL = "https://iam.viessmann.com/idp/v2/token";
$client_id = "my_client_id"; // Change to your API Key
$code_challenge = "code_challenge"; // Change to your challende ig
$callback_uri = "http://localhost:4200/oauth-callback";
$user = "username"; // Change to your username
$pwd = "password"; // change to your password
$token = "not_used";
$refresh_token = "not_used";

/* */
// Code parameters 
//
$url = "$authorizeURL?client_id=$client_id&code_challenge=$code_challenge&scope=IoT%20User%20offline_access&redirect_uri=$callback_uri&response_type=code";
$header = array("Content-Type: application/x-www-form-urlencoded");

$curloptions = array(
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD => "$user:$pwd",
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_POST => true,
);

// Call Curl Code 
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

// Code Extraction 
//
$matches = array();
$pattern = '/code=(.*)"/';
if (preg_match_all($pattern, $response, $matches)) {
    $code = $matches[1][0];
} else {
    exit("Erreur"."\n");
}

// Token Settings 
//
$url = "$tokenURL?grant_type=authorization_code&code_verifier=$code_challenge&client_id=$client_id&redirect_uri=$callback_uri&code=$code";
$header = array("Content-Type: application/x-www-form-urlencoded");

$curloptions = array(
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_POST => true,
);

// Call Curl Token 
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

// Token extraction 
//
$json = json_decode($response, true);
echo($response);
echo("\n");
$token = $json['access_token'];
/**/

// Read user data 
//
$url = "https://api.viessmann.com/users/v1/users/me?sections=identity";
$header = array("Content-Type: application/x-www-form-urlencoded","Authorization: Bearer $token");

$curloptions = array(
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
);

// Data Curl Call 
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);

print_r(json_decode($response));


// get Installations-Id 
//

$getURL='https://api.viessmann.com/iot/v1/equipment/installations/';
$headerRequest = array(
    "Content-Type: application/x-www-form-urlencoded",
    "Authorization: Bearer $token" //put here the name you have used for the AuthorizationTOKEN variable
);

$cURLConnection = curl_init();
curl_setopt($cURLConnection, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)");
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER,true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headerRequest); 
curl_setopt($cURLConnection, CURLOPT_CONNECTTIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_TIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_URL,$getURL);

$apiResponse = curl_exec($cURLConnection);
$apiErr = curl_error($cURLConnection);
curl_close($cURLConnection);
$jsonResponse = json_decode($apiResponse, true);
print_r($jsonResponse);
print_r($apiErr);

?>

THanks and regards

Andreas

Your code looks and works fine 🙂

print_r($jsonResponse);

The above line will return an array.

Accordingly with the documentation available here

https://developer.viessmann.com/en/doc/iot/overview

you will find the InstallationID under the parameter "id".

 

To extract the parameter from the array you can ad to your code the following two lines:

$installationId = $jsonResponse['data']['0']['id'];
echo "installationId: ".$installationId."<br>";

 


Well, that's interesting... It is not working on my server..... 😞

 

I'm quite familiar with PHP or shell scripting so it must be something wrong with my user profile or my installation that I don't have access to the installationId and so on...

 

How can I check that? Or may be who can check that?

 

My response looks like this:

 

Array
(
[data] => Array
(
)

[cursor] => Array
(
[next] =>
)
)

 

 

 

Hi @MrAnderson ,

 

it appears to me that for the account that you are using for requesting the API, there is no installation registered. This should explain why you are getting an OK response, but without information.

 

Please make sure that you use the account that registered the installation (and is able to see it within ViCare) to request the data via API.

Hi @MichaelHanna 

 

you made my day........

 

Shame on me that I didn't get it. For my ViCare I'm using a different user as for the community...
After one and a half year I simply forgot it 🙂 

 

Many thanks