Improve my rule for alarming me as soon as the washing machine is done

Hey all,

I created a rule to alarm me as soon as my washing machines program has finished. Its based on the energy usage of the machine. But my machine is a bit difficult to “read”. My rule basically works but its alarming me sometime even when the machine is not finished yet. And my rule alarms me several times and not only once. But I already added something to get ride of that issue but didnt checked if its working yet. And I guess my code is not really “comfortable”.

Let me show you the watts of the machine in a standard program. Looks little different in other washing programs but quite similar. Watts go up to 2.000 in the beginning (heating I guess). Than it jumps in the lower watt area and nearly before done it goes up about 500 ones when it starts a final fast spin to dry the clothes. Unfortunately in the time between heating and the final spin sometimes it goes down to a very low energy usage too. So I already added the final spin into my rule. Only if this has happend the rule may even start. Its called “ZSpeicher_Waschmaschine_Schleudert”.

If the rule have all triggers positive it starts a 5 minute timer to check if the energy usage is still low. But even if the machine is ready sometime the energy usage goes up a bit. If the 5 minutes are over in exactly that moment rule won’t run.

I guess the best thing would be to check the average energy usage in the last 5 minutes instead of that exact moment but I have no idea how to do that.

Energy usage of the whole washing program

Final hour of the washing program with

My current rule:

rule "Waschmaschine fertig"
    Item Waschmaschine_Verbrauch changed
    if ((Waschmaschine_Verbrauch.state) < (20.0) && (ZSpeicher_Waschmaschine_Laeuft.state == ON) && (ZSpeicher_Waschmaschine_Schleudert.state == ON) && (rulerunning_waschmaschine != "1")){
	sendCommand(rulerunning_waschmaschine, "1")
	createTimer(now.plusMinutes(5)) [|
	if ((Waschmaschine_Verbrauch.state) < (20.0))		{
	val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")
	telegramAction.sendTelegram(273100007L, "Die Waschmaschine ist fertig.")
	Echo_Buero_TTS.sendCommand('Die Waschmaschine ist fertig.')
	Echo_Kueche_TTS.sendCommand('Die Waschmaschine ist fertig.')
	Echo_Flur_TTS.sendCommand('Die Waschmaschine ist fertig.')
	Echo_Fitness_TTS.sendCommand('Die Waschmaschine ist fertig.')
	sendCommand(ZSpeicher_Waschmaschine_Laeuft, OFF)
	sendCommand(ZSpeicher_Waschmaschine_Schleudert, OFF)
	sendCommand(rulerunning_waschmaschine, "0")
	if ((Tagesart.state == "Wochentag" || Tagesart.state == "Homeoffice") && (((now.getHour() * 60 + now.getMinute()) <= 1260) && ((now.getHour() * 60 + now.getMinute()) >= 420))){
	Echo_Schlafzimmer_TTS.sendCommand('Die Waschmaschine ist fertig.')
	if ((Tagesart.state == "Wochenende" || Tagesart.state == "Urlaub") && (((now.getHour() * 60 + now.getMinute()) <= 1320) && ((now.getHour() * 60 + now.getMinute()) >= 660))){
	Echo_Schlafzimmer_TTS.sendCommand('Die Waschmaschine ist fertig.')
	}													}

Any suggestions?

Looking in the big gargler i found a reference to


Which of i get it is supposed to work directly out of the box with default persistence in oh3. Then you should be able to look for an average value below a certain threshold over a long enough period and your should be golden?

1 Like

In addition to persistence and averageSince I notice a few things:

  • I would flip your initial if statement to test for the opposite and then return; That will make the rule’s nesting one shorter which improves legibility and understanadability.

  • Please please use proper indentation. Every time you have a { the next lines should be indented two or four spaces until the }. Same for [ and ]. This is vital for you, the human, to easily see where one context starts and another one ends.

  • As the docs suggest, use rulerunning_waschmaschine.sendCommand(“1”) instead of the sendCommand action. Then you should be able to send just 1.

  • Add all your Echo Items to a Group and send command to the Group. It will be forwarded to all the members of the Group.

@joriskofman @rlkoshak
Thanks. Regarding improvment:

  1. Done
  2. OK, have to renew some rules now :wink:
  3. Doesn’t work, but I guess it’s because I didn’t defined the var in detail (var rulerunning_waschmaschine = “”)
  4. Yes thats easier but depending on the rule the Echos which I want to speak differ a lot so I activate them one by one per rule.

AverageSince looks like it could be working. At least visual studio code doesn’t display any errors.
But it says it has a problem with the greater symbol in the part of the rule:

(Waschmaschine_Verbrauch.averageSince(now.minusMinutes(10)) > (20.0))


"message": "Ambiguous binary operation.\nThe operator declarations\n\toperator_greaterThan(Type, Number) in NumberExtensions and\n\toperator_greaterThan(Number, Number) in NumberExtensions\nboth match.",

I think I already understand whats the problem. I want to compare the result of averagesince with a number, but the rule doesn’t know if averagesince will deliver a number. Simply adding “as Number” didn’t do the job :frowning: