Format function for database - deviceNames

Rick from tech support gave me these instructions for automatically inserting the device name into a text message. This allowed me to run the same program on multiple devices, but when one publishes and event I can recieve a message that notes which device it is coming from.

I wanted to modify to do the same for a firebase database. I set this up to recieve all publications from all devices. The previous instructions worked for this, but the data came in as all on string…“this event happened at this time from this device”

I need it to come through as different data sets so I tried to modify the function similar to this tutorial:

Here’s my code. and a screen shot with the error I get.

Can anyone help me format this, so that it works

var deviceNames = flow.get(‘deviceNames’, deviceNames);

msg.payload = {‘Event’: (msg.event),
‘Payload’: (msg.payload),
‘Time’: msg.published_at,
‘Device’: deviceNames[msg.device]};

here’s a picture of the database with previous entries coming through the way I want, then the last entries are with my new flow (all one strng)

OK, It’s working now. I had stolen parts from my test unit to send out the 7 production units, so I was trying to simulate events with CLI. When the message went out as a string originally, it just ignored the device name code and I got “Event Power on Payload Test Power on Time 2018-…” in firebase, so I figured it would do same for what I am trying to do now. I just set up a button on the device and did it the correct way and this flow works.

thanks for your help

I wanted to try to set up Mongol and try that too, but I am having a hard time. Here’s the link to the discussion I started on Forum:

If you have time and have any idea what I am doing wrong, I’d appreciate your help

Thanks again.