GPIO Pin drops to 0V when sensors publishes

Hi *,

I want to control a thermostat with a servo connected via API to HA. No PWM, only full speed.
In principle this works fine, since I use a motor driver l298.

I am trying to drive the motor for some ten seconds, but after a few seconds it is stopped (gpio pin 16 drops from 3V to 0V) as soon as some sensor or other component is published.
I have two template switches “Turn On Heater” and “Turn Off Heater” to trigger this pin.

It has worked some code iterations before. So I don’t think it is a hardware issue.

The while loop is an attempt to overcome the problem, but it does not work.

Does anyone have an idea?

Here is my yaml, I removed some code for clarity:

esphome:
  name: thermostat_lab
  platform: ESP32
  board: esp32-poe-iso
# on boot
  on_boot:
    - priority: -150.0
      then:
        - climate.control:
            id: pid_climate
            mode: "OFF"
    - priority: -10.0
      then:
        - switch.turn_on: calibration_sw

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  safe_mode: True
  password: ""


######################### GLOBALS #############################################
globals:
  - id: global_position_ms
    type: long
    restore_value: no
    initial_value: '0'
  - id: global_old_pid_val
    type: double
    restore_value: no
    initial_value: '0.0'
  - id: global_drive_time_ms
    type: int
    restore_value: no
    initial_value: '0'
  - id: global_set_temp
    type: double
    restore_value: no
    initial_value: '22.0'

######################### SENSORS #############################################
text_sensor:
  - platform: version
    name: "ESPHome v0.1b-v0.0d" # b=base d=device

sensor:
  - platform: uptime
    name: Uptime Sensor
  - platform: dallas
    index: 0
    name: "Lab Heater Temperature"
    id: lab_heater_temperature
    internal: true
  - platform: template
    name: "Position [ms]"
    lambda: !lambda return id(global_position_ms);
    update_interval: 10s
  - platform: homeassistant
    name: "Set Temp"
    id: settemp
    entity_id: sensor.lab_thermostat_settemp
    on_value: 
      - lambda: !lambda id(global_set_temp) = id(settemp).state;

######################### SWITCH #############################################
switch:
  - platform: template
    name: "Turn Off Heater"
    id: turn_off_heater
    optimistic: true
    turn_on_action:
      - output.turn_on: ccw_pin
      - output.turn_off: cw_pin
      - while:
          condition:
            lambda: !lambda return (id(global_position_ms) > 0);
          then:  
            - output.turn_on: pwm_output
            - lambda: !lambda id(global_position_ms) -= 1000;
            - delay: 1000ms
            - output.turn_off: pwm_output
            - delay: 50ms
      - output.turn_off: ccw_pin
      - output.turn_off: cw_pin
      - switch.turn_off: turn_off_heater
  - platform: template
    name: "Turn On Heater"
    id: turn_on_heater
    optimistic: true
    turn_on_action:
      - output.turn_off: ccw_pin
      - output.turn_on: cw_pin
      - while:
          condition:
            lambda: !lambda return (id(global_position_ms) < 70000);
          then:  
            - output.turn_on: pwm_output
            - lambda: !lambda id(global_position_ms) += 1000;
            - delay: 5000ms
            - output.turn_off: pwm_output
            - delay: 50ms
      - output.turn_off: ccw_pin
      - output.turn_off: cw_pin
      - switch.turn_off: turn_on_heater


######################### CORE #############################################
dallas:
  - pin: 5
    update_interval: 10s

climate:
  - platform: pid
    id: pid_climate
    name: "PID Climate Controller"
    sensor: lab_heater_temperature
    default_target_temperature: 22°C
    heat_output: convert_float
    control_parameters:
      kp: 0.0
      ki: 0.0
      kd: 0.0

######################### OUTPUT #############################################
output:
  - platform: gpio
    id: pwm_output
    pin: 16
  - platform: gpio
    pin: 15
    id: cw_pin
    inverted: yes
  - platform: gpio
    pin: 14
    id: ccw_pin
    inverted: yes

Using it without USB and the console logger makes no difference.

I experienced similar situations from C-multitasking, wenn printf manages your string buffers. With printf it works, seg fault without… Maybe my issue might be something similar?

Any ideas?

Didn’t find any solution. Abandoned ESPHome, back to custom code again.