I finally got the systeminfo binding on OH2 to work. Now I wanted to create a simple rule which alerts me when the diskpace drops below a certain value (in percent). Disk space available at the time of testing was 67.6%, so I choose 67.5% as the threshold value.
I want to receive a notification as soon as the available space drops below 67.5%. Also I want to receive a notification as soon as there is more than 67.5% space available.
Since the systeminfo binding updates every now and then I would receive a notification with every update as long as the space available is less than 67.5% That is why I have implemented a switch (sDiskSpaceAlert) which will be set to ON and as soon as the switch is turned on it will send the notification. So I will receive the “low disk space notification” only once.
Well, that´s at least what I thought.
Here is what really happened:
As soon as the disk space drops below the limit, the rule fires, sets the switch to ON and sends the “Low disk space notification”. But instantly after that the switch moves back to OFF and sends the “Low disk space alert canceled” notification even with the space available below the threshold limit.
Here is my item:
Number Swap_Available_Percent (gSystem) { channel="systeminfo:computer:openHABianPi:swap#availablePercent" }
and the rule:
rule "low disk space alert 1"
when
Item Storage_Available_Percent changed to <67.5
then
sDiskSpaceAlert.sendCommand(ON)
end
rule "low disk space alert 2"
when
Item Storage_Available_Percent changed to >=67.5
then
sDiskSpaceAlert.sendCommand(OFF)
end
rule "low disk space alert 3"
when
Item sDiskSpaceAlert changed from OFF to ON
then
sendNotification("myemailadress@email.com", "Low diskspace alert")
end
rule "low disk space alert 4"
when
Item sDiskSpaceAlert changed from ON to OFF
then
sendNotification("myemailadress@email.com", "Low diskspace alert USA CANCELED")
end
And finally an excerpt from the log: (I have copied only the relevant parts to keep it simple)
2017-05-09 22:13:33.562 [ItemStateChangedEvent ] - systeminfo_computer_openHABianPi_storage_availablePercent changed from 67.6 to 67.4
2017-05-09 22:13:33.568 [ItemStateChangedEvent ] - Storage_Available_Percent changed from 67.6 to 67.4
2017-05-09 22:13:34.193 [ItemCommandEvent ] - Item 'sDiskSpaceAlert' received command ON
2017-05-09 22:13:34.197 [ItemCommandEvent ] - Item 'sDiskSpaceAlert' received command OFF
2017-05-09 22:13:34.200 [ItemStateChangedEvent ] - sDiskSpaceAlert changed from OFF to ON
2017-05-09 22:13:34.203 [ItemStateChangedEvent ] - sDiskSpaceAlert changed from ON to OFF
2017-05-09 22:14:33.554 [ItemStateChangedEvent ] - systeminfo_computer_openHABianPi_storage_availablePercent changed from 67.4 to 67.7
2017-05-09 22:14:33.560 [ItemStateChangedEvent ] - Storage_Available_Percent changed from 67.4 to 67.7
2017-05-09 22:14:33.608 [ItemCommandEvent ] - Item 'sDiskSpaceAlert' received command OFF
2017-05-09 22:14:33.614 [ItemCommandEvent ] - Item 'sDiskSpaceAlert' received command ON
I don’t know what’s happening, but what about condensing the rule into one? Might help?
You could also add a Storage_Min_Percent item to store a particular percentage value elsewhere. Depends what you need to do I guess.
rule "low disk space alert"
when
Item Storage_Available_Percent changed
then
val stor = Storage_Available_Percent.state as DecimalType
Thread::sleep(5000)
val stortgt = Storage_Min_Percent.state as DecimalType
Thread::sleep(5000)
if (Storage_Available_Percent < Storage_Available_Percent){
sDiskSpaceAlert.sendCommand(ON)
sendNotification("myemailadress@email.com", "Low diskspace alert")
}
else{
sDiskSpaceAlert.sendCommand(OFF)
sendNotification("myemailadress@email.com", "Low diskspace alert USA CANCELED")
}
end
I don’t think that will work as desired because this rule will send an notification each time the Storage_Available_Percent changes, for each and every change! A change from 70 to 69% will try and give a notification “Low diskspace alert USA CANCELED”.
Having said that, I notice that the If clause is weird, since it compares a value with itself, that doesn’t work either!
rule "low disk space alert"
when
Item Storage_Available_Percent changed
then
val stor = Storage_Available_Percent.state as DecimalType
Thread::sleep(5000)
val stortgt = 25.0
Thread::sleep(5000)
if (stor < stortgt) {
sDiskSpaceAlert.sendCommand(ON)
}
else {
sDiskSpaceAlert.sendCommand(OFF)
}
end
Now, when the switch moves from OFF to ON, I will get a notification. Witch the switch on the ON position it doesn´t matter if receives more “ON” commands since it already is ON. So I get the notification only once…
I didn’t find that threat from Kai and tried to check that trigger usage. I can confirm that a trigger with “changed to <67” will run through, however the part “<67” is totally neglected. That was the reason for the problem in the starting question, both rules, the one with “<” and the one with “>=” are triggered by ANY change!
I must admit I am confused. What is the working rule right now? I am really interested in it, as I want to have an alarm whenever temperature is below zero.