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
VERSION  : 3.14.14 (31 May 2016) debian
CABLE    : USB Cable
UPSMODE  : Stand Alone
STARTTIME: 2021-03-01 17:39:52 -0500
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
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
STATFLAG : 0x05000008
SERIALNO : QB1048332151
BATTDATE : 2010-11-26
NOMINV   : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 865 Watts
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.


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.

    #mytext {
        white-space: pre;
<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.