I have two Tasmota flashed sonoff devices. The POWCT and the TH316. The TH316 is connected to two temperature sensors which monitor my solar geyser’s temperature, while the POWCT is monitoring my total power usage.
On connect and monitor them using my iHost, I have installed the following:
Add-ons: (docker containers)
eclipse-mosquitto (standard add-on)
port: 1889:1883
volumes: MQTT:/mosquitto/config
(MQTT is a custom named volume)
nodered/node-red (standard add-on)
port: 1880:1880
volumes: /data
prom/prometheus-linux-armv7
port: 9090:9090
volumes: PrometheusEtc:/etc/prometheus & Prometheus:/prometheus
(PrometheusEtc and Prometheus are custom named volumes)
filebrowser/filebrowser (standard add-on)
port: 8080:80
nodered:/srv/nodered
MQTT:/srv/mosquito
Prometheus:/srv/prometheus
PrometheusEtc:/srv/prometheusEtc
Filebrowser:
All volumes need to be mounted into /srv/
You should do this AFTER making all volumes as the only way I know to add new mounts is to delete the container and re-install it.
Prometheus:
The prometheus configs are in a yml files, so after install and running the container, you will need to open the file-browser app, open the prometheusEtc folder, download the prometheus.yml file and add or update the target list with the IP and port of your ihost and node-red :
- targets: ["192.168.1.99:1880"]
Remove the old file and replace it with your copy. Thereafter re-start prometheus.
It will start scraping your data but note this will throw errors until you have installed the prometheus exported in node-red.
Mosquito:
There are multiple existing posts describing how to setup and configure Mosquito and import data via MQTT
Node-Red:
In node-red I installed the following:
The temperature data comes in a single message, so I first split that into two messages with a function.
if (msg.payload.Time != undefined) {
var msg1 = null;
var msg2 = null;
var msg3 = null;
// we only have one temp sensor
if (msg.payload.DS18B20 != undefined) {
msg1 = { payload: { Time: msg.payload.Time, Id: msg.payload["DS18B20"].Id, Temperature: msg.payload["DS18B20"].Temperature } }
}
// we have multiple sensors
if (msg.payload["DS18B20-1"] != undefined) {
msg2 = { payload: { Time: msg.payload.Time, Id: msg.payload["DS18B20-1"].Id, Temperature: msg.payload["DS18B20-1"].Temperature}}
}
if (msg.payload["DS18B20-2"] != undefined) {
msg3 = { payload: { Time: msg.payload.Time, Id: msg.payload["DS18B20-2"].Id, Temperature: msg.payload["DS18B20-2"].Temperature}}
}
return [msg1, msg2, msg3];
}
return [null, null, null];
Thereafter, the messages all go into a function to generate the prometheus payload, which updates a gauge. A single gauge with a label for each of the sensors:
var newMsg = {}
newMsg.payload = {
"reset": false,
"op": "set",
"val": msg.payload.Temperature,
"labels": {
"device": msg.payload.Id
}
};
return newMsg;