Timed RH Alert from GUI

I would like to create a rule that sends an email alert if the humidity has been higher than x for more than 12 hours. We manage a number of HA systems and are hoping to move our platform over to OpenHAB but I need for people to be able to create rules like this without writing code and I’m hoping the new rule engine will provide this opportunity.

OK, so I wanted to start without the timer just to keep it simple and I did create a rule in the GUI that sends an email when the temp (using that as a proxy for RH right now) gets below a set level. The problem is that the trigger is when the sensor changes state so I get the alert every time the sensor updates instead of just once when the temp crosses the threshold. This is what it looks like:

When = an item state is updated (the temp sensor)
Then = execute a given script (the email script)
But only if = Outdoor Temp is less than x

So I tried something that was actually simpler and I hoped would work but it’s not triggering:

When = an item was changed from state > 39 to < 40

Then = execute a given script (the email script)

code:
triggers:

  • id: “1”
    configuration:
    itemName: Localweatherandforecast_OutdoorTemperature
    state: < 40
    previousState: “> 39”
    type: core.ItemStateChangeTrigger
    conditions: []
    actions:
  • inputs: {}
    id: “2”
    configuration:
    type: application/vnd.openhab.dsl.rule
    script: val mailActions = getActions(“mail”,“mail:smtp:02645bf95b”)
    mailActions.sendHtmlMail(“skye@bpsgreenhomes.com”, “Outdoor Temp Alert”,
    “Outdoor Temp Below 40”)
    type: script.ScriptAction

I did think of just doing this in Blockly because that’s where I’ll end up once I want to add a timer anyway. I did this:

if (‘Localweatherandforecast_OutdoorTemperature’ < 40) {
}

but I couldn’t figure out how to do sendmail from there.

Unfortunately not. You’ll need to write some code to achieve this.

You can’t use greater than/equals in the trigger. You have to put those in a condition (i.e. “But only if…”). So you would trigger when the Item changes and then you can test in the condition whether the current state is over 40 and previous state is under 39. But that is going to require a Script Condition (i.e. some code).

Blockly doesn’t yet support Timers. Hopefully soon but not yet. You can’t call Actions from Blockly either (so no sendMail).

In general this is easily doable with a minimal amount of actual code, but it’s going to require some code.

Thanks Rikoshak, Can you tell me what language Blockly uses? I envision using that to get to a certain place & then adding…

Under the blocks it’s all JavaScript.

Cool, that’s what I was hoping. Time to learn some Java. I’m assuming there is a cache of typical things we use somewhere in here like timers & such.

Java is not JavaScript. They are two completely different languages. Don’t get confused and head down the wrong path. But it gets more complicated because All of the stuff you use to interact with openHAB from Rules is written in Java.

I don’t know what you mean by a cache but there are essentially dozens of examples here and there showing how to do various things in JavaScript rules.

Ah, thanks for clarifying. Yeah I just meant I should be able to find examples of things like a timer without having to actually try and reinvent the wheel.

https://community.openhab.org/search?q=createTimer%20JavaScript