MQTT Plugin Call Switch Button

I added an MQTT device and a Script to the Scripts section. I wrote my MQTT codes in this script. I also added a Switch button within a page. I want to check the POWER status of my IOT device and update the status of this Switch button. In short, from the Script file, buttons on any page, etc. How can I access the component? My button’s Name tag is full. However, when I call it with this name, I get an “is not defined” error. May I request a sample?