Esphome pulsed output at interval

Hi all,

I have a garden cooling mist sprayer that needs to be pulsed at intervals. Ideally, i’d like it to present as a switch. When the switch is on, the output is pulsed for 500ms every 20 seconds. When the switch is off - nothing, obviously.

I’d prefer that the actual output is not exposed to to homeassistant, to reduce the risk that the output gets turned on and left like that.

I have the following code, which works, but all the time. I can’t enable and disable the interval timer.

any ideas?

esphome:
  name: mister_minimal
  platform: ESP8266
  board: esp8285

wifi:
  ssid: 'SSID'
  password: 'why you wanna know'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

output:
  - platform: gpio
    pin: GPIO16
    id: mister_relay

switch:
  - platform: template
    name: "Mister"
    id: mister_pulse
    turn_on_action:
    - output.turn_on: mister_relay
    - delay: 500ms
    - output.turn_off: mister_relay

interval:
  - interval: 20sec
    then:
      - switch.turn_on: mister_pulse

Create an input boolean in home assistant:

input_boolean:
  mister_enable:
    name: Mister Enable

Bring it in to your esphome config as a sensor:

binary_sensor:
  - platform: homeassistant
    name: "Mister Enable"
    entity_id: input_boolean.mister_enable

Then, I think you should be able use it to enable / disable your mister like this:

interval:
  - interval: 20sec
    if:
      condition:
        binary_sensor.is_on: mister_enable
      then:
        switch.turn_on: mister_pulse

Untested, and you may have to massage the syntax a bit.

1 Like

Thanks. That didn’t work out of the box, but I managed to make this work.

output:
  - platform: gpio
    pin: GPIO16
    id: mister_relay

switch:
  - platform: template
    name: "Mister"
    id: mister_enable
    optimistic: on

interval:
  - interval: 20sec
    then:
      if:
        condition:
          switch.is_on: mister_enable
        then:
          - output.turn_on: mister_relay
          - delay: 500ms
          - output.turn_off: mister_relay

1 Like