added zone specific readings (temp & hum), getter for zone state added
This commit is contained in:
parent
ff7a81075d
commit
5c10147c88
104
98_TadoAPI.pm
104
98_TadoAPI.pm
|
@ -57,7 +57,7 @@ my $Response=undef;
|
|||
my $UserAgent = undef;
|
||||
|
||||
my %sets = (
|
||||
"getTemperature" => "noArg",
|
||||
"getTemperature" => "",
|
||||
"refreshToken" => "noArg",
|
||||
"password" => "",
|
||||
"setGeo" => "on,off",
|
||||
|
@ -187,7 +187,17 @@ sub TadoAPI_Set(@) {
|
|||
|
||||
} elsif( $cmd eq 'getTemperature' ) {
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "processing ($cmd)" if $debug;
|
||||
TadoAPI_GetTemperature($hash);
|
||||
return "ZoneID as parameter needed" if (!$value);
|
||||
if( $value >= 1 ) {
|
||||
my ($temperature, $humidity) = TadoAPI_GetZoneTemperatureById($hash, $value);
|
||||
my $zoneName = TadoAPI_GetZoneNameById($hash, $value);
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "Temperatur_" . $zoneName, $temperature);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit_" . $zoneName, $humidity);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
} else {
|
||||
return "Wrong ZoneID";
|
||||
}
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "$cmd finished\n";
|
||||
return undef;
|
||||
|
||||
|
@ -391,8 +401,9 @@ sub TadoAPI_Connect(@) {
|
|||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $tokenFileName = $tokenFile."_".$name;
|
||||
my $tokenLifeTime = 0 unless $hash->{TOKEN_LIFETIME};
|
||||
my $tokenLifeTime = $hash->{TOKEN_LIFETIME};
|
||||
|
||||
$tokenLifeTime = 0 if(!defined $tokenLifeTime || $tokenLifeTime eq '');
|
||||
|
||||
#debug
|
||||
$debug = $attr{$name}{debug};
|
||||
|
@ -675,10 +686,15 @@ sub TadoAPI_GetUpdate(@){
|
|||
if ($success){
|
||||
# readings update
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "Temperatur", $temperature);
|
||||
for (my $i=1; $i <= TadoAPI_GetZoneCount($hash); $i++) {
|
||||
my $zoneName = TadoAPI_GetZoneNameById($hash, $i);
|
||||
# returns temp and humidity
|
||||
my ($temperature, $humidity) = TadoAPI_GetZoneTemperatureById($hash, $i);
|
||||
readingsBulkUpdate($hash, "Temperatur_" . $zoneName, $temperature);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit_" . $zoneName, $humidity);
|
||||
}
|
||||
readingsBulkUpdate($hash, "Geolocation", $setting);
|
||||
readingsBulkUpdate($hash, "HomeMode", $tadoMode);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit", $humidity);
|
||||
readingsBulkUpdate($hash, "Heizleistung", $currentHeatingPower);
|
||||
readingsBulkUpdate($hash, "OverlayType", $overlay);
|
||||
readingsBulkUpdate($hash, "DesiredTemp", $desiredTemp);
|
||||
|
@ -690,49 +706,6 @@ sub TadoAPI_GetUpdate(@){
|
|||
return undef;
|
||||
}
|
||||
|
||||
|
||||
sub TadoAPI_GetTemperature(@){
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $homeID = $attr{$name}{homeID};
|
||||
my $URL=$QueryURL.qq{/$homeID/zones/1/state};
|
||||
my $temperature = 0;
|
||||
my $humidity = 0;
|
||||
|
||||
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "homeID: $homeID" if $debug;
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "query-URL: $URL" if $debug;
|
||||
|
||||
if($apiStatus == 1){
|
||||
TadoAPI_Connect($hash);
|
||||
|
||||
$header = HTTP::Headers->new("Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}");
|
||||
$UserAgent = LWP::UserAgent::Paranoid->new(ssl_opts => { verify_hostname => 1 },protocols_allowed => ['https','http'],request_timeout => 5,);
|
||||
$UserAgent->default_headers($header);
|
||||
|
||||
$Request = GET($URL);
|
||||
$Response = $UserAgent->request($Request);
|
||||
|
||||
if($Response->is_success){
|
||||
my $ResponseData = decode_json($Response->content);
|
||||
$temperature = $ResponseData->{'sensorDataPoints'}->{'insideTemperature'}->{'celsius'};
|
||||
$humidity = $ResponseData->{'sensorDataPoints'}->{'humidity'}->{'percentage'};
|
||||
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Retriving zone 1 state:\n" . $Response->content if $debug;
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Actual temperature is: $temperature Celsius" if $debug;
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "Temperatur", $temperature);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit", $humidity);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
return $temperature;
|
||||
}else{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "[Authentication Error]". $Response->status_line;
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub TadoAPI_GetGeo(@){
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
@ -918,10 +891,9 @@ sub TadoAPI_SetGeo(@){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
######################################
|
||||
############ Helpers #################
|
||||
######################################
|
||||
sub TadoAPI_GetZoneCount(@) {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
@ -971,6 +943,36 @@ sub TadoAPI_GetZoneNameById(@) {
|
|||
return undef;
|
||||
}
|
||||
|
||||
sub TadoAPI_GetZoneTemperatureById(@){
|
||||
my ($hash, $zoneID) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $homeID = $attr{$name}{homeID};
|
||||
my $URL=$QueryURL.qq{/$homeID/zones/$zoneID/state};
|
||||
my $temperature = 0;
|
||||
my $humidity = 0;
|
||||
|
||||
if($apiStatus == 1){
|
||||
TadoAPI_Connect($hash);
|
||||
|
||||
$header = HTTP::Headers->new("Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}");
|
||||
$UserAgent = LWP::UserAgent::Paranoid->new(ssl_opts => { verify_hostname => 1 },protocols_allowed => ['https','http'],request_timeout => 5,);
|
||||
$UserAgent->default_headers($header);
|
||||
|
||||
$Request = GET($URL);
|
||||
$Response = $UserAgent->request($Request);
|
||||
|
||||
if($Response->is_success){
|
||||
my $ResponseData = decode_json($Response->content);
|
||||
$temperature = $ResponseData->{'sensorDataPoints'}->{'insideTemperature'}->{'celsius'};
|
||||
$humidity = $ResponseData->{'sensorDataPoints'}->{'humidity'}->{'percentage'};
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Temperature: $temperature Humidity: $humidity\n" if $debug;
|
||||
return ($temperature, $humidity);
|
||||
}else{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "[Authentication Error]". $Response->status_line;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue