I haven't looked through your code but based on the description it probably does something very similar to the app I wrote for essentially the same reason. I used this device instead of a esp device to report power states.
1 Like