tl;dr: If you have a Number:Temperature
that Item’s state is always going to have a unit. In OH 4 the only way to have a state without a unit is if it’s a Number
or the state is NULL
or UNDEF
.
There is a unit
property on the MQTT Channel where you can supply the unit.
Since you’ve not defined unit
metadata on the Item, what ever unit MQTT supplies ill be converted to that unit
if it’s not already (e.g. is °F is published as the state update, that value will be converted to °C when the Item is updated if the default for your locale is SI units).
If there is no unit published in the state update, the system default unit is assumed.
Setting the label in your .items file does nothing to define the unit carried by the Item.
This is irrelevant to any unit related error coming from a rule.
You can configure the MQTT Channel to supply units.
[rant] If you are using .things files and didn’t know this property existed, well that’s why I don’t support people with text based config problems any more. All that time you think you are saving gets lost fighting problems like these because the text files are not self documenting. [/rant]
But even if the Channel doesn’t post update with a unit, your Item is going to have a unit no matter what because it’s a Number:Temperature
. Either it’s going to be the system default or it’s going to be what you’ve set the unit
metadata to.
A unit is already being added even with your current config. Right now you are depending on the system default. But you can fix it by setting the unit
metadata on the Item. You should also set it in the MQTT Channel so that OH doesn’t just assume the unit matches the Item’s unit.
If the unit of the number matches the unit of the Item, nothing will change for persistence. If it’s different you probably would have noticed before now. But that is a problem when working with units in OH 4+. Since the unit is not stored in persistence, if you change the unit of the Item it will not convert the old values already stored in persistence to match the new unit.
Nothing, the unit is not stored in persistence, only the number is. Where you run into trouble is if you were using °F before and change the unit
to °C later, all those previous values stored in persistence will be treated as if they were always °C. They don’t get converted.
Why can’t you change it?
Why can’t you change it?
Indeed if they don’t both have units, you need to change the if statement to either add a unit to the one lacking or remove the unit from the one that has units. But better would be the fix the Item to carry units in the first place.
Are you sure you don’t have an Item that’s NULL or UNDEF or something because this would have always been a problem, even as far back as OH 2.5.
Better to set ESP82661temp
to carry units. And in fact, based on that line from the .items file, it already is carrying units. Are you sure it’s not NULL
?
Back to my original reply,
Log out the states of these Items when the rule runs and see what the states are when it fails.