diff --git a/fhem/FHEM/00_MQTT.pm b/fhem/FHEM/00_MQTT.pm index cb7ef7904..c7bbffd3a 100644 --- a/fhem/FHEM/00_MQTT.pm +++ b/fhem/FHEM/00_MQTT.pm @@ -433,6 +433,7 @@ sub Client_Define($$) { $client->{NOTIFYDEV} = $client->{DEF} if $client->{DEF}; $client->{qos} = MQTT_QOS_AT_MOST_ONCE; + $client->{retain} = 0; $client->{subscribe} = []; $client->{subscribeExpr} = []; @@ -459,6 +460,14 @@ sub client_attr($$$$$) { } last; }; + $attribute eq "retain" and do { + if ($command eq "set") { + $client->{retain} = $value; + } else { + $client->{retain} = 0; + } + last; + }; $attribute eq "IODev" and do { if ($main::init_done) { if ($command eq "set") { diff --git a/fhem/FHEM/10_MQTT_BRIDGE.pm b/fhem/FHEM/10_MQTT_BRIDGE.pm index 8a89e2ea9..3bedea8f5 100644 --- a/fhem/FHEM/10_MQTT_BRIDGE.pm +++ b/fhem/FHEM/10_MQTT_BRIDGE.pm @@ -48,6 +48,7 @@ sub MQTT_BRIDGE_Initialize($) { $hash->{AttrList} = "IODev ". "qos:".join(",",keys %MQTT::qos)." ". + "retain:0,1 ". "publish-topic-base ". "publishState ". "publishReading_.* ". @@ -108,12 +109,12 @@ sub Notify() { my $msgid; if (defined $3 and $3 ne "") { if (defined $hash->{publishReadings}->{$1}) { - $msgid = send_publish($hash->{IODev}, topic => $hash->{publishReadings}->{$1}, message => $3, qos => $hash->{qos}); + $msgid = send_publish($hash->{IODev}, topic => $hash->{publishReadings}->{$1}, message => $3, qos => $hash->{qos}, retain => $hash->{retain}); readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1); } } else { if (defined $hash->{publishState}) { - $msgid = send_publish($hash->{IODev}, topic => $hash->{publishState}, message => $1, qos => $hash->{qos}); + $msgid = send_publish($hash->{IODev}, topic => $hash->{publishState}, message => $1, qos => $hash->{qos}, retain => $hash->{retain}); readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1); } } diff --git a/fhem/FHEM/10_MQTT_DEVICE.pm b/fhem/FHEM/10_MQTT_DEVICE.pm index b379c3c16..eaec71f10 100644 --- a/fhem/FHEM/10_MQTT_DEVICE.pm +++ b/fhem/FHEM/10_MQTT_DEVICE.pm @@ -46,6 +46,7 @@ sub MQTT_DEVICE_Initialize($) { $hash->{AttrList} = "IODev ". "qos:".join(",",keys %MQTT::qos)." ". + "retain:0,1 ". "publishSet ". "publishSet_.* ". "subscribeReading_.* ". @@ -83,10 +84,10 @@ sub Set($@) { my $value = $a[2]; my $msgid; if (defined $value) { - $msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{$command}->{topic}, message => $value, qos => $hash->{qos}); + $msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{$command}->{topic}, message => $value, qos => $hash->{qos}, retain => $hash->{retain}); readingsSingleUpdate($hash,$command,$value,1); } else { - $msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{""}->{topic}, message => $command, qos => $hash->{qos}); + $msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{""}->{topic}, message => $command, qos => $hash->{qos}, retain => $hash->{retain}); readingsSingleUpdate($hash,"state",$command,1); } $hash->{message_ids}->{$msgid}++ if defined $msgid;