Start and stop a generator with ESPHome

Hello all. Have a question for the hive mind. I know I’m overthinking this. I have home assistant setup in a converted cargo trailer/ camper. I’ve been able to use esphome for a lot of the connections between this and that. What is left is starting and stopping a generator that has a push button start. Basically I need it to see if the generator is running (easy to do with the inverter monitoring that is already setup) and if it is, close a contact (basically push the button) for a few seconds and wait to see if it detects power coming in. If there is, it’s done, if not, close the contact again and repeat the process. I also need it to close the same contact for 30 (I think) seconds when I want to shut it off or the batteries show a specific state of charge. The connections to the esp32 are what has me stumped. The code should be pretty simple. I have a bunch of Wemos D1Mini’s. This should be easy, right???

Yes, it is very much possible. I have setup something similar for my friend. use GPIO switch with 30s time delay to make it as push button which in turn triggers a right sized relays. I am using 30A relay boards for this purpose since I am starting a 2HP pump. Refer here.

1 Like

If you don’t want to study the electronics of your generator logic board, just use a small relay module to close the button contacts.
Another option is to measure the voltage of the logic board and verify if button is switching low or high side…

1 Like

Would you be willing to provide some sample code?

You may refer this link.

1 Like

It works! Here is tthe codde I used after all the standard ESPHome stuff. THANK YOU!

output:

  • platform: gpio
    pin: GPIO22
    id: gpio_d1

switch:

  • platform: output
    output: gpio_d1
    id: relay1
    name: “Gen Start-Stop”
    icon: “mdi:generator-mobile”
    on_turn_on:
    • delay: 3500ms
    • switch.turn_off: relay1

Good to hear it has worked for you. :raised_hands: