Working with messages, objects to array, ui-table

I'm using node-red for quite a long time and did a lot of useful things with it. Due to the documentation, forum and provided info's I was able to solve problems on my own. It seems, that I reached my personal limits now. I'm using node-red 4.0.5 running in a docker container on a RPi 5.
This project refers to our switch and energy meter devices flashed with the tasmota firmware. Since we have a lot of these devices I want to display (in a first step) the timer values in a table. To read out date via MQTT is no problem. The complete object looks like this:


I'm interested in the data from Timer1 to Action. UI-Table from the old dashboard accepts only arrays as far as I know. This is my first problem: I can't find out how to convert this object in an object into an array.
If I use the new ui-table (dashboard 2.0) it's no problem to convert the Timer1 object in an object into an object on it's own. Showing data in the new ui-table works, since it accepts objects as well. Unfortunately I'm losing the Object name "Timer1", which is essential. Otherwise I do not know to which Timer the data might belong to.
So the short version of my questions: How to make an array out of an object in an object and how can I display Timer1 in a field of the table in a column named Timers for example.
If possible, I would prefer no function nodes. This makes it much easier for me to understand your help. Thanks a lot.

To convert objects to arrays, you can use either JSONata or some simple JavaScript.

What you really want though, I think, is an array of objects instead of an object of objects.

Using JavaScript, something like this (untested) should work:

msg.payload = Object.values(msg.payload)
return msg.

That keeps the inner object but turns the outer payload into an array.

That will work no matter how many TimerX properties are in the incoming payload.

if you want the value of timer1 in an array then you could , if I understand correctly

In a change node
move msg. payload.Timer1
to msg. payload[0]

That would be payload.Timer1 (capital T). And that only works for a single named Timer. If there are multiple, you would have to do something for every one which isn't scalable.

There will be a JSONata equivalent of the JS code I shared, I am just too tired to work it out.

That's why I said if i understand correctly.

Rereading the topic question i would suggest something like this

That is if the debug shown shows all the message properties incoming.

[edit] Or one that is cleaner and handles multiple timers.

$keys($$.payload).(
    $merge(
        [{"timer": $}, $lookup($$.payload, $)]
    )   
)[]

Perfect, thanks a lot! Though I have got no idea what I typed into the change node but the result is as desired:


If I might bother you again: Do you know how to convert the result into an array in order to use the old dashboard? It is definitely a question without any urge.

Great I also got what i desired, access to your credit card. You should always be sure of what you are adding in code terms. Be aware.

The final example outputs an array, if i am not mistaken.

You are right! All questions solved. Crazy, 3 lines Jasonata and two brackets and four days of searching the web came ton an end. If you know what you do.....
Thanks again.
And you are absolutely right again: That's why I'm running all these things on an island system attached to nothing. Additionally I don't want to have anything on my productive system which isn't tested thoroughly.

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