[Solved] Rule triggered every 5 minutes without change

Hi again,

this time I have a problem with a rule. I like to be notified when the washing machine is done.
I found this german blogpost which makes sense to me so far.
I like to do it with pushover and easier, so I made this rule:
rule Waschmaschine_fertig
when
Item Power_Funksteckdose_1 received update
then
if (Power_Funksteckdose_1.state < 2)
{
pushover(“Waschmaschine ist fertig!”)
}
end
itemdefinition:
Number Power_Funksteckdose_1 “Momentanleistung [%.1f W]” (g_haushalt) {homematic=“address=LEQ0272575, channel=2, parameter=POWER”}
The item shows up and also shows the power used.
But my problem is, I am getting a notification every 3-5 minutes and at the moment I have no Idea what is triggering the rule. The consumption isn’t changing.
I thought eventually it is because I had no persistence, so the value might be lost and everytime homegear and openhab are communicating i get another notification, but also with persistence no change.
Before I had “Item Power_Funksteckdose_1 changed”.
It seems it happens everytime an *.items file is refreshed. But also when nothing in the configuration changed.
So what am I missing here? Unfortunately I found nothing in the wiki or the forum - or I used the wrong terms.

Thanks!

An update to an Item does not necessarily mean a change to that Item. It just means that something has set that Item’s value. Apparently the homematic is reporting the value every 3-5 minutes whether it changed or not.

Using the “changed” trigger is probably the correct answer here as you only want the rule to trigger when Power_Funksteckdose_1’s value actually changes, not whenever the homeatic happens to report its value.

Sometimes you want to know when an Item is updated whether or not there is a change and sometimes you only want to know when the Item changes. Thus we have the two types of triggers, “updated” and “changed”.

Ok, thank you, that explains the difference between update and changed.
But the problem is this behaviour is the same with “changed”.
So I actually have no Idea what triggers this rule, even the value doesn’t change.

Ok, I set the logginglevel to debug and there are very small changes in the value (from 0.22 W to 0.24 W e.g.) and this triggers the rule.
So I think the rule must be modified so that the value has to go over 2 W and should then be triggered only when the value changes from over 2 W to unter 2 W.
For now it is triggered always the reported value is under 2 W.
But how to achieve this?

Thanks!

Hey Nico!

Are you really sure that the value does not change? The item you use is a NumberItem, which can store decimal values of quite high precision. By giving the format %.1f you tell openHAB that you’re only interested in the value rounded to one decimal. So in fact the value can change without you noticing it. Since I also use HomeMatic power outlets I know that the values transmitted are of high precision and even if the washing machine is switched off the power consumption may vary by some mW, which changes the NumberItems every few seconds and this executes the rule.

First of all, I recommend you to try formatting the NumberItem to %.8f or so, to see if it actually changes.

Birger

This isn’t as easy as you would think. You can’t define triggers that specifically. You will need to handle that within your rule.

Keep the trigger as “changed”.

Then in your rule check the previous state (NOTE: persistence must be enabled and properly configured for this to work)

if(Power_Funksteckdose_1.state < 2 && Power_Funksteckdose_1.previousState(true) >= 2) {
    pushover("Waschmaschine ist fertig!")
}

This will only send the pushover when the state changes to a value lower than 2 and the previous state was 2 or greater.

Hi Birger,

just edited my previous post, and yes, I set do debug and there are little changes.
So as just edited the rule should only be triggered if the value is higher than 2 W before.
But don’t know how to achieve this right now.

Thanks

Hi,

so my Idea with persistence wasn’t so wrong, great :slight_smile:
No I get the error “rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested”
rrd4j is the default persistence in the openhab.cfg and in the rrd4j.persist I have “Power_Funksteckdose_1 : strategy = everyMinute, everyChange, restoreOnStartup”
I found this thread, but the problem seems to remain unsolved.
Do you have an Idea for this or should I try to use another persistencestore?

I’ve no idea what causes the error or how to fix it. You can try db4o.

Thank you, I’ll try that!

Ok, got a new error: “Error during the execution of rule ‘Waschmaschine_fertig’: The name ’ >= ’ cannot be resolved to an item or type.”
The only thing I found to this was that there should be decimal numbers, but as far as I can see the values are stored as 0.23 and so on.

My bad.

I should be

if(Power_Funksteckdose_1.state < 2 && Power_Funksteckdose_1.previousState(true).state >= 2) {
    pushover("Waschmaschine ist fertig!")
}

Ah, I think I get slowly how things work with .state and so on. Works like a charm with db4o, with rrd4j not, same error as before (hat to test because was curious about it).
Thank you very much, problem solved!

Hi there, some time gone now, migrating things to OH2 and exactly with this rule I have the problem now, that it won’t work.

Names have changes, so the rule looks like this now:

rule Waschmaschine_fertig
when 
Item LEQ0272555_utility_room_pwrswitch_2_Power changed
then
if(LEQ0272555_utility_room_pwrswitch_2_Power.state < 2 && LEQ0272555_utility_room_pwrswitch_2_Power.previousState(true, 'jdbc').state >= 2 ) {
pushover("Waschmaschine ist fertig! OH2")
}  
end

I tried with .previousState().state, .previousState(true).state, .previousState(true, “jdbc”).state and the version showed in the rule.
The database (and default persistence) is now jbdc-mariadb.

I found very few topics with previousState in the OH2-category but it seems that it should work.
The rule just won’t fire.
Any idea what I am doing wrong here? Maybe @rlkoshak?

Thanks!

Is the rule actually not firing or is your if statement not working? Add a logInfo line as the first line of the rule to verify whether the rule is actually triggering.

previousState returns a State object, just like MyItem.state does. In order to do math with a State that state must come from a Number Item and you must cast the state to DecimalType.

So you need:

if((LEQ0272555_utility_room_pwrswitch_2_Power.state as DecimalType) < 2 && ...)

Ok, getting interesting now:

I did nothing else than modified the rule to:

then
logInfo("washing_machine","State_changed") 
if(LEQ0272555_utility_room_pwrswitch_2_Power.state < 2 && LEQ0272555_utility_room_pwrswitch_2_Power.previousState(true, 'jdbc').state >= 2 ) {
logInfo("washing_machine","Rule fired!")
pushover("Waschmaschine ist fertig! OH2")

switched the homematic-switch of and I got logentries about state changed and rule fired! (and the pushovernotification)
And now I know the washing machine continues with the actual washing after powerloss, because I wasn’t aware it was running a real washing now…
If I need it as DecimalType, do you have an idea why it was working without in OH1 and whyever now in OH2?
I will do more testing after the washingprogram has ended…

There is too much going on to know what changed that caused it to start working now. Was it not firing at all and is now? Was it failing before?

You should have needed the cast to DecimalType in OH 1 as well so I don’t know why it was working there at all.

Has failed before, don’t know why it worked that one time.

For now this is the rule:

then
logInfo("washing_machine","State_changed, Power now: " + (LEQ0272555_utility_room_pwrswitch_2_Power.state as DecimalType))
// if((LEQ0272555_utility_room_pwrswitch_2_Power.state as DecimalType) < 2 ) {
 if((LEQ0272555_utility_room_pwrswitch_2_Power.state as DecimalType) < 2 &&   (LEQ0272555_utility_room_pwrswitch_2_Power.previousState(true, 'jdbc').state as DecimalType) >= 2 ) {
logInfo("washing_machine","Rule fired! Power now: " + (LEQ0272555_utility_room_pwrswitch_2_Power.state as DecimalType))
    pushover("Waschmaschine ist fertig! OH2")
   }  
end

I have this logentries

2016-12-27 23:06:51.529 [INFO ] [arthome.model.script.washing_machine] - State_changed, Power now: 3.53


2016-12-27 23:08:14.002 [INFO ] [arthome.model.script.washing_machine] - State_changed, Power now: 0.23

I thing this should fire the rule, but it doesn’t.
However, the commented out section without the && … >= 2 part seems to fire the rule (of course also when it changes from 0.21 to 0.24 and so on, the reason why the &&… part was introduced).
OH1 and OH2 are running in parallel and because homegear acts as bridge the values are given to OH1&2 here, the old rule in OH1 fires every time as it should.
I think the problem is anywhere in the && … >= 2 part so any idea how to get further is welcome.

Highly confused now.
Have given up yesterday in the evening. Today the rule works as expected multiple times.
I think I’ll monitor this some days.

Ok, not anything better.
One day the rule works, the other day not.
All other rules work as expected.
As I am on a snapshotversion I’ll let it be for now and when it still won’t work on a stable release I’ll investigate further.