Dear all,
I am pretty new to openHAB and I am currently struggeling with a rule execution. I’d like to change the color setting of my HUE lamp depending on the content of a string item (here ‘WeatherWarningString’) of the DWD Unwetter binding. The rule is as follows:
rule “Define Weather Event”
when
Item SwitchX changed to ON // SwitchX is triggered in a separate rule by an event channel
then
if (WeatherWarningString.contains(“Storm”)) {
var DecimalType hueINT = new DecimalType(120)
var PercentType saturationINT = new PercentType(100)
var PercentType brightnessINT = new PercentType(100)
var HSBType changeCol = new HSBType(hueINT, saturationINT, brightnessINT) }
else {
var DecimalType hueINT = new DecimalType(360)
var PercentType saturationINT = new PercentType(100)
var PercentType brightnessINT = new PercentType(100)
var HSBType changeCol = new HSBType(hueINT, saturationINT, brightnessINT) }
ColorX.sendCommand(changeCol)
end
Executing the rule leads to the following error message:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Define Weather Event’: ‘contains’ is not a member of ‘org.eclipse.smarthome.core.library.items.StringItem’;
I have checked recent posts on this forum, on whether I am missing to load an additional library, but could not found any solution.
I am using openHAB 2.4.0 release on a raspberry pi 2.
An Item is an object with name, label, etc. properties. You would presumably be interested in its state property.
State may not have all the methods of a regular string variable, I don’t know, so to be safe I’d get the string conversion anyway.
Thanks for your quick reply. Unfortunately neither
if (WeatherWarningString.state.contains(“Storm”)) nor
if (WeatherWarningString.state.toString.contains(“Storm”)) worked.
With “state.toString” a second error message appears:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Define Weather Event’: ‘contains’ is not a member of ‘org.eclipse.smarthome.core.types.State’;
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Define weather event’: Script interpreter couldn’t be obtain
The toString problem seems to be fixed now. The above error message does not occur any longer. Unfortunately I stumbled over another problem with my rule.
rule "Define Weather Event"
when
Item Kueche_Schalter changed to ON
then
if (WarningLichTyp.state.toString.contains("Sturm")) {
var DecimalType hueINT = new DecimalType(120)
var PercentType saturationINT = new PercentType(100)
var PercentType brightnessINT = new PercentType(100)
var HSBType lightOBJ = new HSBType(hueINT, saturationINT, brightnessINT)
}
if (WarningLichTyp.state.toString.contains("Gewitter")) {
var DecimalType hueINT = new DecimalType(360)
var PercentType saturationINT = new PercentType(100)
var PercentType brightnessINT = new PercentType(100)
var HSBType lightOBJ = new HSBType(hueINT, saturationINT, brightnessINT)
}
if (WarningLichTyp.state.toString.contains("Frost")) {
var DecimalType hueINT = new DecimalType(240)
var PercentType saturationINT = new PercentType(100)
var PercentType brightnessINT = new PercentType(100)
var HSBType lightOBJ = new HSBType(hueINT, saturationINT, brightnessINT)
}
else {
var DecimalType hueINT = new DecimalType(360)
var PercentType saturationINT = new PercentType(0)
var PercentType brightnessINT = new PercentType(100)
var HSBType lightOBJ = new HSBType(hueINT, saturationINT, brightnessINT)
}
sendCommand(Kueche_Farbe,lightOBJ)
end
This code results in
2019-10-19 19:46:13.621 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Weather.rules', using it anyway:
The value of the local variable lightOBJ is not used
The value of the local variable lightOBJ is not used
The value of the local variable lightOBJ is not used
The value of the local variable lightOBJ is not used
Could there be something wrong with my if-else statements?
rule "Define Weather Event"
when
Item Kueche_Schalter changed to ON
then
var DecimalType hueINT = null
var PercentType saturationINT = null
var PercentType brightnessINT = null
var HSBType lightOBJ = null
if (WarningLichTyp.state.toString.contains("Sturm")) {
hueINT = new DecimalType(120)
saturationINT = new PercentType(100)
brightnessINT = new PercentType(100)
}
if (WarningLichTyp.state.toString.contains("Gewitter")) {
hueINT = new DecimalType(360)
saturationINT = new PercentType(100)
brightnessINT = new PercentType(100)
}
if (WarningLichTyp.state.toString.contains("Frost")) {
hueINT = new DecimalType(240)
saturationINT = new PercentType(100)
brightnessINT = new PercentType(100)
}
else {
hueINT = new DecimalType(360)
saturationINT = new PercentType(0)
brightnessINT = new PercentType(100)
}
lightOBJ = new HSBType(hueINT, saturationINT, brightnessINT)
Kueche_Farbe.sendCommand(lightOBJ)
end
Thanks a lot, that solved the problem. I only had to change
else {
hueINT = new DecimalType(360)
saturationINT = new PercentType(100)
brightnessINT = new PercentType(100)
}
to
if (WarningLichTyp.state.toString.contains("NULL")){
hueINT = new DecimalType(360)
saturationINT = new PercentType(100)
brightnessINT = new PercentType(100)
}
because that is the name of the weather warning type if no alarm is active.