Question about using Any Component to create new components and saving them to a Database

There seems to be a bug in this platform when you use the “Any Component / Switch” blocks.
If you use (Component) this to minimize the number of blocks needed in your app, The data written to a Realtime DB is shown as a long string of numbers and letters. If you specify the specific switch you are changing, the data is written as the switch name (i.e. Switch1, Switch2, Switch3).
The issue is, if you use “Component” instead of the “switch name” (i.e. Switch1), you cannot put the data from the database and display the switch value when the app opens. Your switch value will be grey and off. Use the switch name and the value of the switch is displayed correctly. Can the code of this component be modified to write the component name instead of the long string of numbers and letters? This would solve a big problem. See the screen prints below.

![image|690x367](upload://tR6meMg6RA4K3y

xyzCzl0WtuGWg.png)

I solved this problem using Button or switch Text , Simply add a text to the button you need to use and hide the text if You don’t want to be shown. the when any component used don’t use the button name, use the button component get text.

Thanks. this would work on the phone. However, I need to be able to make a change to the way the value is saved in a realtime DB. I need to be able to change the output label of the Component to the switch name, not the long running list it produces now. so, instaed of it reading this in the database

17273-374ddc-3783784-fdfd-44858
switch
true

I need it to say
Switch1
true

This is what I get

Use all available options amigo :wink:

1 Like

It is necessary for the component to manually create a new Name property and use it to write it to the database and read from the database instead of the component identifier.

I did that. That is what the variable Switches selected does. I also created a new object to see if that would help. As you can see, it writes to the database with the switch name selected in the variable. However, it still will not pull the data and assign it to the right switch.

Hey @bobbyj12,

Just to let you know that this is actually the expected behaviour (and not limited to Switches either!) so I’ve edited the title of this post since it’s not really a bug.

The string of characters you see is actually the unique ID of the component. You can see some more examples of these in the address bar of your browser when you click on different components.

1 Like

I don’t see any blocks for creating a new property, so your example can’t possibly implement what I suggested.

The if/then statement in the Switch change says, if sw_1 selected, set variable to sw1. This actually writes “sw1” and the switch value. If you look at the screenshot of the DB, does it look ok? I would think I should use this info to write the values to the switches in my app. I just need to figure out what I need to input into the Key field of the get statement. It pulls the data into the switches but only the last entry into the database.

here’s an example of this working with cloud variables now:

There are a small few improvements to make in terms of UX, but if a switch is toggled on one device, that same switch will toggle on every device.

Hope that helps!

Thanks for the reply @domhnall. Looking at my blocks, where am I doing wrong not being able to show the value of each block when the app opens?