Hahaha yes I should have expected that.
The subscribed to topic is
tele/thuis/bgg/tuinkamer/sensors/+
The wildcard translates to the subtopics SENSOR, LWT, INFO1, INFO2, INFO3, STATE and STATUS of which I want to use SENSOR and INFO2.
The function node has this code to extract temperature values
msg.payload = {
"DateTime": msg.payload.Time,
"Tr": msg.payload['DS18B20-1'].Temperature,
"Ta": msg.payload['DS18B20-2'].Temperature,
"Tk": msg.payload['DS18B20-3'].Temperature
};
msg.payload.Td = parseFloat((msg.payload.Ta - msg.payload.Tr).toFixed(1));
return msg;
Since only the subtopic SENSOR contains this payload and there is no distiction between the messages of the subtopics, the others throw an error.
The SENSOR message results in something like this:
29-10-2024, 09:34:14[node: debug 9]
tele/thuis/bgg/tuinkamer/sensors/SENSOR : msg.payload : Object
object
DateTime: "2024-10-29T09:33:17"
Tr: 18.6
Ta: 18.6
Tk: 18.4
Td: 0
But the others (LWT, INFO1, INFO2, etc), repeated for every subtopic, all result in this:
29-10-2024, 09:34:14[node: Tr, Ta, Tk, Td]
function : (error)
"TypeError: Cannot read properties of undefined (reading 'Temperature')"
I tried a switch node to seperate the different messages based on msg.topic like this
but I can't get that to work.