rule "Change Ceiling Light to White"
when
Item Switch00Lux received update
then
if ( Switch00Lux.state < 10 ) {
logInfo("Lumination", "it's getting to dark, illuminating!")
Bridge1_CH2_White.sendCommand(ON)
}
else if ( Switch00Lux.state > 9 ) {
logInfo("Lumination", "it's illuminated already")
}
else logInfo("Lumination", "this rule does not function :(")
end
I tried to figure out by myself what’s going wrong but with no luck…
The rule gets fired everytime my Item sends an update.
The Item publishes a state.
So I think the problem is the if clause. I don’t know the right syntax.
I also tried:
if ( Switch00Lux.state < "10" ) {
if ( Switch00Lux.state < '10' ) {
if ( Switch00Lux.state.toString < 10 ) {
if ( Switch00Lux.state.toString < "10" ) {
if ( Switch00Lux.state.toString < '10' ) {
if ( Switch00Lux < "10" ) {
state.toString causes an error in events log so this will definately not work. but I still dont know if and how I can use less-than / more-than signs.
==> /var/log/openhab2/openhab.log <==
2019-01-27 18:10:27.885 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'luminance.rules' has errors, therefore ignoring it: [6,40]: no viable alternative at input '10'
I get the above when trying with “as Number” in the if clause…
Not sure if this will make a difference but you can try it.
rule "Change Ceiling Light to White"
when
Item Switch00Lux received update
then
var lux = Switch00Lux.state as Number
if ( lux < 10 ) {
logInfo("Lumination", "it's getting to dark, illuminating!")
Bridge1_CH2_White.sendCommand(ON)
}
else if ( lux > 9 ) {
logInfo("Lumination", "it's illuminated already")
}
else logInfo("Lumination", "this rule does not function :(")
end
Will the item still work if you change it from a String to a Number?
Number Switch00Lux "Illuminance" <sunrise> (gSwitch_1) { channel="mqtt:topic:Switch00:illuminance" }
==> /var/log/openhab2/openhab.log <==
2019-01-27 18:59:16.810 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Change Ceiling Light to White': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_lessThan(java.lang.Number,java.lang.Number) on instance: null
==> /var/log/openhab2/openhab.log <==
2019-01-27 19:04:16.940 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Change Ceiling Light to White': Could not cast 127 to java.lang.Number; line 5, column 19, length 27
Ithink i tried with val as i mentioned but will give it another try… ahh btw with or without the int data type? you left it away in your edit… so I’m unsure