Energy rule

energy
rules
ruleengineexperim
Tags: #<Tag:0x00007f6ce1d9c600> #<Tag:0x00007f6ce1d9c4c0> #<Tag:0x00007f6ce1d9c358>

(Andreas Imhof) #21

Hi Tommy,

your Item BilVarmeDag shows the value for the last 24 hours, because you use now.minusDays(1) it’s the difference between the actual value (now) and the value from the day before (minusDays(1)).

So if you want the difference to the value of midnight, you need to use “toDateTimeAtStartOfDay()”.
The Item should be:

BilVarmeDag.postUpdate(BilVarme.deltaSince(now.toDateTimeAtStartOfDay()

For the values from beginning of the week or from beginning of the month I don’t know about a easy solution…

Andreas


(Rich Koshak) #22

withTimeAtStartOfDay

I have no idea why they use with instead of to.


(Tommy Hagenes) #23

Thanks! Updated rule now, and will see if it works.
Week and month is maybe OK as it is. But i’m using day every day to see my 40 meeters :slight_smile:


(Tommy Hagenes) #24

Hi again Andreas,

And thanks for the answer.
The complete line for this, should it be like this? I still need three bracket at the end to close the previosly?

    BilVarmeDag.postUpdate(BilVarme.deltaSince(now.toDateTimeAtStartOfDay()))

I cant get it to work as intended. Or maybe i misunderstand. My goal is to show the value in realtime of how much i use today. So if i use 1kw/h, then it should say 0 at 00.00 and 1 at 01.00, then at 17.00 when i look at all my meeters this one shows 17kw/h.


(Josar) #25

@tomhag maybe you missed what @rlkoshak posted and yes you will need the closing brackets.

withTimeAtStartOfDay != toDateTimeAtStartOfDay

So it should look like this

BilVarmeDag.postUpdate( BilVarme.deltaSince( now.withTimeAtStartOfDay() ) )

(Tommy Hagenes) #26

Thanks Josar, i read what Rick was reading but then i started to copy/past and forgot :zipper_mouth_face:
Updated now and will see tonight if it works, thanks also for clearifying about the brackets.


(Andreas Imhof) #27

Hi Tommy,

sorry, you are right about the brackets. You Need for every opened bracket a closing one. So you need one for:

  • withTimeAtStartOfDay
  • deltaSince
  • postUpdate

The other problem about “realtime” values:
Your rule triggers every night at midnight (“0 0 0 * * ? *”), so your calculated items are updated once a day at midnight.
If you want to update the items more frequently, you have to change the trigger condition.
For the energy consumption for the current day I would suggest a second rule, which is triggered on every Change of BilVarme. So if your power meter updates the value, the consumption for the current day is also updated.

Andreas


(Tommy Hagenes) #28

Hi again Andreas,

Ofcourse as calculation is done at midnight, so for this solution the “day” should be a standalone rule.
But is there a better way to do this? I do have the “total” counter and also a reset.
If i reset the total at midnight the “total” will only count that day.
But will that be a problem for week, month and year?

I tried with a simple rule at the end for this.

BilVarmeReset.sendCommand(ON)
BilVarmeReset.sendCommand (OFF)

But that did not do it, dont know if my rule is wrong or if it happens so quick that it does not reset? Maybe there should be a “wait” for 5 seconds?


(Andreas Imhof) #29

Hi Tommy,

if you reset your total value each day you will have a problem showing your weekly/monthly/yearly values.
The assumption for this kind of usage is, that you have an energy Counter which is counting up without reset. If you reset the counter, you will get negative values for your weekly/monthly/yearly values which are indeed wrong in this situation.

I did not get the logic for resetting the counter and why you want to reset the counter.

You have energy meters which are:

  • counting up
  • overflow at 65556 (to start at 0 again)
  • some of them you can reset manually

I would use two items for each energy meter:

  1. the actual value of the energy meter
  2. the sum/total of the energy meter

The first item represents the value you get from the counter. Via rule you update the second item from the first item with respect to overflows. Therefore your second item has the actual value since you started your measurement. So if your energy meter had the third Overflow, the second item should have a value around 196.668

Your reporting is done with the second item, which has no overflows and shows the real values for week/month/year.

With this Approach you don’t need any manual reset of the energy meters…

Andreas