Hi great work!
Any chance for your sketch? There isn't many working sketches (without many errors in log) for home assistant. Unfortunately I can't write code.
I have different question doesn't this line give you errors?