In FHEM sieht das ganze ziemlich einfach aus: Zum setzen wird nur dieser Code benötigt:
if($setting eq "fakeSC") {
return "Invalid number of arguments" if(@args != 2);
return "Invalid fakeSCaddr attribute set (must not be 000000)" if(CUL_MAX_fakeSCaddr($hash) eq "000000");
my $state = $args[1] ? "12" : "10";
my $groupid = ReadingsVal($destname,"groupid",0);
return CUL_MAX_Send($hash, "ShutterContactState",$dest,$state,
groupId => sprintf("%02x",$groupid),
flags => ( $groupid ? "04" : "06" ),
src => CUL_MAX_fakeSCaddr($hash));
} elsif($setting eq "fakeWT") {
return "Invalid number of arguments" if(@args != 3);
return "desiredTemperature is invalid" if(!validTemperature($args[1]));
return "Invalid fakeWTaddr attribute set (must not be 000000)" if(CUL_MAX_fakeWTaddr($hash) eq "000000");
#Valid range for measured temperature is 0 - 51.1 degree
$args[2] = 0 if($args[2] < 0); #Clamp temperature to minimum of 0 degree
#Encode into binary form
my $arg2 = int(10*$args[2]);
#First bit is 9th bit of temperature, rest is desiredTemperature
my $arg1 = (($arg2&0x100)>>1) | (int(2*MAX_ParseTemperature($args[1]))&0x7F);
$arg2 &= 0xFF; #only take the lower 8 bits
my $groupid = ReadingsVal($destname,"groupid",0);
return CUL_MAX_Send($hash,"WallThermostatControl",$dest,
sprintf("%02x%02x",$arg1,$arg2), groupId => sprintf("%02x",$groupid),
flags => ( $groupid ? "04" : "00" ),
src => CUL_MAX_fakeWTaddr($hash));
}
sowie der Code zum linken/unlinken:
} elsif(grep /^\Q$setting\E$/, ("associate", "deassociate")) {
my $dest = $args[0];
my $destType;
if($dest eq "fakeWallThermostat") {
return "IODev is not CUL_MAX" if($hash->{IODev}->{TYPE} ne "CUL_MAX");
$dest = AttrVal($hash->{IODev}->{NAME}, "fakeWTaddr", "111111");
return "Invalid fakeWTaddr attribute set (must not be 000000)" if($dest eq "000000");
$destType = MAX_TypeToTypeId("WallMountedThermostat");
} elsif($dest eq "fakeShutterContact") {
return "IODev is not CUL_MAX" if($hash->{IODev}->{TYPE} ne "CUL_MAX");
$dest = AttrVal($hash->{IODev}->{NAME}, "fakeSCaddr", "222222");
return "Invalid fakeSCaddr attribute set (must not be 000000)" if($dest eq "000000");
$destType = MAX_TypeToTypeId("ShutterContact");
} else {
if(exists($defs{$dest})) {
return "Destination is not a MAX device" if($defs{$dest}{TYPE} ne "MAX");
$dest = $defs{$dest}{addr};
} else {
return "No MAX device with address $dest" if(!exists($modules{MAX}{defptr}{$dest}));
}
$destType = MAX_TypeToTypeId($modules{MAX}{defptr}{$dest}{type});
}
Log3 $hash, 5, "Using dest $dest, destType $destType";
if($setting eq "associate") {
return ($hash->{IODev}{Send})->($hash->{IODev},"AddLinkPartner",$hash->{addr},sprintf("%s%02x", $dest, $destType));
} else {
return ($hash->{IODev}{Send})->($hash->{IODev},"RemoveLinkPartner",$hash->{addr},sprintf("%s%02x", $dest, $destType));
}
Ich finde das sieht doch ziemlich machbar aus, die schwierigste Frage ist wohl nur wo man das am besten einbaut.