added reading heatingpower and humidity
+ changed token directory to fhemutils
This commit is contained in:
parent
9b686b31c1
commit
ed7af3236f
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env perl
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: 98_TadoAPI.pm
|
||||
# FILE: 98_TadoAPI_API.pm
|
||||
#
|
||||
# USAGE: Module for FHEM
|
||||
# Info: Turn $debug on for debugging
|
||||
|
@ -18,7 +18,7 @@
|
|||
# ORGANIZATION:
|
||||
# VERSION: 1.0
|
||||
# CREATED: 04/12/2019 07:55:44 PM
|
||||
# REVISION: 10/16/2019 02:17:22 PM
|
||||
# REVISION: 04/23/2019 05:17:22 PM
|
||||
#===============================================================================
|
||||
package main;
|
||||
use strict;
|
||||
|
@ -39,7 +39,7 @@ my $scope='home.user';
|
|||
my $AuthURL = qq{https://auth.tado.com/oauth/token};
|
||||
my $DataURL = qq{https://my.tado.com/api/v2/me};
|
||||
my $QueryURL = qq{https://my.tado.com/api/v2/homes};
|
||||
my $tokenFile = "./temp/TadoAPItoken_module";
|
||||
my $tokenFile = "./FHEM/FhemUtils/TadoAPI_token";
|
||||
my $debug = 0;
|
||||
my $header = {};
|
||||
my $data = {};
|
||||
|
@ -64,6 +64,7 @@ my %sets = (
|
|||
|
||||
my %gets = (
|
||||
"getHomeMode" => "noArg",
|
||||
"getZoneInfo" => "noArg",
|
||||
"getGeo" => "noArg"
|
||||
);
|
||||
|
||||
|
@ -176,6 +177,8 @@ sub TadoAPI_Set(@) {
|
|||
|
||||
} elsif( $cmd eq 'refreshToken' ) {
|
||||
Log3 $name, 3, "TadoAPI: set $name: processing ($cmd)\n";
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer( gettimeofday() + 10, "TadoAPI_Update", $hash, 0 );
|
||||
TadoAPI_Connect($hash);
|
||||
return undef;
|
||||
|
||||
|
@ -226,6 +229,13 @@ sub TadoAPI_Get(@) {
|
|||
last;
|
||||
};
|
||||
|
||||
$cmd eq "getZoneInfo" and do {
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "processing ($cmd)" if $debug;
|
||||
TadoAPI_GetZoneInfo($hash);
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "$cmd finished\n";
|
||||
last;
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
return TadoAPI_Catch($@) if $@;
|
||||
|
@ -473,6 +483,8 @@ sub TadoAPI_GetUpdate(@){
|
|||
my $deviceURL=$QueryURL.qq{/$homeID/mobileDevices/$mobileID/settings};
|
||||
my $setting = 0;
|
||||
my $temperature = 0;
|
||||
my $humidity = 0;
|
||||
my $currentHeatingPower = 0;
|
||||
my $tadoMode = 0;
|
||||
my $success = 0;
|
||||
|
||||
|
@ -491,6 +503,9 @@ sub TadoAPI_GetUpdate(@){
|
|||
my $ResponseData = decode_json($Response->content);
|
||||
$temperature = $ResponseData->{'sensorDataPoints'}->{'insideTemperature'}->{'celsius'};
|
||||
$tadoMode = $ResponseData->{'tadoMode'};
|
||||
$humidity = $ResponseData->{'sensorDataPoints'}->{'humidity'}->{'percentage'};
|
||||
$currentHeatingPower = $ResponseData->{'activityDataPoints'}->{'heatingPower'}->{'percentage'};
|
||||
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "UpdateFn: Actual temperature is: $temperature Celsius and home mode $tadoMode" if $debug;
|
||||
$success = 1;
|
||||
}else{
|
||||
|
@ -518,6 +533,8 @@ sub TadoAPI_GetUpdate(@){
|
|||
readingsBulkUpdate($hash, "Temperatur", $temperature);
|
||||
readingsBulkUpdate($hash, "Geolocation", $setting);
|
||||
readingsBulkUpdate($hash, "HomeMode", $tadoMode);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit", $humidity);
|
||||
readingsBulkUpdate($hash, "Heizleistung", $currentHeatingPower);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
|
@ -533,6 +550,8 @@ sub TadoAPI_GetTemperature(@){
|
|||
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;
|
||||
|
@ -550,11 +569,14 @@ sub TadoAPI_GetTemperature(@){
|
|||
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{
|
||||
|
@ -606,6 +628,38 @@ sub TadoAPI_GetGeo(@){
|
|||
}
|
||||
}
|
||||
|
||||
sub TadoAPI_GetZoneInfo(@) {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $homeID = $attr{$name}{homeID};
|
||||
my $URL=$QueryURL.qq{/$homeID/zones/1/state};
|
||||
|
||||
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);
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Retriving zone 1 state:\n" . $Response->content if $debug;
|
||||
|
||||
my $text = $Response->content;
|
||||
|
||||
print "Retriving zone 1 state:\n" . $text;
|
||||
}else{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "[Authentication Error]". $Response->status_line;
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
|
||||
|
||||
}
|
||||
|
||||
sub TadoAPI_GetHomeMode(@) {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
|
Loading…
Reference in New Issue