I have a UPS that has a USB connected to my physical device that I run HA on. This uses the APC UPS daemon but I had some trouble using the “APC UPS Daemon” integration (it worked but would disconnect) so I came up with a workaround. Basically I have a cron job that runs every minute and grep’s /sbin/apcaccess status and sends the output as a mqtt message.
In HA I have a mqtt sensor for this that populates correctly and an automation that sends a notification when the state changes. Generally, this works fine.
But after a reboot or reload the mqtt sensor loses it’s previous value and goes into “unknown state” until the next cron runs (up to 60 seconds later). The “unknown state” triggers the automation to send me a notification.
I tried changing the mqtt publish to include the retain flag (and I see HA see it) but when I reload HA config it will notify me that the sensor state is “none”.
I tried using the uptime sensor to mitigate this but I believe this is only looking at restarts, not configuration reloads.
Am I missing a step to take advantage of the retain flag? Can I trigger my cron job via HA whenever it reboots/reloads? Is there a way to add a condition that the automation shouldn’t notify if HA was reloaded?
Any point in the right direction would be appreciate. Thanks.