BMON Calculated Fields and Transform

We run into some confusion with Calculated FIelds and Transforms since they share the same field(s)

image

Issues arise when we check Calculated Field when we are not creating a calculated field.

What’s the difference?

Transform: used to transform an existing sensor’s value into another. Say the sensor records temperature in Degrees C but you work in Degrees F. By adding a transform to a sensor we can accomplish this by entering val*1.8+32 into the Transform or Calculated Field Function Name field
note: Calculated Field is NOT checked

image(1)
dev note: once the transform is saved, all future data recorded in the database for this sensor will be it’s transformed value

Calculated Field: When Calculated Field is checked, a new sensor table is created in the BMON database. This option is used for one of two purposes:

  • to add sensor readings gathered from the Internet.
  • to create new sensor readings calculated from other readings that are in the sensor database.

Here, we are acquiring via getInternetTemp the temperature data from Internet weather services for stnCode PANV adding it as a new sensor because we checked Calculated Field.

image(2)

Here, we are creating a new sensor manor_snw1_run by calculating the runtimeFromOnOff of a Monnit sensor 29631 that we already have reporting to BMON by using onOffID: 29631 and checking Calculated Field. additional information here
calc_ex3

Additional Tips:

An easy rule of thumb, if it’s a sensor that is POSTing data to BMON (has an id, anything Monnit, LoRa, etc.) it is not a Calculated Field.

The BMON process that calculates Calculated Fields run every one-half hour at 15 and 45 minutes after the hour.

Debugging Tip:
if you have something that looks like this in your error log, check the sensor, in this case sensor 2963, in BMON to see if the Calculated Fields box is checked and if it should be:

2020-04-13 08:45:34,582 - bms.calc_readings - ERROR - Error calculating 2963 readings
Traceback (most recent call last):
  File "/bmon/bmon/bmsapp/scripts/calc_readings.py", line 38, in run
    rec_count = calc.processCalc(calc_sensor.sensor_id, calc_sensor.tran_calc_function, calc_sensor.function_parameters)
  File "/bmon/bmon/bmsapp/calcs/calcreadings.py", line 233, in processCalc
    stamps, vals = calc_func(**params)
UnboundLocalError: local variable 'calc_func' referenced before assignment