I want to measure waterflow. I have a reading of the watermeter every 15 sec. I want to make the difference of these to readings into a items. How do I do that.
Please post your Items and your first attempt and writing a Rule to do this.
Itās not that we donāt want to help, but we are also not here to do it for you. We are here to teach you how to do it and help you with problems. But the bulk of the work needs to come from you.
If you have specific questions about an approach we will be happy to help answer specific questions.
At a high level, you will want a Rule that triggers when the watermeter Item changes. In that Rule you will do your calculations and update your other Items.
My item is water_volume and it updates every 15 sec. I would like to make a new item (waterflow) where the difference between water_volume and the updated water_volume is.
If I knew how to write the rules I would send the first attempt
āI want to fly to the moonā
āOkay, first take your rocket ā¦ā
āWhatās a rocket?ā
At the moment, it is difficult to help. If we wrote a rule, would you know what to do with it? i.e. are you able to use one of the ways to include rules in your system - using an editor and saving in a file.
You say āI would like to make a new itemā - okay, can you do that or do you need help with that part?
āMy item is water_volumeā - okay, what type of Item is it? Can we see your definition? This makes a difference to how to use it in a rule, Rick didnāt ask for more detail just to be awkward.
Maybe you could sketch out how you think your rule should work. What would start it off? What it would it do, or calculate? What would it do with the result?
Can you roughly fit those ideas into this structure
Thank you for your answer. I hope you know that it can be very difficult to explain yourself when english is not your best language.
At the moment, it is difficult to help. If we wrote a rule, would you know what to do with it? i.e. are you able to use one of the ways to include rules in your system - using an editor and saving in a file.
You say āI would like to make a new itemā - okay, can you do that or do you need help with that part?
I know how to use the rule and I know how to make an item.
āMy item is water_volumeā - okay, what type of Item is it? Can we see your definition? This makes a difference to how to use it in a rule, Rick didnāt ask for more detail just to be awkward.
Water_volume is a number like this 312.938 m3
The water_volume updates every 15. sec and I would like the rule to calculate the waterflow so I can see how many liters of water I have been using in a minut
I have tried this rule but it gives me this error : Rule āMeter_updateā: Could not cast NULL
rule "Meter_update"
when
Item Water_volume received update
then
val Number newMeter = Water_volume.state as DecimalType
switch(updmeter.state as DecimalType) {
case 1: {
val oldMeter = wtrMeter.state as DecimalType
val oldDate = new DateTime((wtrMeterDate.state as DateTimeType).calendar.timeInMillis)
val newDate = new DateTime(now())
val double daymsec= 86400000
var double daydiff = (newDate.millis - oldDate.millis)/daymsec
// if(daydiff==0) {daydiff=1}
wtrUsedI.postUpdate((newMeter-oldMeter)/daydiff)
wtrUsedD.postUpdate((newMeter-oldMeter)/daydiff)
wtrMeter.postUpdate(newMeter)
wtrMeterD.postUpdate(newMeter)
wtrMeterDate.postUpdate(new DateTimeType(newDate.toCalendar(null)))
logInfo("Meters","Updated water meter")
}
}
end
Thereās still secrets about your Item type. Is this a āplainā Number type? Or is it dimensioned, a Number:Volume type? It makes a difference how you handle it in rules.
Okay, letās play.
The message is telling you that something in your rule canāt deal with a value NULL.
NULL (not the same as null
) is what Item states get set to when Items are created at bootup. So weāre talking about an Item that hasnāt yet been updated by binding or rule.
We can guess this is to do with the Item(s) your new rule populates - if itās never run before, theyāll be NULL.
You canāt extract a sensible numeric value from NULL, so that will be the part that fails.
So youād need to change the rule to test for state NULL before extracting the numeric value, and do something else if it is NULL.
Just as a general comment on numeric values, itās usually best to use āas Number
ā in rules (rather than DecimalType
or double
) as itās the closest thing to a ānativeā format. There are exceptions.
var Number oldMeter = 0
if (wtrMeter.state != NULL {
oldMeter = wtrMeter.state as Number
}
Youāll need to deal with the āold readingā timestamp being NULL as well - perhaps skip the calculations and just store the latest reading. You canāt calculate flow rate without the start reading/timestamp.
Iām not sure what the switch/case
part is about, that doesnāt seem to be needed for what you asked. Maybe get it working first before adding complications.