und da liegt es jetzt auch.

NAME
FHEM::Utility::MQTT2_Dispatcher - Subscribe to MQTT messages in fhem modules
SYNOPSIS
package main;
use FHEM::Utility::MQTT2_Dispatcher qw( :DEFAULT );
sub X_Define {
...
$hash->{Listener} = on_mqtt('home/#', sub {
X_MQTT($hash, @_);
}) or do {
Log3($hash, 2, $@);
};
};
sub X_MQTT {
my ($hash, $topic, $value, $io_name) = @_;
};
# required for rereadcfg etc
sub X_Undef {
...
del_mqtt($hash->{Listener});
return;
};
DESCRIPTION
This module provides a couple of helper functions to let a fhem module subscripe to MQTT topics using a defined MQTT2_SERVER or MQTT2_CLIENT.
FUNCTIONS
on_mqtt ($topic, sub {})
This function subscribes to a given $topic. MQTT wildcards are allowed. The MQTT2 IO device, of course, must receive that topic. The coderef can be an anonyious sub or a variable holding one. This function receive 3 params: the $topic (unicode), the $value (raw) and the $name of the receiving IO device.
Returns an identifier that is used to delete that handler at any time. Undef in case of an error.
Multiple handlers can be installed at the same time.
del_mqtt ($id)
This function removes (deletes) the handler specified with $id. It must be called in X_Undef function of the embedding fhem module.