Arduino sketch on board loaded with ESPHome

I have a board board with ESPHome loaded on it (in fact, most of my boards run ESPHome; I love it!).

Often, I come across an Arduino sketch (such as one would load from Arduino IDE) for a specific purpose that is difficult, if not impossible, to run on ESPHome, so I would like to TEMPORARILY load the Arduino sketch, test or run it, then go back to ESPHome.
I want to be able to go back to ESPHome without having to re-upload it “fresh”, i.e. physical connection, etc.

To be clear: I do NOT want to run an Arduino sketch from within ESPHome (i.e. “convert” it). I have seen lots of articles on this, most of them saying it’s not worth it. I want to run the Arduino sketch native, without ESPHome, then go back to “pure” ESPHome.

Is this practically possible? I feel it could be possible with partitioning, but that is beyond my current knowledge set (I’ve only heard of it).

No, the ESPHome firmware is what is allowing you to upload code wirelessly, so a serial connection will always be required when going between environments.

ESPs are dirt cheap; just have extra boards on-hand and use one of those when experimenting/testing.

One way would be to use MQTT to communicate with HA.

Maybe using something like this:

Thanks, @brooksben11. I know that OTA uploads are a ‘built-in’ feature of ESPHome, and I also include code for my Arduino sketches so I can upload them OTA as well.
I do have extra boards, but sometimes I need to use a specific board which is already wired up to components, and I don’t want to start un-soldering, re-wiring, etc.

Thanks, @zenzay42 ! Hopefully it’s not the only way, but I’ll give it a swing… I have a little ESP8266 kicking around, so I’ll test on that.

So, I checked it out, and it seems to be [yet another] way to enable an “Arduino sketch” talk to HA.
This is not what I want to do… I want to:

  1. Load an Arduino sketch (using Arduino IDE, Thony, or whatever) to a board that currently has ESPHome on it
  2. Run that sketch, natively. I don’t want to convert, or emulate anything. I want it to run “as-is”.
  3. Once done, I want to return to ESPHome, without the need for a “fresh” installation, which usually involves klunky physical connection, such as with a USB/TTL cable (which brings with it a whole other set of issues, beyond the scope of this thread).
    Thanks!

I don’t see how to do this without using a physical connection.

I would do a manual install of the ESPHome config, save the .bin file and then use the ESPHome Web installer, when I want to go back to using ESPHome, but that requires a physical connection.

Thanks, @zenzay42, I appreciate all the feedback.
Saving a .bin does shorten and simplify the “return-to-esphome” process somewhat.
It looks like a physical connection is unavoidable.

Why am I trying so hard to avoid a physical connection? Well, as this discussion seems near or at is end, I’ll explain (I didn’t want to muddy the waters before now).

My USB/TTL cable is a Prolific PL2303TA. No matter what I do, Windows 11 “helpfully” “updates” the driver to one which DOES NOT WORK. I have spent hours, days, weeks trying to get Windows to leave it alone, but to no avail.
(For anyone offering the Group Policy solution, I’m on the Home Edition, so this doesn’t work; I’ve tried it)

So, every time I want to use this damned cable, I have to uninstall the “newer” Windows-supplied driver, reboot, install the working one (this often necessitates at least one more reboot), do my thing, and hope that Windows doesn’t automatically update it before I’m done (which, if I leave my PC long enough - this can mean hours or minutes - it will).

I’m convinced that there’s no solution to this issue, other than buying a different cable, impacting my budget.

Ok. Rant over. Thank you for your patience :slightly_smiling_face:

I had the same problem with drivers that didn’t work, and I had to downgrade them all the time. I usually didn’t have to reboot though. I got so fed up with it that I finally ‘upgraded’ to Pro. Nowadays I’m dual booting Linux instead. No more driver issues :smiling_face:

1 Like

I know this is an old thread and is “solved” but I actually figured out how to do this :slight_smile: Thought I’d leave it here for when I inevitably need it in the future.

  1. Compile your arduino code (should get a .bin file).

  2. Create an MD5 file.
    For linux, run this: (Mac & Windows - Google how to create an MD5 from a file)

cat firmware.bin | md5sum > firmware.md5
  1. Upload to a web server.
    I have a web server on my network. You can either install one or use a public free server. Just make sure it’s accessible from the network your ESP is on.

  2. Update your ESPHome device with this code:
    (Don’t forget to change the site url & keys)

esphome:
  name: http_firmware_update
  friendly_name: HTTP Firmware Update


  on_boot:
    - priority: -100.0 # everything is initialized, system is online - if condition waits for connection
      then:
        if:
          condition:
            wifi.connected:
          then:
            - logger.log: "Updating firmware from web..."
            - delay: '00:00:05'
            - ota.http_request.flash:
                url: https://some_site.com/firmware.bin
                md5_url: https://some_site.com/firmware.md5
            - logger.log: "This message should be not displayed because the device reboots"

http_request:
  verify_ssl: false

logger:

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable Home Assistant API
api:
  encryption:
    key: COPY-FROM-YOUR-DEVICE

ota:
  - platform: esphome
    password: COPY-FROM-YOUR-DEVICE
  - platform: http_request

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  1. Hit Upload. Once the OTA is done, the logs should show the ESP boot and then download the firmware from your site.

Done!