Hi, due to Fibaro being totally rubbish, I have to write my own dimmer rules (problems with association groups etc). I’m getting errors on this rule, any ideas?
var buttonDown = false
val intensity = 0
rule "Long press"
when
Item nursery_scene_s2_hold received update
then
buttonDown = true
intensity = nursery_light_lamp.state
while(buttonDown){
// increment or decrement dimmer by 10
intensity = intensity - 10
sendCommand(nursery_light_lamp, intensity)
Thread::sleep(100) // experiment with the value to control dimming speed
}
end
rule "button released"
when
Item nursery_scene_s2_release received update
then
buttonDown = false
end
2016-01-05 00:06:07.597 [INFO ] [runtime.busevents ] - nursery_scene_s2_hold state updated to ON
2016-01-05 00:06:07.645 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Long press': org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [JvmVoid: (eProxyURI: nursery.rules#xtextLink_::0.2.0.2.0.0::0::/1), buttonDown , true, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@3ba41050, org.eclipse.xtext.util.CancelIndicator$1@1c118b8f]
2016-01-05 00:06:09.517 [INFO ] [runtime.busevents ] - nursery_scene_s2_release state updated to ON
2016-01-05 00:06:09.544 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'button released': org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [JvmVoid: (eProxyURI: nursery.rules#xtextLink_::0.2.1.2.0.0::0::/1), buttonDown , false, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@100fcb9a, org.eclipse.xtext.util.CancelIndicator$1@1c118b8f]
The error indicates it can’t find a way to assign the new value to buttonDown. I think the problem can be fixed if we explicitly tell it that buttonDown is a boolean.
Ok I think I’m really close, thanks for the help.
Here is my current rule:
var boolean buttonDown = false
var int intensity = 0
rule "Long press"
when
Item nursery_scene_s2_hold received update
then
buttonDown = true
intensity = nursery_light_lamp.state as DecimalType
while(buttonDown){
// increment or decrement dimmer by 10
intensity = intensity - 10
sendCommand(nursery_light_lamp, intensity)
Thread::sleep(100) // experiment with the value to control dimming speed
}
end
rule "button released"
when
Item nursery_scene_s2_release received update
then
buttonDown = false
end
And this is the error in OHDesigner. Where am I messing up the syntax?
Hmm, I still get errors in OHDesigner.
If I remove the capture of current state and just set the value, then the dimming rule works, although I think there’s going to be further questions at some point after a bit more reading; Like it won’t exist immediately I let go. So say I’ve held it for 60 iterations, but it’s only dimmed for 10 iterations when I let go, it’ll still cycle through the rest. I’m sure there’s a better way of doing this.
Just as an update to this, I got annoyed at it all and sacked it off, going to the source of the problem (the hardware) and I think I’ve fixed the problem I was having, so no longer need to write rules to control the dimming directly.
The above imports didn’t work for me still, however, now I’ve removed all my rules and written another one (a less complicated, “goodnight” mode for the nursery where it just dims all lights down over 15 minutes) and it works fine.
In that one I just used “var Number myNum” and it gave no warnings. “var int myNum” wasn’t working in the previous one.
When I return to it at a later date (probably when OH2 is released) I’ll update so any other beginners might get something useful from it.