Display apcaccess (UPS) Attribute:Value Data in Dashboard

I use an exec node to execute a command that queries UPS system status and returns textual data as shown in the command line snippet below. I want to display this output in the dashboard just as it is, or with two columns where the left column contains the attribute and the right column contains the corresponding value. Unfortunately, the exec node strips out whitespace and newlines or the output could easily be displayed in a UI template node. Is there a way to run a linux command and capture the unmolested output? I suppose this could be done with a custom function.

Here is the invocation and output for the apcaccess command. I can pipe the output to appropriate linux commands to format as needed (running on a Pi), such as sed or awk I guess. It just seems like a lot of effort to start with the format I already want in linux and perform a bunch of steps to get back to it in the node-red dashboard.

I am looking for the obvious "easy button" solution I have missed.

pi@NetMon:~/netmon/logs $ apcaccess -f /etc/apcupsd/apcupsd.upsCOMMS.conf
APC      : 001,036,0869
DATE     : 2021-03-01 22:30:48 -0500
HOSTNAME : NetMon
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : upsCOMMS
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2021-03-01 17:39:52 -0500
MODEL    : J25B AV UPS
STATUS   : ONLINE
LINEV    : 124.0 Volts
LOADPCT  : 3.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 116.5 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 96.0 Volts
HITRANS  : 136.0 Volts
ALARMDEL : No alarm
BATTV    : 27.0 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : QB1048332151
BATTDATE : 2010-11-26
NOMINV   : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 865 Watts
FIRMWARE : 873.P2 .D USB FW:P2
END APC  : 2021-03-01 22:31:36 -0500
pi@NetMon:~/netmon/logs $

Perhaps with a function node (i put your output in a text file and read it into node-red - which should be the same output as the exec node)

let input = msg.payload
let lines = input.split("\n")
let ups = {}

for(let x=0;x<lines.length;x++){
    
    let row = lines[x].split(":")
    
    if(row[0]!="" && row[1]!=""){
        let left = row[0].trim()
        let right = row[1].trim()
        ups[left] = right
    }
}
return {payload:ups}

edit - perhaps i should read in the early morning, anyway you can modify it to your liking to get a formatted output.

That should not happen, can you feed it into a debug node and show us please.

Add a split connected to a change connected to a join node between the exec and ui-text nodes. Leave the split and join nodes to their defaults and in the change node, set msg.payload to JSONata payload&'<br>' and that should do it.

[{"id":"465000e5.b25e48","type":"split","z":"64275f30.98b31","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":190,"y":400,"wires":[["f8e06a1.ae42998"]]},{"id":"ef324c4d.caf9e","type":"join","z":"64275f30.98b31","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":530,"y":400,"wires":[["6e47d13e.5844d","1068b271.49b40e"]]},{"id":"f8e06a1.ae42998","type":"change","z":"64275f30.98b31","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload&'<br>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":400,"wires":[["ef324c4d.caf9e"]]}]

And you are correct, it did not really happen. Dumping the Exec Node msg.payload output to debug shows all multiple spaces and newlines are preserved. They are removed when displaying in the dashboard text node or template node.

I was using the default template node with:

<div ng-bind-html="msg.payload"></div>

I added a style tag to preserve whitespace with proportional spacing. Everything displays properly now.

<style>
    #mytext {
        font-family:monospace;
        white-space: pre;
    }
</style>
<div id="mytext" ng-bind="msg.payload"></div>

Don't I feel silly... Thank you!

1 Like

or for the lazy of us

<pre><div ng-bind-html="msg.payload"></div></pre>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.