I have programmed a Particle IOT device which uses MQTT to communicate with Home Assistant.
The device publishes data payloads whenever a state-change occurs.
The device also publishes a notification when the device reboots after power outages or software updates.
I now need:
Home Assistant to always retain a copy of the latest data payload.
Home Assistant to return the latest data payload to the device when it receives a reboot notification. (This will permit the device to restore information lost in the reboot.)
This particular Particle “Photon” has controlled my garage doors for the past couple of years. I wrote the code from scratch … to control up to four garage doors. My application exposes a variable named “dStateJSON” and a function named “webButtonPress”. I then wrote an HTML GUI that presents data parsed from “dStateJSON” and presents an HTML button to trigger “webButtonPress” for each garage door. That GUI is displayed below. Note, I only have two garage doors … so only two are listed.
dStateJSON is large because it contains door-state, door-stateTime, door-stateText, door-buttonText, and other data elements that I use for debugging purposes. Of course this gets multiplied by (up to four doors) Particle will expose up to 622 bytes per variable, so I was not forced to be frugal.
When the Photon reboots, dStateJSON disappears. The rebooted Photon refreshes it based on its sensors, but it does not know the correct stateTimes.
I’m now in the process of integrating this application with Home Assistant. The first step was to publish dStateJSON via MQTT. As I did that, I saw the opportunity to address the lost-data problem.
At some point, I hope to create a HA card that looks something like the cell-phone GUI … but I think I need to build up my HA skills before I take that task on.
Thanks for your curiosity, comments, and a good laugh.