How to calculate power consumption and indicate on HMI

How to calculate power consumption and indicate on HMI
none 0.0 0
  • HMI Model: Cmt FHD 820
  • EasyBuilder Pro Version: V6.10.01.442

Dear Sir,

I have some power meters. I am using HMI communication with power meter to indicate power consumption (KWH) parameter on HMI.

Now, I would like to calculate KWH for everyday.

By formula: KWH (consumption) = KWH (today) - KWH (yesterday)

There are 30 or 31 days per month.

Please, how to do that on EasyBuilder Pro?

Could you show me some solutions to perform it? (Macro, or other object…?)

Thank you so much!

Hi @cuongho ,
Yes, using a macro would definitely work. Below is the macro used and the project to show a small demo.

We can use the GETDATA and SETDATA functions to pull the data, apply the formula, and store the correct consumption value in the memory register.

In the demo, I am using a function key to execute the macro, but if you want to automate it, I suggest using periodical execution. Furthermore, LW-0 is today, LW-10 is yesterday, and LW-20 is the consumption rate. Please feel free to update these values with the correct memory registers.

Please let me know if you have any question!

Demo Project


macro_command main()
short today
short yesterday
short consumption


GetData(today, "Local HMI", LW, 0, 1)
GetData(yesterday, "Local HMI", LW, 10, 1)

consumption = today - yesterday

SetData(consumption, "Local HMI", LW, 20, 1)

end macro_command

I would also recommend using the GET/SET FN API to write your macros.


1 Like

Dear Aaron.S

Thank you for your instruction.

Your demo project is only applied for one day.

Please tell more:

  • I would like to do automatic calculation for everyday per month. (29, 30, 31 days)
  • The result of everyday consumptions will be save in local memory (separate address)

How to make HMI recognize day of month (ex: 1st, 4th, 6th, 20th…etc) and HIM can store KWH consumption into separate memory?

For example:

  • kwh - September 1 store in LW101
  • kwh - September 2 store in LW102
  • kwh - September 3 store in LW103
  • ……………….

I think that we should use system tag “Local day” to consider or create Macro.

Hope you will support more times.

Thank again.

Hi @cuongho,

Below is a macro that uses the system register LW9013 to get the day of the month, compares it with yesterday’s value, and calculates the daily consumption, storing the result in a sequential memory address.
LW50 is used to store the value of the last processed day.

If you need any other time-related system registers, they’re listed in the image below.
Please feel free to use them and update the macro as needed.

macro_command main()
short today
short yesterday
short consumption
short current_day
short last_run_day
short storage_address

// 1. Get today/yesterday values
GetData(today, "Local HMI", LW, 0, 1)
GetData(yesterday, "Local HMI", LW, 10, 1)

// 2. Get current day and last run day
GetData(current_day, "Local HMI", LW, 9013, 1)   // System day
GetData(last_run_day, "Local HMI", LW, 50, 1)    // Stored last-run day

// 3. Only run if the day has changed
if (current_day <> last_run_day) then

  // 4. Compute consumption
  consumption = today - yesterday

  // 5. Store consumption in LW101 + (day - 1)
  storage_address = 100 + (current_day - 1)

  SetData(consumption, "Local HMI", LW, storage_address, 1)

  // 6. Update last_run_day so it doesn't run again today
  SetData(current_day, "Local HMI", LW, 50, 1)

end if

end macro_command

1 Like

Dear Aaron.S

It is very good. I will try to do.

Thank you so much!