HabPanel - date operations in widget

Hi,

I am using Openhab 2.4.0 with Z-Wave binding 2.5.0.

I can do simple widgets to turn on/off with some ng-if or ng-click expressions. I am learning how to use openhab and habpanel.

I have problem to do simple calculation with dates and show result. I have power plug with meter nas-wr01ze and I would like to calculate and show cost of average used energy in the monthly period.

  1. I need to set constant start_date (perfectly if defined in a widget configuration, rounded to full days)
  2. Second parameter is a constant price = cost of 1 kWh = 0,6 (perfectly if defined in a widget configuration)
  3. Third parameter is variable actual_date
  4. 4th parameter is variable energy energia read from power plug

Equation:
monthly_cost = (energia / (actual_date - start_date)) * 31 * price

Could you write me a code which I can put directly to the widget code?

This sample will help me pretty much in case of other calculations in widgets. How to use variables, do equations etc. There is any tutorial which can help?

I’ve moved this to a more appropriate category.

Because most people want to use the results of these calculations elsewhere (e.g. save them to a database, chart them over time, use them to drive automation), they are typically calculated in Rules, not in widgets. See https://www.openhab.org/docs/configuration/rules-dsl.html for getting started with Rules.