LogicMachine Forum
Setting a trend back to nil - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Setting a trend back to nil (/showthread.php?tid=1215)



Setting a trend back to nil - mykro - 05.02.2018

I have a trend that I only want to plot some of the time.  This is for an A/C's set point, which I only want to plot when the A/C is actually turned on.   I'd rather not plot it as zero when it's off because that affects the Y-axis scaling.  To achieve this I'm trying to clear or nil the object's value, similar to when it's first created.

Note, this is for a C-Bus Automation Controller.  The SetCBusMeasurement function doesn't accept a nil value, but can this be achieved through the standard LM libraries?

Here is my (non-working) code. The grp.find call successfully retrieves an object, but I cannot get it to clear the value:


Code:
    if ( ac["SystemOn"] == true ) then         SetCBusMeasurement(0, CBUS_MEASUREMENT_DEVICE, CBUS_MEASUREMENT_CHANNEL_SETPOINTACTIVE, ac["Setpoint"], CBUS_MEASUREMENT_UNIT_CELSIUS)      else       log("Setpoint Active : trying to set set to nil so it doesn't plot on trend")       local obj = grp.find("0/"..CBUS_MEASUREMENT_APP.."/"..CBUS_MEASUREMENT_DEVICE.."/"..CBUS_MEASUREMENT_CHANNEL_SETPOINTACTIVE)       if ( obj ~= nil ) then         obj.value = nil                 obj.data = nil            obj.datahex = ""       end     end



RE: Setting a trend back to nil - admin - 06.02.2018

You can try using float32 data type and writing NaN value to your object. Note that it will still show as 0 in the web interface.
Code:
nan = 0/0 -- zero divided by zero produces NaN



RE: Setting a trend back to nil - mykro - 12.02.2018

(06.02.2018, 10:35)admin Wrote: You can try using float32 data type and writing NaN value to your object. Note that it will still show as 0 in the web interface.

Thank you!  I also realised I was attempting to manipulate grp.find results which of course does nothing.  This is what works:

Code:
local function clearObject(name)   local obj = grp.find(name)   if ( obj ~= nil ) then     grp.write(name,0/0)   end end

Trend now stops plotting as desired. 

   

Thanks again Smile