-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path99_myUtils_ZWave.pm
158 lines (135 loc) · 5.38 KB
/
99_myUtils_ZWave.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
##############################################
# $Id: 99_attrT_ZWave_Utils.pm Test Ack-userReadings 2020-10-30 Beta-User $
#
# packages ####################################################################
package FHEM::attrT_ZWave_Utils; ## no critic 'Package declaration'
use strict;
use warnings;
use GPUtils qw(GP_Import);
## Import der FHEM Funktionen
#-- Run before package compilation
BEGIN {
# Import from main context
GP_Import(
qw(
InternalVal
readingsSingleUpdate
ReadingsVal
ReadingsNum
ReadingsAge
devspec2array
FW_makeImage
defs
)
);
}
sub main::attrT_ZWave_Utils_Initialize { goto &Initialize }
# initialize ##################################################################
sub Initialize {
my $hash = shift;
return;
}
sub identify_channel_devices {
my $devname = shift;
my $wanted = shift // return;
my $mainId = substr(InternalVal($devname,"nodeIdHex","00"),0,2);
my $wantedId = $mainId;
$wantedId .= "0$wanted" if $wanted;
my @names = devspec2array("TYPE=ZWave:FILTER=nodeIdHex=$wantedId");
return if !@names;
return $names[0];
}
sub devStateIcon_shutter {
my $levelname = shift // return;
my $model = shift // "FGR223";
my $mode = shift // "roller"; # or "venetian"
my $slatname = $levelname;
my $dimlevel= ReadingsNum($levelname,"dim",0);
my $ret ="";
my $slatlevel = 0;
my $slatcommand_string = "dim ";
my $moving = 0;
if ($model eq "FGR223") {
if ($mode eq "venetian") {
#my ($def,$defnr) = split(" ", InternalVal($levelname,"DEF",$levelname));
#$defnr++;
#my @slatnames = devspec2array("DEF=$def".'.'.$defnr);
$slatname = identify_channel_devices($levelname,2);
$slatlevel= ReadingsNum($slatname,"state",0);
}
$moving = 1 if ReadingsNum($levelname,"power",0) > 0;
}
if ($model eq "FGRM222") {
if ($mode eq "venetian") {
$slatlevel= ReadingsNum($slatname,"positionSlat",0);
$slatcommand_string = "positionSlat ";
}
$moving = 1 if ReadingsNum($levelname,"power",0) > 0;
}
#levelicon
my $symbol_string = "fts_shutter_";
my $command_string = "dim 99";
$command_string = "dim 0" if $dimlevel > 50;
$symbol_string .= int ((109 - $dimlevel)/10)*10;
$ret .= $moving ? "<a href=\"/fhem?cmd.dummy=set $levelname stop&XHR=1\">" . FW_makeImage("edit_settings","edit_settings") . "</a> "
: "<a href=\"/fhem?cmd.dummy=set $levelname $command_string&XHR=1\">" . FW_makeImage($symbol_string,"fts_shutter_10") . "</a> ";
#slat
if ($mode eq "venetian") {
$symbol_string = "fts_blade_arc_close_";
$slatlevel > 49 ? $symbol_string .= "00" : $slatlevel > 24 ? $symbol_string .= "50" : $slatlevel < 25 ? $symbol_string .= "100" : undef;
$slatlevel > 49 ? $slatcommand_string .= "0" : $slatlevel > 24 ? $slatcommand_string .= "50" : $slatlevel < 25 ? $slatcommand_string .= "25" : undef;
$symbol_string = FW_makeImage($symbol_string,"fts_blade_arc_close_100");
$ret .= qq(<a href="/fhem?cmd.dummy=set $slatname $slatcommand_string&XHR=1">$symbol_string $slatlevel %</a>);
}
return "<div><p style=\"text-align:right\">$ret</p></div>";
}
sub desiredTemp {
my $name = shift // return;
my $call = shift // 'OK';
my $hash = $defs{$name} // return;
my $now = time;
my $state = ReadingsVal($name,'state','unknown');
my $stateNum = ReadingsNum($name,'state',20);
# return if ReadingsAge($name,'state',10000000) - ReadingsNum($name,'timeToAck',0) > 1;
if ($state =~ m,desired-temp|thermostatSetpointSet,) {
readingsBulkUpdate($hash, 'desired-temp',$stateNum,1);
return;
}
if ($state =~ m,tmAuto|tmManual|tmHeating,) {
readingsBulkUpdate($hash, 'desired-temp',ReadingsVal($name,'heating','unknown'),1);
return;
}
if ($state =~ m,tmEnergySaveHeating,) {
readingsBulkUpdate($hash, 'desired-temp',ReadingsVal($name,'energySaveHeating','unknown'),1);
return;
}
if ($state =~ m,off,) {
readingsBulkUpdate($hash, 'desired-temp',6,'unknown',1);
return;
}
Log3($name, 3, "ZWave-utils desiredTemp called, but no match for state comparisons");
return;
}
1;
__END__
=pod
=begin html
<a name="attrT_ZWave_Utils"></a>
<h3>attrT_ZWave_Utils</h3>
<ul>
<b>devStateIcon_shutter</b>
<br>
Use this to get a multifunctional iconset to control shutter devices like Fibaro FGRM222 devices in venetian blind mode<br>
Examples:
<ul>
<code>attr Jalousie_WZ devStateIcon {FHEM::attrT_ZWave_Utils::devStateIcon_shutter($name,"FGRM222")}<br> attr Jalousie_WZ webCmd dim<br>attr Jalousie_WZ userReadings dim:(dim|reportedState).* {$1 =~ /reportedState/ ? ReadingsNum($name,"reportedState",0):ReadingsNum($name,"state",0)}
</code><br>
or <br>
<code>attr Jalousie_WZ devStateIcon {FHEM::attrT_ZWave_Utils::devStateIcon_shutter($name,"FGR223", "venetian")}<br> attr Jalousie_WZ webCmd dim<br>attr Jalousie_WZ userReadings dim:(dim|reportedState).* {$1 =~ /reportedState/ ? ReadingsNum($name,"reportedState",0):ReadingsNum($name,"state",0)}
</code><br>
Code can be used for blinds with or without venetian blind mode. In cas if and slat level is not part of the main device (like Fibaro FGR223, the second FHEM device to control slat level has to have a userReadings attribute for state like this:<br>
<code>attr ZWave_SWITCH_MULTILEVEL_8.02 userReadings state:swmStatus.* {ReadingsNum($name,"swmStatus",0)}</code>
</ul>
</ul>
=end html
=cut