ESPHome code vs. Wokwi Arduino

Dear comunity,

I`m struggling building an ESP8266 with an rotary encoder for displaying the movement of my Garage Door indside HomeAssistant.

I created a sketch ans also the working Code at the online Tool Wokwi ESP Simulator which is working.
Wokwi Simulator Garagentor

But if i copy this code inside the ESPHome code editor to upload it to my ESP8266 I only get error messages…
error

What is also missing to send the "Tor auf " CW or “Tor zu” CCW direction via MQTT.

Is there a online converter or can anybody help me please.?

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:

Ok, thank you for your help. :ok_hand:

So after a lot of reading I´m back here again.

This is the code right now.

esphome:
  name: esp-garagentor
  friendly_name: ESP-Garagentor

esp8266:
  board: esp01_1m
mqtt:
  broker: 192.165.64.64
  username: mqtt_sender
  password: !secret mqtt_password

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "tada"

ota:
  password: "tada"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Garagentor Fallback Hotspot"
    password: "tada"

captive_portal:

sensor:
  - platform: rotary_encoder
    name: "Torantrieb"
    pin_a: GPIO4
    pin_b: GPIO5
    on_clockwise:
      then:
        - mqtt.publish:
            topic: Torfahrt
            payload: "Tor hoch"

    on_anticlockwise:
      then:
        - mqtt.publish:
            topic: Torfahrt
            payload: "Tor zu"  
  - platform: rotary_encoder
    name: "Torantrieb"
    pin_a: GPIO4
    pin_b: GPIO5
    on_clockwise:
      - logger.log: "Torhoch"
    on_anticlockwise:
      - logger.log: "Torzu"      

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… :beers: