You don’t use normal arduino C++ code in ESPHome.
You program it in YAML, using various built-in pre-made objects that you define and configure. (Though, using lambda functions and custom components you can add your own C++ code for special cases)
You really need to read the ESPHome documentation to see how it’s supposed to be done.
For your original question of adding a rotary encoder, you define the 2 pins per the rotary encoder documentation:
The Code is uploaded, and the ESP is OK connected to Homeassistant, but the rotary function shows no result.
But at the moment i disconnect the ground wire from the Rot.Enc. an MQTT Meassage is published, showing the counter +1 or -1 steps.
For my demands i wouldn`t need a counter function, just the info via MQTT if the turning is CW or CCW.
Any ideas what to change ?
Thank you…