I tried mixing Fahrenheit and Celsius degree. termo1.state, and tc.state are in Celsius degree. tE.state is reported as mqtt-channel property being Fahrenheit, but the system has Metric set as Measurement system (config/org/openhab/i18n.config:measurementSystem="SI"), so this Fahrenheit is converted to Celsius. tF.state is temperature in Fahrenheit, it is enforced by the item link:
Thing mqtt:topic:d {
Type number :termo [stateTopic="a/b/c", transformationPattern="JSONPATH:$.AM2301.Temperature", unit="℃"]
Type number : temperatureC "Реле 2" [stateTopic="m/n/i:0", transformationPattern="JSONPATH:$.temperature.tC", unit="℃"]
Type number : temperatureF "Реле 2" [stateTopic="m/n/i:0", transformationPattern="JSONPATH:$.temperature.tF", unit="°F"]
}
Number:Temperature tC {channel="mqtt:topic:d:temperatureC"}
Number:Temperature tE {channel="mqtt:topic:d:temperatureF"}
Number:Temperature tF {channel="mqtt:topic:d:temperatureF", unit="°F"}
Number:Temperature termo1 [%.1f ℃]" {channel="mqtt:topic:dht22_1:termo", expire="135s,NULL"}
So items tC, tE and tF present the same temperature as feeling.
rule a
when
System reached start level 100
then
logError("A", termo1.state.toString)
logError("B", tC.state.toString)
logError("C", tE.state.toString)
logError("D", tF.state.toString)
logError("E", "value=" + tE.state.toString + " unit " + tE.unit.toString)
logError("F", "value=" + tF.state.toString + " unit " + tF.unit.toString)
logError("G", (termo1.getStateAs(Number) - tC.getStateAs(Number)).toString)
logError("H", (termo1.state as Number - tC.state as Number).toString)
logError("I", (tC.state as Number - tF.state as Number).toString)
val diff1 = termo1.state as QuantityType - tC.state
val diff2 = termo1.state as QuantityType - tE.state
val diff3 = termo1.state as QuantityType - tF.state
val diff4 = tC.state as QuantityType - tF.state
logError("J", diff1.toString + "|" + diff2.toString + "|" + diff3.toString + "|" + diff4.toString)
logError("K", diff1.unit.toString + "|" + diff2.unit.toString + "|" + diff3.unit.toString + "|" + diff4.unit.toString)
logError("L", diff1.class.toString + "|" + diff2.class.toString + "|" + diff3.class.toString + "|" + diff4.class.toString)
end
produces
2026-06-01 14:53:57.174 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading DSL model 'a.rules'
2026-06-01 14:53:57.605 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in DSL model 'a.rules', using it anyway:
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
2026-06-01 14:53:58.012 [ERROR] [org.openhab.core.model.script.A ] - 19.1 °C
2026-06-01 14:53:58.014 [ERROR] [org.openhab.core.model.script.B ] - 41 °C
2026-06-01 14:53:58.016 [ERROR] [org.openhab.core.model.script.C ] - 40.94444444444444 °C
2026-06-01 14:53:58.017 [ERROR] [org.openhab.core.model.script.D ] - 105.699999999999992 °F
2026-06-01 14:53:58.020 [ERROR] [org.openhab.core.model.script.E ] - value=40.94444444444444 °C unit °C
2026-06-01 14:53:58.023 [ERROR] [org.openhab.core.model.script.F ] - value=105.699999999999992 °F unit °F
2026-06-01 14:53:58.027 [ERROR] [org.openhab.core.model.script.G ] - -21.90
2026-06-01 14:53:58.029 [ERROR] [org.openhab.core.model.script.H ] - -21.90
2026-06-01 14:53:58.032 [ERROR] [org.openhab.core.model.script.I ] - 0.0555555555555599999999999999999748724444444444448
2026-06-01 14:53:58.042 [ERROR] [org.openhab.core.model.script.J ] - -21.90 °C|-21.84444444444444 °C|-39.6222222222222177777777777777778 °C|-17.7222222222222177777777777777778 °C
2026-06-01 14:53:58.046 [ERROR] [org.openhab.core.model.script.K ] - °C|°C|°C|°C
2026-06-01 14:53:58.050 [ERROR] [org.openhab.core.model.script.L ] - class org.openhab.core.library.types.QuantityType|class org.openhab.core.library.types.QuantityType|class org.openhab.core.library.types.QuantityType|class org.openhab.core.library.types.QuantityType
So on line I substracting the from a temperature in Celsius the same temperature in Fahrenheit, and casting the state to Number produces zero.
The cast for the differences as QuantityType is required, otherwise the minus sign is an error.
For me diff4 is surprizing, because tC is 41 °C, tF is 105.6 °F, 41 °C is the same as 105.6 °F, so I do not understand why their difference is -17°C