Yes, Despite its name, your txtTestItem
is actually a Number:Temperature type Item, so I would expect commands to include a unit. That’s exactly how it is supposed to work.
Yes. You can link a a Number:Temperature type Item to a string type MQTT channel. The channel will pass along the string version of the Number:Temperature command, so you’ll see payload 20.0 ºC
This is working exactly as intended.
It’s doing what you told it to do.
It is possible to apply transformation to alter the command before putting it in the topic.
Your tempTestItem
is also a Number:Temperature type Item,
Technically, command 20 is faulty for this Item type - a unit is required.
I’m honestly not sure how you managed to load the Item state with 25 without units to begin with - a system default unit should appear - but that would be why the slider generates commands without.
Anyway, this Item state deals in “quantities”, numbers with units - so it will pass “20 + blank unit” to the MQTT channel.
This time the channel is a number
type, it is going to try to process that quantity, not convert it to a string first.
What is also different about it is the parameter
formatBeforePublish: "%.1f"
As we discussed already, I would definitely expect that to choke and fail with a quantity like “20 °C” with proper units.
I really wouldn’t like to predict what happens here though - technically “20 + blank unit” is a valid quantity (just not for a temperature). It means 20-to-1 ratio, or 2000%. Quite how this is going to interact with your max
and min
values I have no idea.
I’m going to guess commanding 20 gets added to min, giving 25? (and so nothing to do with old value) Try it, command 15.
The point of all this, is that this is all broken. Not because of bugs but because of bad data to begin with. You can’t just hook up a Number:Temperature Item to a number channel without doing something about units.
So, what do you really need here?
Great. Simplify.
Never mention units
in your MQTT channel, or you will get them in published messages.
Get rid of max
and min
in the channel. These are about scaling, not limit restraints. The device will tell you what it wants to tell you in inbound messages. If you want to limit the commands that you publish, this should be done at source - the UI slider or rule generating the commands.
So that leaves -
- id: tempTest
channelTypeUID: mqtt:number
label: Temperature test (number)
description: ""
configuration:
commandTopic: cmnd/testThing/TRV/valve1/settemp
stateTopic: stat/TRV/valve1/state
transformationPattern: JSONPATH:$.temp
For the simple solution, link that to a Number type Item. Not a Number:Temperature.
Try it.
The more elegant solution would be to use the number
channel with a Number:Temperature
Item, but that will require more effort to add/remove units along the way. Satisfy yourself that a plain Number works first.