I need to create a sensor with an attribute containing a Mikrotik connection table in HA for further displaying the table using a flex-table-card. To do this, a function was written that sends data to the sensor node attribute 'clients' as a string
- interface: '2G'
rx_rate: '13Mbps-20MHz/1S'
tx_rate: '14.4Mbps-20MHz/1S/SGI'
uptime: '1w1d22h36m47s'
last_activity: '280ms'
signal_strength: '-65@5.5Mbps'
signal_to_noise: '33'
signal_strength_ch0: '-68'
signal_strength_ch1: '-76'
tx_ccq: '30'
distance: '2'
last_ip: '192.168.0.11'
authentication_type: 'wpa2-psk'
encryption: 'aes-ccm'
- interface: '2G'
rx_rate: '54Mbps'
tx_rate: '72.2Mbps-20MHz/1S/SGI'
uptime: '1w1d22h36m44s'
last_activity: '1s360ms'
signal_strength: '-54@6Mbps'
signal_to_noise: '44'
signal_strength_ch0: '-58'
signal_strength_ch1: '-58'
tx_ccq: '87'
distance: '1'
last_ip: '192.168.0.39'
authentication_type: 'wpa2-psk'
encryption: 'aes-ccm'
But I can't figure out how to get rid of | in the attribute value
clients: |
- interface: '2G'
rx_rate: '13Mbps-20MHz/1S'
tx_rate: '9Mbps'
uptime: '1w1d22h35m47s'
last_activity: '360ms'
signal_strength: '-63@5.5Mbps'
signal_to_noise: '37'
signal_strength_ch0: '-67'
signal_strength_ch1: '-75'
tx_ccq: '32'
distance: '2'
last_ip: '192.168.0.11'
authentication_type: 'wpa2-psk'
encryption: 'aes-ccm'
- interface: '2G'
rx_rate: '54Mbps'
tx_rate: '72.2Mbps-20MHz/1S/SGI'
uptime: '1w1d22h35m44s'
last_activity: '1s360ms'
signal_strength: '-53@6Mbps'
signal_to_noise: '47'
signal_strength_ch0: '-57'
signal_strength_ch1: '-58'
tx_ccq: '96'
distance: '1'
last_ip: '192.168.0.39'
authentication_type: 'wpa2-psk'
encryption: 'aes-ccm'
Tell me, please, what am I doing wrong?
[{"id":"54c6e062bb19fa85","type":"group","z":"264869427f0f7cb8","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["96154c702dc64b8d","f0fe72fe67491246","e05582db968be14b","2c015140a31d62c5"],"x":1014,"y":1039,"w":852,"h":182},{"id":"96154c702dc64b8d","type":"inject","z":"264869427f0f7cb8","g":"54c6e062bb19fa85","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1150,"y":1120,"wires":[["f0fe72fe67491246"]]},{"id":"f0fe72fe67491246","type":"mikrotik","z":"264869427f0f7cb8","g":"54c6e062bb19fa85","device":"10e65d39218dd615","name":"Connected WiFi","action":"2","x":1340,"y":1120,"wires":[["2c015140a31d62c5"]]},{"id":"e05582db968be14b","type":"ha-sensor","z":"264869427f0f7cb8","g":"54c6e062bb19fa85","name":"Connected WiFi","entityConfig":"8476da6722585417","version":0,"state":"payload","stateType":"msg","attributes":[{"property":"clients","value":"clients","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":1760,"y":1080,"wires":[[]]},{"id":"2c015140a31d62c5","type":"function","z":"264869427f0f7cb8","g":"54c6e062bb19fa85","name":"Create Table","func":"let data = msg.payload; \nlet count = msg.payload.length; \ndata.forEach(item => {\n delete item.ap;\n delete item.wds;\n delete item.bridge;\n delete item.packets;\n delete item.bytes;\n delete item.frames;\n delete item['frame-bytes'];\n delete item['hw-frames'];\n delete item['tx-frames-timed-out'];\n delete item['p-throughput'];\n delete item['management-protection'];\n delete item['wmm-enabled'];\n delete item['tx-rate-set'];\n delete item['strength-at-rates'];\n delete item['802.1x-port-enabled'];\n delete item['group-encryption'];\n delete item['.id'];\n delete item['hw-frame-bytes'];\n});\n\nlet keys = Object.keys(data[0]);\n\nlet text = '';\n\ndata.forEach(item => {\n text += '-';\n keys.forEach((key, index) => {\n text += ` ${key.replace(/-/g, '_')}: '${item[key]}'\\n`;\n if (index < keys.length - 1) {\n text += ' ';\n }\n });\n //text += '\\n';\n});\n\nmsg.clients = text; \nmsg.payload = count;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1570,"y":1180,"wires":[["e05582db968be14b"]]},{"id":"10e65d39218dd615","type":"mikrotik-device","host":"*.*.*.*","port":"8728","username":"*","password":"*"},{"id":"8476da6722585417","type":"ha-entity-config","server":"31f480d3.0e3b28","deviceConfig":"","name":"Mikrotik Connected WiFi","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Mikrotik Connected WiFi"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"31f480d3.0e3b28","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]