The value of trigger is a range, how do I write it?

I search for a while but couldn’t finde it. I think I did not search right or with the right keywords, because I can’t imagine that my question is new. So maybe you could advise me where I can finde an answere or maybe giving me the answere here :slight_smile:

I do have a Luftentfeuchter in my basment, as soon as the water tank is full I get a push. I do that with a homematic power plug. As soon as current is 2.00 I will reciev a message. Normaly if it is off the current is 0 and if it is on the current is around 2340.
Curent is changing constantly, so 2.00 is not alway true it is a range between 1.00 and 2.00.

I don’t know how to define a range for the value.

rule "Luftentfeuchter bitte Tank leeren"
when
	Item K_Basement_Current changed
then
	if (K_Basement_Current.state == 0.00 ) {
	if (K_Basement_Current_timer!==null) {
		K_Basement_Current_timer.cancel
		K_Basement_Current_timer=null
	}
}
else if (K_Basement_Current.state == 2.00) {
	if (K_Basement_Current_timer === null) {
		K_Basement_Current_timer=createTimer(now.plusSeconds(30)) [
			sendTelegram("bot1", "ACHTUNG: Luftentfeuchter bitte Tank leeren!!!")
			]
	}
}
end 

the line should be K_Basment_Curent between 1.00 and 2.00, but how to write it correctly?

else if (K_Basement_Current.state == 2.00) 

As I said, if someone can point me where I can read the information that I want, this would be awsome.

Thanks for the help

What is the Item definition for K_Basement_Current? The rule will be different if it’s state is a QuantityType or DecimalType. If you define it in the UI, then post a line from the event.log when it is changing value.

item is

Number    K_Basement_Current                    "Luftentfeuchter strom"                     <power>         (K_Basement, gPower)                   ["Power"]                {channel="homematic:HmIP-PSM-CH:XXXXXX:6#CURRENT"}

It is not in the UI, it is only for trigering the push

Assuming 1.00 and 2.00 are to be included in the range…

else if (K_Basement_Current.state >= 1 && K_Basement_Current.state <= 2) {

awsome, thanks verymuch.
I couldn’t finde this in the documentation. Can you advise me a place to read things like this? I would like to be able to finde piece of codes like this you gave me.

2 Likes

The best place is to look for them in the forum… or to ust ask :wink:. There are some very basic programming concepts that have never made it into the documentation. Now that you have found what you needed, maybe you could add it to the docs to make it easier for others to find. Here is a helpful resource for use with the old rules DSL and the obscure (and nearly dead) language that it uses… https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html.

It is much easier to learn and find information for real scripting languages, like Python. These can be used with the new rule engine and scripted automation. For now, the easiest way to get started is…

In case you choose to use the new rule engine, here is your rule converted to Jython to get you started…

from org.joda.time import DateTime

from core.rules import rule
from core.triggers import when
from core.actions import ScriptExecution, Telegram

K_Basement_Current_timer = None

def scriptUnloaded():
    # This function is called when each script is unloaded and is a nice way to cleanup timers
    if K_Basement_Current_timer is not None and not K_Basement_Current_timer.hasTerminated():
        K_Basement_Current_timer.cancel()

@rule("Luftentfeuchter bitte Tank leeren")
@when("Item K_Basement_Current changed")
def current_check(event):
    if items["K_Basement_Current"] == DecimalType(0):
        scriptUnloaded()
    elif items["K_Basement_Current"] >= DecimalType(1) and items["K_Basement_Current"] <= DecimalType(2):
        if K_Basement_Current_timer is None or K_Basement_Current_timer.hasTerminated():
            K_Basement_Current_timer = ScriptExecution.createTimer(DateTime.now().plusSeconds(30), lambda: Telegram.sendTelegram("bot1", "ACHTUNG: Luftentfeuchter bitte Tank leeren!!!"))
1 Like

Wow, thanks verymuch, I’m a beginner as you noticed :wink: , so this is awsome to start learning.
Is Jython going to take over or is it more going to be a addon?

I just started a couple of days ago with OH, so I’m descovering this new world :slight_smile:

Thanks for your help and patience

Is Jaython also compatible with visual studio code? For me it is veryhelpfull this visualisastion in VSC.

I submitted Jython and the helper libraries for openHAB Core back before OH 2.5, but the maintainers decided to not include it. I then submitted them separately as add-ons, so maybe some day! Until then you can install through the jar. I will be updating this soon, along with a bunch of updates to the helper libraries and an update to Jython 2.7.2.

You are very welcome! There is a learning curve, but it is very much worth it. Learn and then give back to the community!

Currently, the OH extension for VSC does not do anything with Jython. However, you can use Pylint in VSC, which is very helpful. You’ll also find a .pylintrc file in the helper library repo. I will push some docs soon with more info on how to configure it, but you can find some info in the forum.

If you have questions, just ask! If it is about Jython, tag your post with it and I will get a notification.

1 Like