Contents
FHEM integrates the sensor via MQTT. You connect FHEM to the broker the sensor is attached to (MQTT2_CLIENT), and define the sensor as a
MQTT2_DEVICE using the block below. After that, fill level, contents, fill height, temperature and alarm are available as readings. Alarm limits and alarm switches can be set from FHEM.
<Hauptthema> stands in this guide for the value entered on the sensor under
Main topic (e.g. zisterne). It must be entered in FHEM in exactly one place, see step 2.
Prerequisites
- Sensor with firmware 4.2.8 or newer, on Wi-Fi, and with the settings under Tank Config completed
- FHEM 6.x with the built-in modules
MQTT2_CLIENTandMQTT2_DEVICE. No further Perl packages are required. - An MQTT broker on the network, e.g. Mosquitto.
Setting up the sensor
In the sensor's web interface, under Connections enter the connection type MQTT Broker, server and port of the broker, a unique
Client id and a Main topic. Leave the switch Home Assistant
switched off.
Setup
-
Connect FHEM to the broker (skip if there is already an
MQTT2_CLIENTfor this broker). On the FHEM command line:define mqtt MQTT2_CLIENT <Adresse des Brokers>:1883Afterwards, the device
mqttmust showopened. If the broker requires a login:attr mqtt username <Benutzer>andset mqtt password <Passwort>. -
Create the sensor. Open any device (e.g.
mqtt), scroll to the very bottom and click Raw definition, replace the contents of the text field with the following block and click Execute commands. Beforehand, in the second line, replacezisternewith your main topic (only there). The device nameZisternecan be chosen freely, but then change it in all lines.define Zisterne MQTT2_DEVICE attr Zisterne devicetopic zisterne attr Zisterne readingList tele/$DEVICETOPIC/LWT:.* LWT\ tele/$DEVICETOPIC/STATE:.* { json2nameValue($EVENT) }\ stat/$DEVICETOPIC/[^/]+:.* { +{ lc(($TOPIC =~ m,([^/]+)$,)[0]) => ($EVENT eq "" ? "-" : $EVENT =~ m/^(True|False)$/ ? lc($EVENT) : $EVENT) } } attr Zisterne setList update:noArg cmnd/$DEVICETOPIC/UPDATE 1\ mini:slider,0,1,100 cmnd/$DEVICETOPIC/MINI $EVTPART1\ maxi:slider,0,1,100 cmnd/$DEVICETOPIC/MAXI $EVTPART1\ alert_min:ON,OFF cmnd/$DEVICETOPIC/ALERT_MIN $EVTPART1\ alert_max:ON,OFF cmnd/$DEVICETOPIC/ALERT_MAX $EVTPART1 attr Zisterne stateFormat { ReadingsVal($name,"LWT","") eq "Online" ? ReadingsVal($name,"rel_level","-")." %" : "nicht erreichbar" } -
Save: at the top left Save config.
The readings fill immediately because the broker keeps the last value of each. The most important ones:
| Reading | Meaning |
|---|---|
rel_level |
Fill level in % |
filling |
Contents in liters |
level |
Fill height in cm |
temperature |
Temperature in °C |
alert |
MIN, MAX or - (no alarm). Appears only once the sensor sends the topic for the first time |
problem, out_of_range
|
true / false
|
LWT |
Online / Offline
|
The values under stat/<Hauptthema>/… and the JSON from
tele/<Hauptthema>/STATE end up in the same readings, written in lowercase.
Quick test
Execute on device Zisterne set … update: after a few seconds all readings carry the current time, and the status shows the fill level, e.g. 50 %. If the list stays empty, the main topic in the line
devicetopic is wrong. Mind upper and lower case.
Optional
-
Setting values:
set Zisterne mini 20andset Zisterne maxi 85set the alarm limits in %,set Zisterne alert_min OFForalert_max ONswitch the alarms. The sensor reports back the accepted value and discards an invalid one. -
Report an alarm:
define n_Zisterne_Alarm notify Zisterne:alert:.(MIN|MAX) { Log 1, "Füllstand-Alarm $NAME: $EVTPART1" }Instead of
Logput your own notification method here (push, mail …). -
Availability: The status shows
nicht erreichbar(“not reachable”) as soon as the broker reports the sensor asOffline; the corresponding reading is calledLWT. -
Fewer events:
attr Zisterne event-on-change-reading .*makes FHEM report a value only when it changes. -
Chart:
define FileLog_Zisterne FileLog ./log/Zisterne-%Y.log Zisterne:(rel_level|filling|level|temperature):.*logs the measured values. From this, you generate the chart with Create SVG plot on the FileLog. -
FHEM itself as the broker (
define mqttServer MQTT2_SERVER 1883 global, the sensor connects to FHEM): the same block works unchanged, but FHEM then also creates a device by itself with the sensor's Client id. You can delete it and switch it off withattr mqttServer autocreate no.
Limitations
- There is no automatic setup:
autocreatecreates only a collective device for this sensor, with duplicate readings and no controls. The Tasmota templates (attrTemplate tasmota_…) do not fit despite the same topic names. Do not apply them. - If a measured value is missing, the reading shows
-instead of a number. A chart then has a gap or an outlier at that point. - In power saving mode,
LWTstays atOnline, although the sensor is asleep, andsetcommands reach it only while it is awake. - The commands are sent without acknowledgment and without protection against loss (QoS 0). Whether a value arrived is shown by the reading of the same name.
- If, for the
MQTT2_CLIENTautocreateis switched on, you also get the sensor's topics in its collective device.
Verification status
Tested with FHEM 6.5 and sensor firmware 4.2.8.