I am trying to figure out how to count my powerconsumption of my heating pump.
I have installed a subcounter in front of my heatingpump which is sending via an S0 impulses to my Wago SPS.
For 1kwh it sends 500 impulses.
I read via Modbus every 30 seconds from my SPS the actual value of the powerconsumption and write it into an mysql database.
So i see how much energy the heatingpump is actually consuming.
Is there a way to count this values up anyhow?
I searched a lot but i can´t find a hint how to do this.
Persistence service provides sumSince() and other functions that you can use in a rule e.g.
var today = yourItem.sumSince(now().with(LocalTime.MIDNIGHT))
But what you really want to do will depend on what your Item represents and how you recorded it… kW per hour? Instantaneous kW every ten minutes? Ever-increasing kWh counter?
yes… something like this… when the heating pump is not heating the warmwater or the house, then i have round about 120w for only the circulating pump.
When it starts heating, than the power consumption encreasing to round about 1500w and when finished than it will be going back to 120w.
I already searched in the forum and also google, but nothing leads mit to the solution… all topic i found have some different requirements then mine.
I added now an item:
Number Heatpump_total_kwh_daily "Waermepumpe daily"
and a rule like this for testing:
rule "Daily Power Consumption"
when
Item Waermepumpe_HT received update
then
Thread::sleep(2000)
Heatpump_total_kwh_daily.postUpdate((Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc").toString))
val summary = Heatpump_total_kwh_daily.state as Number
Heatpump_total_kwh_daily.postUpdate(summary/60)
val kilowatt = Heatpump_total_kwh_daily.state as Number
Heatpump_total_kwh_daily.postUpdate(kilowatt/1000)
end
i have to check if the sum value is correct or not and also when i would like to store the value to the mysql i will overwrite the values several times…
2021-02-11 14:36:57.830 [vent.ItemStateChangedEvent] - Heatpump_total_kwh_daily changed from 9495.51174316 to 569.73070459
2021-02-11 14:37:57.963 [vent.ItemStateChangedEvent] - Heatpump_total_kwh_daily changed from 569.73070459 to 570201.50820922851550
2021-02-11 14:37:57.969 [vent.ItemStateChangedEvent] - Heatpump_total_kwh_daily changed from 570201.50820922851550 to 9.49551174
That will not work properly.
postUpdate is asynchronous, the request is sent off to the Item but the rule does not stop and wait for it to take effect.
If you read the Item state in the next line you will most likely get the old value.
You don’t need to read the state, you already know what you just sent, use that.
val summary = Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc")
Heatpump_total_kwh_daily.postUpdate(summary.toString)
Yes you are right!
i see in the logs that is are not consistent and mixed up often…
But now i think i get it… is it that simple?
rule "Daily Power Consumption"
when
Item Waermepumpe_HT received update
then
val summary = Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc") /60 /100
Heatpump_total_kwh_daily.postUpdate(summary.toString)
end
so now… for this rule i have always the summary from now 24h back… correct?
If I let the rule run at 23:59 i will get the summary of the day…
Is there also a possibility to let the summary count up during the day?
to count only from midnight to now?
so… when the value for “Waermepumpe_HT” is stored every minute and I would like to get the power for the whole last 24 hours the rule have to be look like this right?
rule "Daily Power Consumption"
when
Time cron “0 59 23 * * ?”
then
val summary = Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc") /60 /100
Heatpump_total_kwh_daily.postUpdate(summary.toString)
end
And to let the daily value count up during the day? is this also possible?
Sure. You don’t have to use persistence for that. If your readings reliably come in every minute, just /60 and then add to a running Wh total. Decide when you are going to reset that total to 0. You might for instance do that in your “midnight” rule, and also persist the day to your jdbc (you can persist on demand in a rule).
To be honest, I have no idea how to build the rule for this counting value.
I tried a lot and searched a lot… but the combination with persistence and non persistence is confusing me.
I know letting me find the solution by myself is the best way to learn, but this is a little bit to hard for me to understand how the syntax should look like. I also can´t find any example in the forum which leads me to the point.
Well, your reports come every minute reliably?
Oh doh - look back at your original post and they come each half-minute, correct?
You might need to change the maths in your other rules.
Alright, so create somewhere to keep your running total. Almost certainly an Item, you’ll likely want to persist and chart it later.
Now create a rule to trigger from every update to your modbus counter, so every half-minute.
Do maths on the half-minute reading to convert to Wh or kWh or whatever you want your total in.
Add to existing total and post the result back to the running total.
Done, you’ve made a meter.
You will want refinements on top - you need to zero the running total before first use.
You may want to zero at other times depending on what you want this meter to represent - daily, monthly?
Choose persistence if needed - you may want to persist a daily total to your SQL just once at the end of the day, for example.
However - you will probably want to persist frequently and have restore-on-startup so that the meter reading survives a reboot in the middle of the day - I’d do that with a different database, MAPDB is made for that job.
I changed the transmission rate of the value from 30s to 60s to have the easier math…
So the Item Waermepumpe_HT is changing every 60s now.
i found a topic where someone is asking nearly the same, but the syntax is not clear for me and i am not able to replicate it for my purposes.
I did a typo in my rule for the daily count… so i don´t know if this rule is working properly… I will see it tomorrow morning.
rule "Daily Power Consumption"
when
Time cron "0 59 23 ? * * *"
//Item Waermepumpe_HT changed
then
val summary = Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc") /60 /100
Heatpump_total_kwh_daily.postUpdate(summary.toString)
end
I am afraid this counting function I have to let it go for now… because I have to learn the persistance function and the rule syntax much much more in detail to solve this.
Normally i can gather all needed informations from different threads and combine them for my purposes but here i am stuck.
I would need the aggregateion the other way round. My SolarEdge inverter has valus for day, week year, but waht is missung is the total. I think the best way would be, to take the daily values and add them up. Unfurtunatly I have no idea how this would look like.
In this Example I have the following Items:
SolarEdge_Production_energy
SolarEdge_Import_energy
I am doing this with a rule.
I do a “summary” of values which are written to the DB.
rule "Daily Power Consumption"
when
Time cron "0 59 23 ? * * *"
//Item Waermepumpe_HT changed
then
val summary = Waermepumpe_HT.sumSince(now.minusDays(1), "jdbc") /60 /1000
Heatpump_total_kwh_daily.postUpdate(summary.toString)
end
At the End of the Day i count the values wich are written every 60 seconds and divide it again with 1000 to get kW instead of W.
so it should be possible to to this with your values of day, week or year?
I hope this leads you to a solution.
i would suggest you pull the data shortly before the inverter resets the values and write them to the DB and then you can work with this data to sum up the values to a total sum.
I do the same… the rule runs at 23:59 and do a sum of the houly “live” values and i reset then the counter manually… (in your case it is done automaticaly by the inverter.
So i have a sum for every day…