I was expecting raw to work, however using raw throws an error in my reactor.log file:
[stable-23078]2023-05-16T11:27:22.250Z <MQTTController:WARN> expression has run, result 20
[stable-23078]2023-05-16T11:27:22.250Z <MQTTController:INFO> MQTTController#mqtt perform hvac_cooling_unit.set_setpoint on MHI_AC_1: publishing ezlo_mqtt/set/item/MHI-AC-Woonkamer/set/Tsetpoint 20
[stable-23078]2023-05-16T11:27:22.254Z <wsapi:CRIT> TypeError: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received type number (20) [-]
TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received type number (20)
at new NodeError (node:internal/errors:372:5)
at Function.byteLength (node:buffer:735:11)
at publish (/var/reactor/ext/MQTTController/node_modules/mqtt-packet/writeToStream.js:334:51)
at Object.generate [as writeToStream] (/var/reactor/ext/MQTTController/node_modules/mqtt-packet/writeToStream.js:34:14)
at sendPacket (/var/reactor/ext/MQTTController/node_modules/mqtt/lib/client.js:176:29)
at MqttClient._sendPacket (/var/reactor/ext/MQTTController/node_modules/mqtt/lib/client.js:1250:7)
at publishProc (/var/reactor/ext/MQTTController/node_modules/mqtt/lib/client.js:659:14)
at MqttClient.publish (/var/reactor/ext/MQTTController/node_modules/mqtt/lib/client.js:665:74)
at /var/reactor/ext/MQTTController/MQTTController.js:616:25
at new Promise (<anonymous>)
As you can see, I try to publish the raw value 20 to topic ezlo/.../Tsetpoint which fails as the number is not a string (so far for untyped behaviour of js..)
Both your alternatives, using json or raw with the str() expression work flawlessly. I'll remove my unneeded changes in the code!