[SOLVED] Power usage daily

Hi all,

Recently, i bought a P1 cable for use with the DSMR meter binding. This cable has not arrived yet, but I am already trying this system out with the console. The binding periodically gives me the current usage in kW. I made a rule that changes that to W for use in HABPanel. So far that’s working.

My question now is: how can I convert this to daily usage, and after that change to daily cost. I know there is already a lot of posts regarding this, but after searching for a clear explanation for about an hour I thought i’d ask it in a new post. I already understand that calculating the cost can be easily done using this rule:

val Number kWh_price = 0.2290

rule MeterDailyCost
when
    Item MeterDayUsage changed
then
    MeterDayCost.postUpdate((MeterDayUsage.state as DecimalType) * kWh_price)
end

I just don’t understand how i can create the MeterDayUsage from the current usage.

Is there anyone that can help me?

Kind Regards,
jvank

You could create a simple rule that triggers at midnight to save the current reading in an item and throughout the day calculate the MeterDayUsage from the delta.
There may be easier ways, but that was the first approach that came to mind.

Ok, thanks for the idea. I just recently started using rules though so I have no idea what you mean :sweat_smile: . Is is it possible for you to help me understand?

Sure :grin:, like this:

rule "Midnight DSMR counters persist rule"
    when
    	Time is midnight
    then
      	PowerMeterMidnight.postUpdate(PowerMeterTotal.state)
    end

where PowerMeterTotal is the current meter reading (you canreplicate this if you have low/high tariff) and PowerMeterMidnight is the value to save every night. You have to define both Items.

Ok I think i’m starting to understand now.
Will this allow me to calculate Energy Cost during the day, or only the entire day at a time though? My idea was to make a dial or something on HABPanel that says the energy cost so far today.

I found this topic:


It seems to have the answer to my question, but since I’m a bit of a noob i can’t seem to make sense of that rules file, because it’s just a big text block. Will it work if i just copy that and change some values? I can make the layout a bit better later.

Okay so I’ve looked farther as is had some more spare time and i have this now:


rule "Daily power usage"
when
    Item MeterActualDeliveryW received update
then
    var long currentTime = now.millis
        if (Last_Update !=0) {
            var long timeElapsed = currentTime - Last_Update

            if (timeElapsed > 0) {
                var Number power = MeterActualDeliveryW.state as DecimalType
                var Number powerUsage = (power * timeElapsed) / 3600000 / 1000 
                postUpdate(MeterDayUsage, MeterDayUsage.state as DecimalType + powerUsage) 
            }
        }
        Last_Update = currentTime
end

There’s just one problem: it doesn’t work…
I’m going to try putting my logging on a higher level to see what is going wrong.

So i think i got it to work. For anyone interested, here is how i did it.

First i made the rule you can see above. I takes the current wattage reading and does some math to later add it to the MeterDayUsage item.

What made it work was initializing the MeterDayUsage by making a rule that changes it to 0 on system startup.


rule "Energy init"
when
    System started
then
    postUpdate(MeterDayUsage, 0 )
end

When i did that it magically started working. I now have 2 rules for changing MeterDayUsage to 0, one for initializing and one at midnight, but i will be combining those now.

1 Like

…and you learned a few tricks along the way. :blush:
Just remember that the 'System started event gets triggered on reload of rules as well.

Can you please mark this as solved?
Thanks.

Thank you for your help! Also thanks for letting met know about the System Started event, I might try a different solution then.

I’ll mark this as solved.