Fixes https://github.com/esphome/issues/issues/824 Fixes https://github.com/esphome/issues/issues/851