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.
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?