Send return of the digital pins arduino for HA

I have a Mega arduino with 32 digital ports in use, 16 ports with relays and the other 16 with button, when I click on a button the arduino it checks the status of the relay port and if it is on it turns off, or if it is off He on.
I’m trying to integrate the HA with this automation I already have at home, but I’m having some difficulties.
In the arduino I installed the FIRMATA library mixing with the program that I did to make the control of the buttons and relays, and in the HA I put the Arduino switch component, if I go in the HA interface and click on the switch it turns on the relay, I’m on the button it also turns on the relay, except that by clicking on the button it does not send to the HA the return that the switch was turned on.
I already tried searching and I can not find how to make the arduino send to HA that the digital pin is turned on.

thank you so much

Forgive my English. I live in Brazil.

I solved my problem using MQTT.
Thank you all.

Please tell me how to do it - I have the same problem…