mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-20 19:36:02 +00:00
attrTemplate: changes to z2m-thermostat-utils, peer review version #122708
git-svn-id: https://svn.fhem.de/fhem/trunk@24898 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f67adcbe72
commit
35f9e41f8d
@ -7,29 +7,28 @@ package FHEM::attrT_z2m_thermostat_Utils; ## no critic 'Package declaration'
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use JSON qw(decode_json);
|
use JSON qw(decode_json);
|
||||||
#use Time::HiRes qw( gettimeofday );
|
use Carp qw(carp);
|
||||||
|
#use POSIX qw(strftime);
|
||||||
#use List::Util qw( min max );
|
#use List::Util qw( min max );
|
||||||
|
#use Scalar::Util qw(looks_like_number);
|
||||||
|
#use Time::HiRes qw( gettimeofday );
|
||||||
|
|
||||||
use GPUtils qw(GP_Import);
|
use GPUtils qw(GP_Import);
|
||||||
|
|
||||||
## Import der FHEM Funktionen
|
## Import der FHEM Funktionen
|
||||||
#-- Run before package compilation
|
#-- Run before package compilation
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
|
||||||
# Import from main context
|
# Import from main context
|
||||||
GP_Import(
|
GP_Import(
|
||||||
qw(
|
qw(
|
||||||
AttrVal
|
AttrVal
|
||||||
InternalVal
|
InternalVal
|
||||||
CommandGet
|
|
||||||
CommandSet
|
|
||||||
readingsSingleUpdate
|
|
||||||
readingsBulkUpdate
|
|
||||||
readingsBeginUpdate
|
|
||||||
readingsEndUpdate
|
|
||||||
ReadingsVal
|
ReadingsVal
|
||||||
ReadingsNum
|
ReadingsNum
|
||||||
ReadingsAge
|
ReadingsAge
|
||||||
|
CommandGet
|
||||||
|
CommandSet
|
||||||
|
readingsSingleUpdate
|
||||||
json2nameValue
|
json2nameValue
|
||||||
defs
|
defs
|
||||||
Log3
|
Log3
|
||||||
@ -37,7 +36,7 @@ BEGIN {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub main::attrT_z2m_thermostat_Utils_Initialize { goto &Initialize }
|
sub ::attrT_z2m_thermostat_Utils_Initialize { goto &Initialize }
|
||||||
|
|
||||||
# initialize ##################################################################
|
# initialize ##################################################################
|
||||||
sub Initialize {
|
sub Initialize {
|
||||||
@ -47,19 +46,14 @@ sub Initialize {
|
|||||||
|
|
||||||
# Enter you functions below _this_ line.
|
# Enter you functions below _this_ line.
|
||||||
|
|
||||||
#attr DEVICE userReadings charger_state:car.* { my $val = ReadingsVal($name,"car","none");; my %rets = ("none" => "-1","1" => "Ready","2" => "Charging","3" => "waiting for car","4" => "Charging finished",);; $rets{$val}}, energy_total:eto.* { ReadingsVal($name,"eto",0)*0.1 }, energy_akt:dws.* { ReadingsVal($name,"dws",0)*2.77 }
|
|
||||||
|
|
||||||
#attr DEVICE jsonMap alw:Activation amp:Ampere tmp:temperature
|
|
||||||
|
|
||||||
|
|
||||||
my %jsonmap = (
|
my %jsonmap = (
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sub z2t_send_weekprofile {
|
sub z2t_send_weekprofile {
|
||||||
my $name = shift;
|
my $name = shift // carp q[No device name provided!] && return;
|
||||||
my $wp_name = shift;
|
my $wp_name = shift // carp q[No weekprofile device name provided!] && return;
|
||||||
my $wp_profile = shift // return;
|
my $wp_profile = shift // carp q[No weekprofile profile name provided!] && return;
|
||||||
my $model = shift // ReadingsVal($name,'week','5+2');
|
my $model = shift // ReadingsVal($name,'week','5+2');
|
||||||
my $topic = shift // AttrVal($name,'devicetopic','') . '/set';
|
my $topic = shift // AttrVal($name,'devicetopic','') . '/set';
|
||||||
|
|
||||||
@ -72,53 +66,51 @@ sub z2t_send_weekprofile {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my @D = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
|
my @D = qw(Sun Mon Tue Wed Thu Fri Sat); # eqals to my @D = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
|
||||||
my $payload;
|
my $payload;
|
||||||
my @days = (0..6);
|
my @days = (0..6);
|
||||||
my $text = decode_json($wp_profile_data);
|
my $decoded;
|
||||||
|
if ( !eval { $decoded = decode_json($wp_profile_data) ; 1 } ) {
|
||||||
|
Log3($name, 1, "JSON decoding error in $wp_profile provided by $wp_name: $@");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $model eq '5+2' || $model eq '6+1') {
|
if ( $model eq '5+2' || $model eq '6+1') {
|
||||||
@days = (0,1);
|
@days = (0,1);
|
||||||
#$payload = '{"holidays":[';
|
|
||||||
} elsif ($model eq '7') {
|
} elsif ($model eq '7') {
|
||||||
@days = (1);
|
@days = (1);
|
||||||
#$payload = '{"workdays":[';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $i (@days) {
|
for my $i (@days) {
|
||||||
$payload = '{';
|
$payload = '{';
|
||||||
|
|
||||||
for my $j (0..7) {
|
for my $j (0..7) {
|
||||||
if (defined $text->{$D[$i]}{'time'}[$j]) {
|
if (defined $decoded->{$D[$i]}{'time'}[$j]) {
|
||||||
my $time = $text->{$D[$i]}{'time'}[$j-1] // "00:00";
|
my $time = $decoded->{$D[$i]}{'time'}[$j-1] // "00:00";
|
||||||
my ($hour,$minute) = split m{:}xms, $time;
|
my ($hour,$minute) = split m{:}xms, $time;
|
||||||
$hour = 0 if $hour == 24;
|
$hour = 0 if $hour == 24;
|
||||||
$payload .= '"hour":' . abs($hour) .',"minute":'. abs($minute) .',"temperature":'.$text->{$D[$i]}{'temp'}[$j];
|
$payload .= '"hour":' . abs($hour) .',"minute":'. abs($minute) .',"temperature":'.$decoded->{$D[$i]}{'temp'}[$j];
|
||||||
$payload .= '},{' if defined $text->{$D[$i]}{'time'}[$j+1];
|
$payload .= '},{' if defined $decoded->{$D[$i]}{'time'}[$j+1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$payload .='}';
|
$payload .='}';
|
||||||
if ( $i == 0 && ( $model eq '5+2' || $model eq '6+1') ) {
|
if ( $i == 0 && ( $model eq '5+2' || $model eq '6+1') ) {
|
||||||
#$payload .='},'if $i == 0 || $i > 1 && $i != $days[-1];
|
CommandSet($hash,"$name holidays $payload");
|
||||||
#$payload .='],"workdays":[' if $i == 1;
|
|
||||||
CommandSet($defs{$name},"$name holidays $payload");
|
|
||||||
$payload = '{';
|
$payload = '{';
|
||||||
}
|
}
|
||||||
CommandSet($defs{$name},"$name workdays $payload") if $model eq '5+2' || $model eq '6+1' || $model eq '7';
|
CommandSet($hash,"$name workdays $payload") if $model eq '5+2' || $model eq '6+1' || $model eq '7';
|
||||||
}
|
}
|
||||||
#$payload .=']}';
|
readingsSingleUpdate( $hash, 'weekprofile', "$wp_name $wp_profile",1);
|
||||||
readingsSingleUpdate( $defs{$name}, 'weekprofile', "$wp_name $wp_profile",1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
=item summary helper functions needed for zigbee2mqtt thermostats in MQTT2_DEVICE
|
=item summary helper functions needed for zigbee2mqtt thermostats in MQTT2_DEVICE
|
||||||
=item summary_DE needed Hilfsfunktionen für zigbee2mqtt MQTT2_DEVICE-Thermostate
|
=item summary_DE Hilfsfunktionen für zigbee2mqtt MQTT2_DEVICE-Thermostate
|
||||||
=begin html
|
=begin html
|
||||||
<a id="attrT_z2m_thermostat_Utils"></a>
|
<a id="attrT_z2m_thermostat_Utils"></a>
|
||||||
There may be room for improvement, please adress any issues in https://forum.fhem.de/index.php/topic,116535.0.html.
|
There may be room for improvement, please adress any issues in https://forum.fhem.de/index.php/topic,116535.0.html.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user