Questions on Rules

  • Platform information: OpenHAB2
    • Hardware: CPUArchitecture/RAM/storage RaspberryPi 4
    • OS: what OS is used and which version Debian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:2

Hi,

I’m a complete beginner here. I’ve also made some progress. I have understood what items and things are, I know the channels and sitemap and rules as well. All devices are set up and also communicate with my PaperUI, I have already managed with external help a rule (window open, then heating to 7 ° C; window closed, then heating to 20 ° C), which looks like this:

`rule "Badheizung auf Frostschutz"

when
Item FF_Bathroom_Window changed
then
if (FF_Bathroom_Window.state == OPEN) {
FF_Bathroom_Heating.sendCommand(7)
}
else {FF_Bathroom_Heating.sendCommand(20)
}
end`

But if I want to create the next rule, then I’ll come back to my limits.

I just want the socket (where the dehumidifier is attached to) to go off at below 55% and back on at over 60%:

Different attempts:

1)
Code:

rule “Entfeuchter”
when
Item C_HomeCinema_Humidity changed
then
if (C_HomeCinema_Humidity >= 60)
{C_HomeCinema_Socket1.sendCommand(on)}
else
if (C_HomeCinema_Humidity <= 58)
{C_HomeCinema_Socket1.sendCommand(off)}
end

Code:

rule “Entfeuchter”
when
Channel “zwave:device:36288293:node6:sensor_relhumidity” changed
then
if (C_HomeCinema_Humidity >= 60)
{C_HomeCinema_Socket1.sendCommand(ON)}
else
if (C_HomeCinema_Humidity <= 58)
{C_HomeCinema_Socket1.sendCommand(OFF)}
end

Code:

rule “Entfeuchter”
when
Channel “zwave:device:36288293:node6:sensor_relhumidity” triggered
then
if (C_HomeCinema_Humidity >= 60)
{C_HomeCinema_Socket1.sendCommand(ON)}
else
if (C_HomeCinema_Humidity <= 58)
{C_HomeCinema_Socket1.sendCommand(OFF)}
end

Code:

rule “Entfeuchter”
when
Channel “zwave:device:36288293:node6:sensor_relhumidity” triggered
then
if (Channel “zwave:device:36288293:node6:sensor_relhumidity” >= 60)
{C_HomeCinema_Socket1.sendCommand(ON)}
else
if (Channel “zwave:device:36288293:node6:sensor_relhumidity” <= 58)
{C_HomeCinema_Socket1.sendCommand(OFF)}
end

Das sind die beiden Items, die ich anspreche:
Code:

Switch C_HomeCinema_Socket1 “Steckdose” (C_HomeCinema, gPower) [“Switch”, “Switchable”] {channel=“zwave:device:36288293:node2:switch_binary”}

und

Code:

Number C_HomeCinema_Humidity “Luftfeuchtigkeit” (C_HomeCinema, gHumidity) ’

Where is my lathe in my mind? What am I doing wrong?

Thanks and regards,
Torsten

Try:

if (C_HomeCinema_Humidity.state >= 60)

EDIT: And welcome to openHAB! :grinning:

1 Like

Hi and thank you.

I think it didn’t work. I have changed the trigger so I can “shoot” the triggering event as often as I want:

rule "Entfeuchter"

when
Channel “network:pingdevice:192_168_178_35:online” triggered
then
if (C_HomeCinema_Humidity.state >= 60)
{C_HomeCinema_Socket1.sendCommand(ON)}
else
if (C_HomeCinema_Humidity.state <= 58)
{C_HomeCinema_Socket1.sendCommand(OFF)}
end

Humidity is over 60 at the moment so the socket should have been switched on… but it doesn’t

And I cannot check the events.log. They are not written since 15:14 o’clock this afternoon… don’t know what happend there, too…

You should add some logging to the rule to confirm whether you are actually entering the rule in the first place. Something like:

logInfo("Entfeuchter", "I'm here!!")

Or something more descriptive at relevant sections in your rule. Then check the logs.

Try to work out why your events log isn’t working. Maybe try an OpenHAB restart?

Where shall I add the logInfo to? at the end of the rule? Or at the beginning?

I have already restartet the system, yes. No change in the events.log

The logs do work again: I have deleted the events.log-file and then restarted the system once again.

It maybe was a fault to delete the first 50.000 lines this afternoon to make the file a little bit easier to read :wink:

All over the place!

rule "Entfeuchter"
when
    Channel “network:pingdevice:192_168_178_35:online” triggered
then
    logInfo("Entfeuchter", "I'm in the rule!")
    if (C_HomeCinema_Humidity.state >= 60){
        logInfo("Entfeuchter", "Humidity is high!")
        C_HomeCinema_Socket1.sendCommand(ON)
    }
    else{
        logInfo("Entfeuchter", "Humidity is low!")
        C_HomeCinema_Socket1.sendCommand(OFF)
    }
end

The other thing to check: are you certain the Item C_HomeCinema_Humidity is working? It has a value? Your original post does not have it attached to a channel…

You don’t need to open the file. Use the command:

tail -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log

In a terminal to get a live view of your logs. More info here: https://www.openhab.org/docs/tutorial/logs.html

And lastly: make sure you are actually able to switch your plug on and off via openHAB in the first place, irrespective of humidity!

1 Like

hmmmm…

Well, I can turn the switch on and off with the PaperUI and the iOS-App as well…

The Humidity-Sensor is working also

I now used your command. But it is hardly readable at one glance:
grafik

Or is this the normal view and I have to get used to it?

Where shall I find the LogInfo that you wrote me? In this log or in another log?

Yep! When you trigger your rule, do you see the custom log lines?

I have triggerd, but I don’t see the custom log lines:

Don’t do that, you’ll mess up the logger (which manages its own archives etc.)

Unfortunately your events.log snippet does not show that.
Does this Item happen to have units?

1 Like

Here: I have blown at it: it works:

Yes, my question was really about whether your Item has units.
For example, your C_HomeCinema_Temperature Item does have units, it is most likely a Number;Temperature type Item.
It’s important, because you need to deal with these Quantity Types (with units) differently in rules.

Okay, so your C_HomeCinema_relHumidity Item does not appear to have units … but I still have doubts because it is probably populated in the same as temperature that does have units?
So, let’s ask directly; what is the type of your humidity Item - Number or Number:Dimensionless ?

The logInfo()s pop up in your openhab.log. You almost always want to keep an eye on that as well as events.log when investigating issues.

This is the item:

Number C_HomeCinema_Humidity “Luftfeuchtigkeit” (C_HomeCinema, gHumidity) {channel=“zwave:device:36288293:node6:sensor_relhumidity”}

hmm, that’s the same zwave node6 that you have linked the temperature feed to a Quantity Type Item? Or have you linked a number-temperature zwave channel to another just Number Item?
Mismatching types sort-of works, but with weirdness sometimes. Number:Dimensionless (the kind you would use for humidity in %) acts especially weird when involved with just-a-number.

I guess you can log out what your rule sees before comparing

logInfo("test", "raw state " + C_HomeCinema_Humidity.state.toString)
logInfo("test", "value " + (C_HomeCinema_Humidity.state as Number).toString)

Hmmmm… I don’t know, if I understood you correctly, but this thing has a sensor for temperature and a sensor for humidity:

grafik

Where shall I put, what you wrote (the logInfo("test…)

Well the channel says its just a number, so we’ll go with that. It’s a bit inconsistent of zwave binding but there’s nothing we can do about it.

You would add that to your rule. If we wanted to see what was being compared before doing the comparison, you would add it to your rule before the comparison.

So, I have now done this rule:

rule “Entfeuchter”
when
Channel ‘network:pingdevice:192_168_178_35:online’ triggered
then
logInfo(“Entfeuchter”, “I’m in the rule!”)
if (C_HomeCinema_Humidity.state >= 60){
logInfo(“Entfeuchter”, “Humidity is high!”)
C_HomeCinema_Socket1.sendCommand(ON)
}
else{
logInfo(“Entfeuchter”, “Humidity is low!”)
C_HomeCinema_Socket1.sendCommand(OFF)
}
end

and the log says:

“trigger” does doch mean, that anything happens with this item… or do I understand this wrong?

I think, the rule is just not starting… :man_shrugging:

Do you think this channel has a trigger event? Most do not. The binding docs will tell you.

For a test trigger, just make a dummy switch Item, linked to nothing, put it in your sitemap, trigger a rule from dummy Item received command.

1 Like