'Average' Virtual Sensor/Switch Needed

I enabled it.

I am using the information in this thread to take average reading of a Watts on a power meter switch. I want to detect 3 power states of my appliance (washing machine) and have been using the Combination Switch plugin to detect these state. E.g.
0 watts = off
1 to 3 watts = stand-by or cycle completed
4 to 2300 watts = cycle run in progress

The difficulty is that during the cycle run, the watts can briefly drop into the 1-3 watts (triggering my stand-by scene) before it shoots up again. Therefore I thought that the average idea in this thread would help me smooth out the readings to avoid false triggers. (I did think of using timers, but the logic seemed more complicated than this average technique).

I have working code but my my averaged value is displayed in Vera with many decimal places. I am hijacking the UV sensor device to create a virtual device rather than Temperature sensor. My knowledge of lua scripting is very poor, and I have been unable to find the code to either round up or truncate the number to an integer. Can anyone tell me how I can accomplish this function please? Many thanks.
jtmoore.

You can use the math.floor function to truncate your result.

Thank you mcvflorin for the math.floor advice, and the link to the reference manual. Worked perfectly for my needs.

Instead of using the UV device, have you considered using the D_PowerMeter1 device as it is geared towards energy devices?

  • Garrett

Thanks Garret. I had completely overlooked D_PowerMeter1.