Rule to detect if device is on - is not working

Hi, i want to detect if my washer is working.

So i get the current power consumption by my knx-actor in mA.

But the rule is not working, the switch will not come to “ON”.

Can you have a look at my configuration files?

Group Strom
/* Stromverbrauch */
Number Strom_Waschmaschine “Strom Waschmaschine [%.2f mA]” (Strom) { knx=“2/3/2” }
Number Strom_Trockner “Strom Trockner [%.2f mA]” (Strom) { knx=“2/3/3” }
Number Strom_Spuelmaschine “Strom Spuelmaschine [%.2f mA]” (Strom) { knx=“2/3/50” }

/* Gerätezustand Aus / Ein */
Switch Zustand_Waschmaschine “Waschmaschine Zustand” (Strom)
Switch Zustand_Trockner “Trockner Zustand” (Strom)
Switch Zustand_Spuelmaschine “Spülmaschine Zustand” (Strom)

Text item=Strom_Trockner
Text item=Strom_Spuelmaschine
Switch item=Zustand_Waschmaschine
Switch item=Zustand_Trockner
Switch item=Zustand_Spuelmaschine

import org.openhab.core.library.types.*
import org.openhab.core.types.Command
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.lang.Math

// Regeln für Zustandsüberprüfung - Waschmaschine Ein / Aus
rule “Waschmaschine Zustand Ein”
item Strom_Waschmaschine changed
if (Zustand_Waschmaschine.state==OFF) {
if (Strom_Waschmaschine.state > 0.20) {
sendCommand(Zustand_Waschmaschine, ON)

rule “Waschmaschine Zustand Aus”
item Strom_Waschmaschine changed
if (Zustand_Waschmaschine.state==ON) {
if (Strom_Waschmaschine.state < 0.10) {
sendCommand(Zustand_Waschmaschine, OFF)

I also tried “received update” instead of changed - but with no luck.

Could be a lot of things. I can’t address any KNX issues that might be the cause. In your rules I recommend the following:

  • Add logging statements and watch your logs to see whether the rules are even triggering. If not then you know the problem is your Item configs.

  • Add some explicit casts to your Number Item’s states just to make sure the rules engine isn’t doing something stupid. For example: if((Strom_Waschmachine.state as DecimalType).doubleValue > 0.20) {

  • There is no need to have two rules here.

You can combine them:

rule "Waschmaschine Zustand"
    item Strom_Waschmaschine changed
    logInfo("Waschmaschine Zustand", "Strom_Waschmaschine changed: " + Strom_Waschmaschine.state.toString + " Zustand_Waschmaschine = " + Zustand_Waschmaschine.state.toString)
    if(Zustand_Waschmaschine.state == OFF) {
        if((Strom_Waschmaschine.state as DecimalType).doubleValue > 0.20) {
            logInfo("Waschmaschine Zustand", "Setting Zustand_Waschmaschine to ON")
    else if(Zustand_Waschmaschine.state == ON) {
        if((Strom_Waschmaschine.state as DecimalType).doubleValue < 0.10) {
            logInfo("Waschmaschine Zustand", "Setting Zustand_Waschmaschine to OFF")

Ok, i will give it a try.

Where can i see the messages from the log, created in this rule? In the openhab.log or in events.log? Or do i have to activate the debug mode first?

Is still not working. I can see 1.57 mA now in openhab, but switch is still “OFF”. No messages in openhab.log or events.log about this.

You should also be aware that as long as the switch (Zustand_Waschmaschine) hasn’t received any update or command since last reboot/startup the state could be “uninitialized” or “null” (if you haven’t configured persistence and restoreOnStartup) and therefore won’t match the conditions OFF or ON.

Yes, i know. So i changed the rule to

if … is “ON”

else …

Without any additional state conditions, so i get “ON” with the first “if” and all other states with the “else”.

But still nothing happens if the item number items changes. I switched the switches manually also, but the rule is not working.

I can see the number changing in the events.log, but no messages from the rule.

Change the when statement from:
item Strom_Waschmaschine changed
Item Strom_Waschmaschine changed

(Capital i/I)

Thanks man! That did it!!!

Now it works.