How to use slow_pwm and define the duty cycle?

Hi,

I just discovered the thermostat integration in esphome and I’m moving all my custom arduino code to this. It’s much simpler and interfaces very nicely with HA. However, I’m having trouble setting a duty cycle for my thermostat. Basically, if the thermostat turns on heating, I want the relais to toggle ON/OFF in 5 min intervals. Ideally, this frequency can be set externally, but let’s not focus on this here.

This is my code:


esphome:
  name: heating_livingroom
  platform: ESP8266
  board: huzzah

wifi:
  ssid: "ssid"
  password: "bla"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "bla"
    password: "bla"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "bla"

ota:
  password: "bla"

sensor:
  - platform: dht
    pin: D13
    temperature:
      name: "Living Room Temperature TEST"
      id: test_temp_livingroom
    humidity:
      name: "Living Room Humidity TEST"
      id: test_hum_livingroom
    update_interval: 60s

output:
  # - platform: gpio
  - platform: slow_pwm
    pin: D15
    id: 'generic_out'
    period: 10s

switch:
  - platform: output
    name: "Generic Output"
    id: heater
    output: 'generic_out'


climate:
  - platform: thermostat
    name: living room thermostat
    id: test_themostat_livingroom
    sensor: test_temp_livingroom
    default_target_temperature_low: 24 °C
    heat_action:
      - switch.turn_on: heater
    idle_action:
      - switch.turn_off: heater

The thermostat is working fine, but the output switch is staying on all the time. It does not toggle. Maybe because it is bound to the switch, which forces it to stay on? How can I decouple this?

Thanks

1 Like

I have the same issue. Output slow_pwm is always on.

esphome:
  name: slow_pwm_node
  platform: ESP32
  board: esp-wrover-kit
  on_boot:
    priority: -10
    then:
      - output.turn_on: my_slow_pwm

wifi:
....

captive_portal:


# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

output:
  - platform: slow_pwm
    pin: GPIO2
    id: my_slow_pwm
    period: 5s

1 Like

Slow PWM is a “float output” it can not just be switched on and off but it also has a level. And I think in your case the level value is at “1” meaning always on.

Try this:

switch:
  - platform: output
    name: "Generic Output"
    id: heater
    output: 'generic_out'
    on_turn_on:
       then:
         - output.set_level:
           id: generic_out
           level: 50%

But maybe PID Climate — ESPHome is for you?

1 Like

My working code, thanks to @danielw suggestion:

esphome:
  name: slow_pwm_node
  platform: ESP32
  board: esp-wrover-kit
  on_boot:
    priority: -10
    then:
      - output.turn_on: my_slow_pwm
      - output.set_level:
          id: my_slow_pwm
          level: "50%"

wifi:
....

captive_portal:


# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

output:
  - platform: slow_pwm
    pin: GPIO2
    id: my_slow_pwm
    period: 5s

3 Likes