I am now searching for 4 hours to create a rule for my light at the house entrance and i am still getting from one problem to the next. I’m starting to feel like I’m making one syntax error after another; sometimes (with omissions of components), it worked halfway. But only halfway.
To my setup:
Above the front door sits the patio lamp (HUE). This is controlled by Hue’s own motion detector.
BUT this lamp should also light red or green for about 10 seconds if an action was detected with the door itself. In the best case, of course, the lamp after its red or green phase should return to the previous state, so that the motion detector is not limited in its function. BUT: that’s optional. I would already be satisfied with that, if it just ONLY 10 seconds lit and then go out again.
Incidentally, the action is as follows: I have an Ekey finger scanner as an access solution. The activity of this is already recorded successfully.
If a finger is pulled over it which is not registered, the lamp should light up red.
When a known finger unlocks the door the lamp should light green.
But only for just 10 seconds …
The motion detector function should not be disturbed by this. (Expire function for example… It would turn off this lamp always after 10 seconds, if it is lit … But the motion detector should be about 2 minutes on).
The code so far created:
rule Ekey-Eingang
when
Item Action received update
then
if (Action.state==-1)
Terrasse.sendCommand("352,100,100")
createTimer(now.plusSeconds(8) [| Terrasse.sendCommand("0,0,0") ]
else {
Terrasse.sendCommand("125,100,100")
createTimer(now.plusSeconds(15) [| Terrasse.sendCommand("0,0,0") ]
var String name = transform("MAP","ekey_names.map",UserID.state.toString())
var String text = " Hallo "+name
Echo_Kueche_TTS.sendCommand(text)
}
end
IF “createTimer” is NOT listed, the whole thing works wonderfully … BUT the lamp burns then constantly.
It’s really worthwhile to use VSCode editor with openHAB extension. Yet another piece of software to run, something else to learn, and it will save you hours of time.
rule EntryCode
when
Item Action received update
then
if (Action.state==-1) {
Terrasse.sendCommand("352,100,100")
createTimer(now.plusSeconds(7). [| Terrasse.sendCommand("0,0,0") ])
} else {
Terrasse.sendCommand("125,100,100")
createTimer(now.plusSeconds(10). [| Terrasse.sendCommand("0,0,0") ])
var String name = transform("MAP","ekey_names.map",UserID.state.toString())
var String text = " Hallo "+name
Echo_Kueche_TTS.sendCommand(text)
}
end
Buuuuut: no actions. No Alexa (Echo_Kueche_TTS) speaking, no Light lit.
What am I missing or what is wrong in this setup?!
Here is the Log:
2019-11-17 03:21:43.741 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'ekey.rules' has errors, therefore ignoring it: [7,35]: no viable alternative at input '['
[10,35]: no viable alternative at input '['
Bad syntax.
createTimer has two parameters createTimer (x , y)
Use a comma , not a stop .
I repeat the advice to use VSCode editor and save your own time, it catches these mistakes.
What are you expecting to happen here?
createTimer(now.plusSeconds(10), [| Terrasse.sendCommand("0,0,0") ])
var String name = transform("MAP","ekey_names.map",UserID.state.toString())
var String text = " Hallo "+name
Echo_Kueche_TTS.sendCommand(text)
This will set up a timer for 10 seconds in the future.
It will immediately send the Hallo text command.
Then the rule will end.
Ten seconds later, the timer will run and send the Terrase command.
Is this what you intended? The indenting is a bit misleading, the String lines are not part of the timer above.
Using the simple createTimer(x,y) idea, y is the block of code to run.
We usually define y inline, using the the format [ | some code ]
The code can be multiline
[ |
//some code
// more code
]
So putting it together,
createTimer(now.plusSeconds(10), [ |
// this code will run in the future
// this is future code too
] )
// this code has nothing to do with the timer
// and runs immediately
In the night i discovered another way how to deal with this rule:
rule EntryCode
when
Item Action received update
then
if (Action.state==-1) {
Terrasse.sendCommand("352,100,100")
Thread::sleep(9900)
Terrasse.sendCommand(OFF)
} else {
Terrasse.sendCommand("125,100,100")
Thread::sleep(3000)
EG_Kueche.sendCommand(ON)
Thread::sleep(3000)
Terrasse.sendCommand(OFF)
Echo_Kueche_TTS.sendCommand("Willkommen.")
}
end
This way seems better for me, because otherwise the things will happen too fast.
The delay-thing is quite perfect here for my needs.
So its just perfect for the timing. I also tried the Code with createTimer; which also works.
This i need now in other rules I already downloaded the VSCode but need some time to study it a bit
It isn’t. The very long series of sleeps uses your host’s resources to do nothing, and prevents other rules from running. Use timers - which use no resources while they wait for their appointed time to come around.