I’m using Homebridge and everything connected is controlled by mqtt. So that’s fine for everybody using a Mac or an iPhone, but I want to be able to controls things from a browser. Using websockets (Paho mqttws31.js) that is working fine. The only thing is that on opening the page there is no information about the current state of things. It always starts with all buttons in the default state. As soon as I change anything either in the home app or by sending a command through an mqtt client, the page is updated. (But of course only for the item that was changed externally).
I know the mqtt broker discards all messages as soon as they are delivered, so that makes things difficult. And since javascript is browser side my http server has no knowledge of what was has been going on in mqtt.
Is there any way to get the initial state of the page correct after opening? Maybe a script running on the server that keeps track of every topic in an xml-file so I can read that file on opening the page and set things right?
Or am I missing something very obvious and can this be done in a simpler way?