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

Hi,
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)
192.168.30.211.1883 > 192.168.30.207.54143: 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;
if(speed==0){
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
Bye
Marcello

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).

Hello,
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
Bye

Yes, I can reproduce this too :sob:

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

I have been spending some time on this problem too… A space is added after the “Tag” resulting in 2 channels with (what seems like) the same channel ID with MQTT, but are actually 2 different names.

Reproduce :
Make a Logic variable name : “Mqtt Command Topic”
Set it to type “Text” and fill it with “HomeyCommand”

Then use the MQTT-Client app to make a flow that Writes in this topic using the variable tag we just made “Mqtt Command Topic”.
Then we also Listen to this same Topic using the same variable tag “Mqtt Command Topic”

With an Laptop running MQTT Explorer, I also write to Topic “HomeyCommand”.
I now see 2 channels with this same ID, only one seems to have a space character behind the ID.

The channel homey is “listening to” seems to be the correct one without a space, but the topic it is wiring to using the same tag appears to add a space behind it.

Work-Around : This problem seems only when using the Homey Android App. Doing it in https://my.homey.app/ lets you place tags without spaces, or even remove the space after the tag when you added the tag using your mobile App

Request : I would really appreciate it if we can remove the “spaces” in front and ofter tags ourselfs…