jneilliii / OctoPrint-TPLinkSmartplug

105 stars 57 forks source link

[BUG]: 'Last power cost' in additional details is wrong #349

Closed AndreasBoehme closed 8 months ago

AndreasBoehme commented 9 months ago

Describe the bug The statistics of an already finished print shows wrong print-costs when using a TP-Link Smartplug and this OctoPrint-Plugin.

e.g. Last power cost: 6.305

TP-Link Smartplug Tab shows: total kWh: ranges from 1.06 to 2.393 => used: 1.333 kWh cost: ranges from 0.3392 to 0.76576 => 0,42656 Euro

(I checked that with the kasa-app from tp-link - the ptint was ~ 2 weeks ago, but the overall power consumtion is ~ 4 kWh, thus costs can't be higher than ~ 1.3 Euros)

To Reproduce

  1. set Cost per kWh to '0.32'
  2. start a long print (e.g. 15h)
  3. show TP-Link Smartplug Tab for the timespan of the print
  4. when print is finished show additonal details of the print
  5. Last power Cost (from additional details) much higher than in the TP-Link Smartplug Tab

Additional context

Seems the overall-power-costs is multiplied with the print-time. I found this line in the source code: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/blob/a3771477d760215871bb98c8fb531fcbfb67f832/octoprint_tplinksmartplug/__init__.py#L707C22-L707C38

Screenshots In the screenshot you see that the total power-consumption was 2.3 kWh when the print was finished. The costs per kWh was configured to be 0.32. Thus the last power cost of 6.3 must be wrong (should be ~ 0.4)

image

image

jneilliii commented 9 months ago

Can you do me a favor and enable debug logging in the plugin's settings, restart OctoPrint and go through a print again, then share the plugin_tplinksmartplug_debug.log file that will show up in OctoPrint's logging section of settings?

puterboy commented 9 months ago

Agree it seems like a bug - I wrote some SQL queries to bring the Obico print history database plus the TPLink database into Excel pivot tables to calculate/display all sorts of stuff about my prints. The energy costs that I calculate are a fraction of what the additional details shows...

puterboy commented 9 months ago

I made the fix that you suggested -- i.e., remove the multiplication by hours and now the energy cost in Octoprint agrees with my database/spreadsheet/pivot table calculations. @jneilliii I will include this in the PR I am testing for the other bugs/enhancements I have been working on...

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days

AndreasBoehme commented 8 months ago

Thank you for the change, @puterboy. Just need a new release or RC to test it.

jneilliii commented 8 months ago

1.0.4rc3 was released with these changes merged

AndreasBoehme commented 8 months ago

Didn't see this bug-number in the release notes, but probably because the fix is part of #352. I will test it.

jneilliii commented 8 months ago

Thanks, updated release notes.

AndreasBoehme commented 8 months ago

Tested 1.0.4rc3, value is correct now! Thank you for the fast implementation.

jneilliii commented 8 months ago

thanks @puterboy for the fix on that one.