In preparation for my OH upgrade, it appears units of measurement are required.
I have a lot of textual configuration and rules, almost none of which uses units for the number variables (and aren’t declared as a temp/power/etc).
As a test, I decided to try set up a new-ish item file and rule, and am running into errors:
Items:
Number:Temperature CNCRoom_TargetTemperature "CNC Room Target Temperature" { unit="°C" }
Number:Temperature ShopLowWorkingTemperature "CNC Low Working Temperature" { unit="°C" }
Number:Temperature ShopHighWorkingTemperature "CNC High Working Temperature" { unit="°C" }
Rules:
rule "Adjust CNC Sonoff Temperatures"
when
Item CNCRoom_TargetTemperature received update
then
logInfo("shopheaters.rules", "Starting Shop Heater Target Temp Change Rule")
logInfo("shopheaters.rules", "Received temperature: " + CNCRoom_TargetTemperature.state)
logInfo("shopheaters.rules", "Received temperature as number: " + (CNCRoom_TargetTemperature.state as Number))
var Number TargetTemp
TargetTemp=(CNCRoom_TargetTemperature.state as Number)
logInfo("shopheaters.rules", "Target temperature changed to: " + TargetTemp)
sonoffCNCRoom_TriggerTemperature.sendCommand(TargetTemp)
sonoffCNCRoom_StopTemperature.sendCommand(TargetTemp+1)
end
Logs (when changing Target Temperature via a slider in the UI):
2023-10-29 22:26:10.419 [INFO ] [openhab.event.RuleStatusInfoEvent ] - shopheaters-1 updated: RUNNING
2023-10-29 22:26:10.421 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CNCRoom_TargetTemperature' changed from 10 °C to 11 °C
==> /var/log/openhab/openhab.log <==
2023-10-29 22:26:10.423 [INFO ] [.core.model.script.shopheaters.rules] - Received temperature: 11 °C
2023-10-29 22:26:10.427 [INFO ] [.core.model.script.shopheaters.rules] - Received temperature as number: 11 °C
2023-10-29 22:26:10.431 [INFO ] [.core.model.script.shopheaters.rules] - Target temperature changed to: 11 °C
==> /var/log/openhab/events.log <==
2023-10-29 22:26:10.435 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'sonoffCNCRoom_TriggerTemperature' received command 11 °C
2023-10-29 22:26:10.440 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'sonoffCNCRoom_StopTemperature' received command 285.15
2023-10-29 22:26:10.511 [INFO ] [openhab.event.RuleStatusInfoEvent ] - shopheaters-1 updated: IDLE
2023-10-29 22:26:10.514 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'sonoffCNCRoom_TriggerTemperature' predicted to become 11 °C
2023-10-29 22:26:10.521 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'sonoffCNCRoom_StopTemperature' predicted to become 285.15
2023-10-29 22:26:10.529 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'sonoffCNCRoom_TriggerTemperature' changed from 10 °C to 11 °C
2023-10-29 22:26:10.529 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'sonoffCNCRoom_TriggerTemperature' received command 11
2023-10-29 22:26:10.531 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'sonoffCNCRoom_StopTemperature' changed from 284.15 °C to 285.15 °C
2023-10-29 22:26:10.532 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'sonoffCNCRoom_TriggerTemperature' predicted to become 11
==> /var/log/openhab/openhab.log <==
2023-10-29 22:26:10.533 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '' not supported by type 'NumberValue'
It appears that the StopValue is in Kelvin? In DSL is there a way to do this better? Do I need to force the unit to Celsius for every mathematical operation? For this rule it wouldn’t be much, but some of my other rules/files - ugh!
(For context, TriggerTemperature is when the heater is triggered to turn on. StopTemperature is when the heater turns off)
When I change the last line in the rule to:
sonoffCNCRoom_StopTemperature.sendCommand(TargetTemp+1|°C)
I get an even worse stop temp of * 558.3 °C for a target temp of 11°C
Now, fortunately, I have the mqtt channel requires values between 1 and 40, so I don’ need to worry about burning my shop down…
I’ve tried reading through much of the units of measurement discussion on here, but haven’t come up with a solution yet. Do I need to ditch the Number:Temperature and use QuantityType?
If onerous, do I really need to make this change over for my old scripts/items that I know all operate in celsius and have rules that presume this, or can I leave them as dimensionless/unitless Number variables before the big upgrade from OH 3.4.2 to 4.0, or will this break things?
Thanks!