ESPHome Error: Could not load broken JSON: /data/cache/platformio/packages/framework-arduinoespressif32/.piopm

Hi guys,

I migrated my HASSIO from a Pi3 to a Pi4 2 days ago
Works great and faster and all
BUT
Since then, I get this error message when I try to compile something in ESPHome …

" Error: Could not load broken JSON: /data/cache/platformio/packages/framework-arduinoespressif32/.piopm"

The YAML I am trying to upload now is the same as I used before (it’s for ESP32-Cam’s)
Tried it on other ESP32 boards too
I get the same error whet I hit the “update” or “update all” in ESPHome

I found a few topics about it already like this one Error: Could not load broken JSON: /data/cache/platformio/platforms/espressif32/.piopm
But the author’s solution is not very clear to me to be honest ^^
Plus I am not running the docker OS

Thanks to those who will have a look at my query!

Delete and reinstall the ESPHome addon.

You won’t lose anything.

Yes I forgot to mention I did that a few times already, as well as a couple system reboots …

Actually, when I uninstall ESPHome, reboot the server, reinstall ESPHome, I get a 502 Bad Gateway on ESPHome, that only disappears when I restart the server again

After restart it works but I get the error message that started this topic…

After repeating the same steps over again, it was fixed. I don’t really know what I did differently this, like, 8th time, but here are the exact steps I followed:

1 Uninstall ESPHome
2 Restart server (I did that physically and left the power plug out of the Pi for a good 5 minutes, maybe that helped but I tried that before)
3 After server restart, reinstall ESPHome
4 DON’T START ESPHOME WHEN INSTALLED, First restart server (I did it that way, but this time, via the restart button in the settings)
5 Start ESPHome, should be up and running, ready to compile and write

Good luck if you encounter this issue, hope it will help!

3 Likes

Thank you for this post.

I just had this exact error when I tried to change one of my esphome device from arduino to esp-idf type, and then when compiling things seemed to get stuck. I force reboot the HA and then I got this error.

In my case, I just need to uninstall esphome and re-install it. No need to reboot or restart HA. That fixes the error for me.

Happy I helped!

I’ve tried the solution a couple of times now, but I didn’t get it solved.
I tried serveral also some variances of rebooting and restarting.
What I could observe is that after install and reboot, the first build process in ESPHome cause a restart of HA. I don’t know why.
After that I get the

InvalidJSONFile: Could not load broken JSON: /data/cache/platformio/packages/tool-esptool/.piopm

error
Any ideas?
Issue was invented after updating to 2023.12.3

delete “/data/cache/platformio” folder. That fixes the error for me.

I didn’t have this path in my Terminal. So no cache folder under /data

1 Like

I have the same problem and configuration but no /data/cache/platformio path on my Pi4

I just had the same issue and I am commenting to this topic since it is the top response when I google. Maybe this could be of help for future users with problems.

Note! Remember the path is seen from the ESPHome containers point of view. So if you enter the docker container you can delete the files from in there.

Here is a process: Error: Could not load broken JSON: /data/cache/platformio/platforms/espressif32/.piopm - #3 by Marco.V

The only thing I would say is this. Rather than the SSH access to host + USB procedure install the Advanced SSH and Terminal: GitHub - hassio-addons/addon-ssh: Advanced SSH & Web Terminal - Home Assistant Community Add-ons. Disable protected mode, then you get access to docker command directly from SSH. Then you run the following commands:

The first command is only to find the ID of the container.

> /# docker ps | grep esphome                       
> 901c04c3f4ff   ghcr.io/esphome/esphome-hassio:2024.5.5                         "/init"                  9 minutes ago   Up 6 minutes                                                                                                                                           addon_5c53de3b_esphome
> /# docker exec -it addon_5c53de3b_esphome /bin/bash                      
> root@5c53de3b-esphome:/# rm -rf /data/cache/platformio
> root@5c53de3b-esphome:/# exit
> exit
> /# docker container restart addon_5c53de3b_esphome 
> addon_5c53de3b_esphome

Note, the ID will probably be different for you. So check the output of the first command and replace in the next commands.

1 Like