I have a heatpump and calculate constantly what power it is delivering. That works fine. So the next step is to convert it to KwH over de day (week ,month etc). I thought I could use the KwH meter for that. But I can not get it right. My code is the following.
MeAlbert wrote: ↑Tuesday 18 February 2020 10:17
The counter works fine, the calculation from power to energy works fine . I can put the value in now but what to do on the end of the day?
If you just enter the values domoticz will take care of the process to transfer data to history tables (meter for 5 min. records and meter_calendar for day records) .
@waaren
It works but I do not understand how it can work.
You use a local newTotal but when I read the manual I have to use persistant variables to keep the value between two script executions.
How does it work? Or is this because you use function?
I have seen more examples of functions but see it nowhere in the manual. Is there another manual I can read?
But thanks for the solution.
Last edited by MeAlbert on Tuesday 18 February 2020 20:41, edited 1 time in total.
MeAlbert wrote: ↑Tuesday 18 February 2020 20:16
@waaren
It works but I do not understand how it can work.
You use a local newTotal but when I read the manual I have to use persistant variables to keep the value between two script executions.
How does it work? Or is this because you use function?
I have seen more examples of functions but see it nowhere in the manual. Is there another manual I can read?
But thanks for the solution.
I don't use persistent variables here. I read the value from the device itself where I stored it in the previous execution of the script.
Functions are just a named section of a program that performs a specific task. Lua (dzVents) and almost every other programming language have the option to use it.
A good place to start reading about Lua functions is lua.org
@waaren
You are going to fast for me. I understand what you are doing but not how you manage to store the newTotal field in betweenscript executions.
But up till now I only used the dzVents wiki which is quite superficial. But I will start to read the lua wiki.
Are the device settings ok?
MeAlbert wrote: ↑Tuesday 18 February 2020 22:20
I understand what you are doing but not how you manage to store the newTotal field in betweenscript executions.
MeAlbert wrote: ↑Tuesday 18 February 2020 23:57
It is not working correctly. The power generated is ok but the energy generated is 0. In the log screen I can see the calculation is correct.
I run the the script myself on a test system and there it does work as expected. Will show some screenshots tomorrow so we can identify the differences between our systems.
I have to come back to my previous statement. It works as on the end of the day it gives the day total in the days overview. I expected also the same thing in the hourly overview and that stays at 0. I have a script which reads the power produces by my solar panels and that does also show hourly values. I expected the same here as it is the same device. But daily is good enough for me.
I also understand the script you made completely now. Learned that it can be easier than you think. But I will probbaly come back again with some other trivial problem.
MeAlbert wrote: ↑Wednesday 19 February 2020 10:34
.. It works as on the end of the day it gives the day total in the days overview..
Good to read its working.
If you go to log page of the target device you will see the graphs and have the option to run a report (top right corner). Sometimes you need to refresh the page first (CTRL r in Chrome) before the graphs / report shows.
I do not know how to put images in this forum. Then I could show you how my graph looks like. In the day view you show here between 12.00 and 16.00 you see some blue bars. I have the dotted yellow line (power generated) but the blue bars are all zero. In the week view Wednesday shows the accumulated value correctly. After some time it started to appear again. So problem solved. Thanks for that