Add temperature sensors to Cerbo GX via MQTT

Hello everyone

I know this is a topic that’s probably been discussed from all angles, but something seems to have gone wrong on my Cerbo during the last update, and somehow I’m not getting anywhere.

Since it gets very warm in summer at the site of my MP2/Fronius, I bought a few 1-Wire DS18B20 sensors and an ESP8266, and configured them with ESPHome so that the ESP now sends all the readings from the sensors connected to the MP2 and MPPT to Iobroker.

Until recently, I could then use the script from GitHub

https://github.com/mr-manuel/venus-os_dbus-mqtt-temperature

to send the readings directly to Venus via the MQTT broker in Iobroker. This meant the temperature readings were displayed as temperatures on the overview page. Since the last (or previous-to-last) update, the Cerbo GX keeps trying to install something whenever I send a sensor reading. (Yes, I have already enabled MQTT, etc.).

I don’t quite understand what I’m doing wrong at the moment. Before I reinstall everything and have to deal with this again at the next update, I thought I’d ask whether there have been any changes. I think the “MQTT devices” item under Integrations is new, but I haven’t found any instructions on how to add sensors there.

Addendum: Venus V3.85

You don’t need any scripts from GitHub. This can be accomplished using standard nodes (mqtt in → change → victron-virtual)

Can you post the payload that your ESP8266 is sending?

Good day, Slowmo

Basically, I already have the temperature sensors integrated into my building system, Iobroker. I’ve also set up an MQTT client there to connect to the MQTT broker on the Cerbo GX. Until recently, I sent the values using the following messages (I implemented the script from GitHub on the Cerbo):

Create on the Cerbo:
// Initial MP2 L1
for (var count = 0; count < 1; count++) {
sendTo(‘mqtt.3’, ‘sendMessage2Client’, { topic: ‘device/tmp001/Status’, message: ‘{ “clientId”: “tmp001”, “connected”: 1, “version”: “v1.2”, “services”: {“t1”: “temperature”} }’, retain: false })
sendTo(‘mqtt.3’, ‘sendMessage2Client’, { topic: ‘W/cxxxxx811/temperature/6/CustomName’, message: ‘{ “value”:“Temperature MP2 L1” }’, retain: false });
}

Send values to the Cerbo:
on({ id: [].concat([‘alias.0.VisuPVA.Temp_MP2_L1’]), change: ‘ne’ }, async (obj) => {
let value = obj.state.val;
let oldValue = obj.oldState.val;
sendTo(‘mqtt.3’, ‘sendMessage2Client’, { topic: ‘W/cxxxxxx811/temperature/6/Temperature’, message: ([‘{ “value”:’,getState(‘alias.0.VisuPVA.Temp_MP2_L1’).val,’ }‘].join(’')), retain: false });
});

But I can put the message together myself as needed, so that’s no problem at all. I know I could also send them directly to the Cerbo from the ESP8266 using a second broker account. But I haven’t yet managed to get that configuration working.

Here’s an example of how I display a temperature using NodeRED:

```flows
[
    {
        "id": "e535ae48405c62c8",
        "type": "victron-virtual",
        "z": "203330207fd5f20e",
        "name": "WWBoiler Mitte",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_nrofphases": 1,
        "enable_s2support": false,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "grid_nrofphases": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "x": 720,
        "y": 720,
        "wires": [
            []
        ]
    },
    {
        "id": "c0b1cef9b3863bf6",
        "type": "mqtt in",
        "z": "203330207fd5f20e",
        "name": "IN: Wert vom Broker",
        "topic": "/hooks/devices/0/SensorData/mitte",
        "qos": "0",
        "datatype": "auto",
        "broker": "5b6f6bd3ef4c8a21",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 230,
        "y": 720,
        "wires": [
            [
                "0a6c5c7279ba3dc6"
            ]
        ]
    },
    {
        "id": "0a6c5c7279ba3dc6",
        "type": "function",
        "z": "203330207fd5f20e",
        "name": "WWBoiler_mitte",
        "func": "// MQTT payload: \"60.50\"\nlet t = Number(msg.payload);\nif (isNaN(t)) return null;\n\n// optional: Grenzen, damit keine Ausreißer geschrieben werden\n// if (t < -40 || t > 120) return null;\n\nmsg.payload = {\n  \"/Temperature\": t\n};\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 720,
        "wires": [
            [
                "e535ae48405c62c8"
            ]
        ]
    },
    {
        "id": "5b6f6bd3ef4c8a21",
        "type": "mqtt-broker",
        "name": "Broker (dein anderer)",
        "broker": "192.168.178.47",
        "port": "1883",
        "clientid": "nodered-mqtt-in",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "856e7e8b46450bdb",
        "type": "global-config",
        "env": [],
        "modules": {
            "@victronenergy/node-red-contrib-victron": "1.7.28"
        }
    }
]
```

Thanks

In the meantime, I’ve realised that in Node-RED I first have to create the temperature sensors using a “virtual device”, and only then can I write values to those topics.

Basically, my original script/Blockly does nothing more than create the “virtual device” when it starts up, and then publish the values whenever it detects a change.

It really does work without a script; it’s already working again for me, at least partly. I also somehow thought I’d read somewhere that the “W” at the beginning is no longer there when publishing.

Many thanks for your support

but then you need the dbus-mqtt script you mentioned, don’t you?

No, I defined the virtual devices as temperature sensors in Node-Red on the Cerbo GX:

They’re now in the MQTT list on the Cerbo.

And I can write to them using a Blockly via the MQTT client in Iobroker:

To write to a topic on the Cerbo GX, you simply replace “N/” with “W/”. This lets you write to the data points externally without any dbus script.

It looks like this in the Victron GUI:

I don’t know yet whether this is the right, reliable way to do it, or whether it will survive an update, but at least I now have the temperatures back in VRM as well, and can intervene remotely to some extent if anything happens. I think it’s a shame that the internal temperatures aren’t accessible on Victron devices, because I assume they’re measured but simply aren’t exposed to the software.

You can also create virtual switches this way, which can then be used for whatever purpose.

I hope my approach is a bit clearer now?

Andi

yes, isn’t that exactly the approach I had outlined?

More or less, yes, except that in my case the data doesn’t come from Node-Red but from an external source. In Node-Red, I’ve basically only defined the virtual devices.

Since I have all these temperatures as values in my home visualisation as well, I couldn’t simply forward them to Node-Red either. I know it would somehow be possible to set up a second MQTT client with ESPHome. But since I haven’t really got to grips with either Node-Red or ESPHome, I use what I’m confident with, what I understand and know how to handle.

Thanks again

Andi