- Platform information:
- Hardware: CPUArchitecture/RAM/storage / Raspberry pi 4b
- OS: _what OS is used and which version_Openhabian
- Java Runtime Environment: which java platform is used and what version
- openHAB version: 3.2
- Issue of the topic: newState gives a wrong value
I changed a lot of my rulesDSL code last from item.state to newState. I noticed that after an item received update, sometimes the item.state isn’t at that state at that moment. So i thought of using newState, that should be right. Now the strangest thing happens this evening.
I use a number item Woonkamer_Preset to set my heating at home (it changes the themostat according to a preset). Woonkamer_Preset can also enable my electric heating when the solar panels generate power and Central Heating when not, sort of, long story… The Woonkamer_Preset trigger reacts on the state change of item Woonkamer_Preset and UseCV item as shown in the code below. It works right after saving the rule file, but after the item UseCV changes to ON or OFF (Switch item) and after that I change Woonkamer_Preset, the newState gives value ON in stead of 1,2,3 etc. I don’t understand why. I thought newState would be the last state of the item that changes. Below is my code how i wrote it:
rule "12 - Thermostaat Preset"
when
Item Woonkamer_Preset received update or
Item UseCV changed
then
var Number numPreset
logInfo("Verwarming","Woonkamer_Preset: " + Woonkamer_Preset.state + " / trigger = " + triggeringItemName.toString)
if (triggeringItemName == "Woonkamer_Preset"){
if (newState == ON){
sendSmartHomeNotify("Newstate lijkt vreemde waarde te hebben: ON. Woonkamer_Preset: " + Woonkamer_Preset.state + " / trigger = " + triggeringItemName.toString)
}
numPreset = (newState as DecimalType).intValue
}
if (triggeringItemName == "UseCV"){
numPreset = (Woonkamer_Preset.state as DecimalType).intValue
}
This is what my log shows:
2022-04-04 22:44:27.699 [INFO ] [org.openhab.core.model.script.Verwarming Woonkamer_Preset: 2 / trigger = Woonkamer_Preset
2022-04-04 22:44:27.701 [ERROR] [ation.module.script.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'mr_verwarming-10' failed: Could not cast ON to org.openhab.core.library.types.DecimalType; line 236, column 22, length 23 in mr_verwarming
So I changed the trigger part to:
Item Woonkamer_Preset received update or
Item UseCV received update
And now it looks like it works but i’m not completely convinced.
Does anyone know if this is intended behaviour or is it a bug in the rules system?