Rule: Push Notification Power Off

Hi there,
I try to get a push notification after my washing machine has finished. I measure that via a TP Link plug.

I tried something like this, but I don’t get a push notification after 30 seconds.

rule "Waschmaschine"
when
    Item TPLinkSteckdoseHS110EnergyMonitoringPower changed
then
    if (TPLinkSteckdoseHS110EnergyMonitoringPower.state as Number == 0)
    {
        Thread::sleep(30000)
        if (TPLinkSteckdoseHS110EnergyMonitoringPower.state as Number == 0) { 
        logInfo("notifications", "Sending notification via app.")
        sendNotification("aa@bb.cc", 
            "Waschmaschine fertig")
            }
        TPLinkSteckdoseHS110EnergyMonitoringPower.postUpdate(OFF)
    }
end

my log states following changes (examples):

[vent.ItemStateChangedEvent] - TPLinkSteckdoseHS110EnergyMonitoringPower changed from 13.955 W to 13.814 W
[vent.ItemStateChangedEvent] - TPLinkSteckdoseHS110EnergyMonitoringPower changed from 13.814 W to 0.0 W

Since I get push notifications when my front door is opened (another rule), push notifications work.
Where is my mistake?

What kind of Item is that, that you’re expecting to send a switch type OFF to, but also read as a Number?

Have you looked in openhab.log for your logInfo message?

Not the cause of your problem, but that is a terrible design approach. The power level could change a hundred times between starting the delay, and checking 30 secs later. Meantime, a hundred new versions of the rule will have started and each run their own delay, seizing your system up.

Consider a timer, start it when power=0 and cancel it when !=0. If/when it expires, send the message.

not shure but when i compare an item state i use code like this:

if ((TPLinkSteckdoseHS110EnergyMonitoringPower.state as Number).intValue == 0)

perhaps try to change the two parts in your code

best stefan

Didn’t test your rule, but 2 remarks:

  1. In general sleep of 30sec is a bad idea and can lead to unexpected behavior of the whole system.

More details here (OH 1.x and OH 2.x Rules DSL only] Why have my Rules stopped running? Why Thread::sleep is a bad idea

  1. Have you seen this solution? This is what I use successfully for my washing machine with some small modifications

Thanks a lot. Your tutorial works like a charm. Since I am not firm enough with programming: How do I map “Washingmachine_Power.state” in my sitemap in order to see the state’s name instead of the numbers 0-3?

You first have to create a map file (and install the map transformation if not already done) as discribed here:

After this you can use it in your sitemap with the label tag, e.g.

label="Washing Machine [MAP(mymap.map):%s]"