Homey Community Forum

Flow to publish an MQTT message add a white space to tag

I connected an ESP32 system of my realization to homey to read and set PWM fan speed values. The ESP32 is connected using MQTT Broker to homey.
I’m using a Flow to set a value to the MQTT Topic using a Tag. I use an homey script to do the job and seems that the Flow itself is adding a white space between the name of the topic and the value I set.
I have a Virtual Device (Dimmer) that I intercept the value in the script and create a Tag from script to be sent as value to the topic.
Topic is fan/setSpeed and values are between 0 to 4 based on the value of the dim capability. The script set a Tag named RetSpeed with the value and publish to the topic.
I made a tcpdump of the value and I see that a white space is inserted between the topic and the value.

************** TCPDUMP OUTPUT **********************
01:35:07.746899 IP (tos 0x0, ttl 64, id 1580, offset 0, flags [DF], proto TCP (6), length 70) > Flags [P.], cksum 0x337c (correct), seq 31255:31273, ack 47, win 453, options [nop,nop,TS val 630292761 ecr 2941428222], length 18
0x0000: 4500 0046 062c 4000 4006 7593 c0a8 1ed3 E…F.,@.@.u…
0x0010: c0a8 1ecf 075b d37f 065f 6f1c f367 6451 …[…_o…gdQ
0x0020: 8018 01c5 337c 0000 0101 080a 2591 8119 …3|…%…
0x0030: af52 a1fe 3010 000c 6661 6e2f 7365 7453 .R…0…fan/setS
0x0040: 7065 6564 2034 peed.4

As you can see there is a space (hex char 20) between the topic fan/setSpeed and the value 4.

This is the script I’m using:

var floatSpeed = parseFloat(args[0]);
var setSpeed = 4;
var speed=256*floatSpeed;
var setSpeed=0;
if(speed>0 && speed<=62) {
var setSpeed=1;
if(speed>=63 && speed<=126) {
var setSpeed=2;
if(speed>=127 && speed<=191) {
var setSpeed=3;
if(speed>=192 && speed<=255) {
var setSpeed=4;
await setTagValue(“RetSpeed”, {type: “number”, title: “RetSpeed”}, setSpeed);
return true;

If I set the value manually not using the Tag in the flow the value is correct. Even if I set it using an MQTT Explorer to publish the value it is correct. It is wrong only when I use the Flow.

Any suggestions?
Thank you in advance

If you created the flow using the web editor (https://flow.homey.app), try creating it (or at least the “publish” part) in the mobile app. The web editor has lots of bugs related to handling tags, and this seems to be one of them (I can replicate it).

thank you for the suggestion. Effectively I created it using the web interface but unfortunately doing it from the mobile phone is the same. It seems to be a bug of both interfaces. I tried with the publish function advanced too and it is adding the space after the value and not before. It is joking me :frowning: .
Thank you

Yes, I can reproduce this too :sob:

Fine… I managed to discard the space on the ESP32 code.
Thank you for help.