The state is read-only, yes. That’s not unique to MQTT switches, that’s how every switch (Zigbee, WiFi, RPi, etc) works. The best HA can do is to ask any switch to turn on or off. If the switch is broken or is not responding, HA isn’t going to override the state with a new (incorrect) state.
No, that’s not necessary. That’s the purpose of the command topic. You can of course do as you suggest, but you’re just creating a unique workaround to a problem that has already been solved cleanly and is supported natively.
The MQTT protocol is equipped to handle unresponsive devices or clients that have disconnected unexpectedly. There is a “last will” message that can be set up by the client, and when the client unexpectedly disconnects, the broker will publish that message. That can be used in this case to make the switch appear “unavailable” in HA. So you’d set up the switch (your RPi) to connect to your broker with a last will message, and then you’d set an an availability topic in your HA MQTT switch configuration. When the RPi connects to the broker it would set the last will message and would then publish available to the availability topic. If the RPi unexpectedly disconnects, the broker will publish the Will Message, which would be set up to be unavailable published to the availability topic.
However, all this is not totally necessary. With the way you have it configured today, you can just look at the last_changed property of the switch to see if it responded to your command. Many dashboard cards can display that along with the switch, and will display the time in an easy-to-read relative time format. So when you toggle the switch and the RPi responds appropriately, the card will show something like “One Second Ago”. If it hasn’t responded it should say something like “Two Hours Ago”.
Even when not on a dashboard, just viewing the switch entity will show you this:
This is a zwave switch and it responds essentially instantly for me, so I see this as soon as I command it on:
If it wasn’t responding, it would have switched to ON but would still show “49 minutes ago”. And when you close and re-open the entity dialog (or just refresh it), it would revert back to the OFF state.
Again, keep in mind this behavior isn’t unique to what you are doing with your RPi and MQTT. This is how every switch in HA behaves.