ESP device log to file?

I’m perplexed at not finding the answer to this pretty easily. Maybe I’m not searching for the right thing.

I would like to send the log from an ESP32 running Esphome to a file, either directly or via HA or MQTT or something else. The method doesn’t matter too much but I want to collect some extended data. My device is sending a hex command via UART to a modbus slave which then returns a hex string which has bytes that change frequently. I want to gather all the hex string responses - 1 per minute - over 24 hours.

The string appears in the log for the device but how do I get it into a file or some other data collection repository?

from the commandline run

esphome logs mydevice.yaml > mydevice.log

If you are using docker (including the addon) you need to enter the docker container first.

Not on Docker, running HassOS on NUC. By commandline, I assumed you meant a terminal in HA but when I do that, I get ‘bash: esphome: command not found’.

Follow steps in this thread/guide to get the SSH and Web Terminal configured.

but use this command to get a command line for the esphome addon docker container

docker exec -it $(docker ps -f name=esphome -q) bash

I have the Terminal & SSH add-on already and I’m not using Docker. HA Core 2022.11.4 on HassOS 9.3 but I get the error in post #3.

It needs to be the SSH & Web Terminal with protection mode disabled in order to execute docker

I don’t know how else to communicate that i’m NOT using Docker. There is no ‘Protection Mode’ in my front-end for this.

So, I discovered that I was using the official add-on so I swapped that out for the community add-on from Frenk. I now see the ‘Protection Mode’ and have disabled it. I now get ‘zsh: command not found: esphome’

So, after a great deal of searching and reading, it seems that the official Esphome page and just about every other source references Docker installs. I cannot find anything for an Esphome install on HassOS that is running natively on Intel with no Docker.

As far as I can see, there is no esphome executable in this instance or if there is, it is hidden way back in the HassOS system. I doubt I’m the first one running up against this and yet, I can’t seem to find anyone else in the same position on the same platform.

You are running docker. How the hell do you think hassos works?

If you have addons, you are using containers. Containers are run in docker. HAOS uses the supervisor to control docker.

I am not sure what you called your device I used ampinvt.yaml from your modbus thread

docker exec -it addon_5c53de3b_esphome /bin/bash

cd /config/esphome

esphome logs ampinvt.yaml > mydevice.yaml

The file will be in your esphome folder in file editor

in screenshot form


Considering you are using the addon.
You can just download the logs from the Logs window of your esphome device too.

logs download

1 Like

As I said in post 2

I discovered something in the Discord chat while chasing this down. Back in early 2022, ESPhome ‘changed tracks’ and the last released version of the ‘old track’ was 2022.3.1. Somehow, I missed all the notices about this so while I was on the latest version of everything else, my ESPhome was 2022.3.1.

In that scenario, the command ‘docker exec -it {options here]’ also results in ‘command not found’ which is what I was getting. The info here was key for me. What was throwing me off is that I do have a Docker system, I just do not run Home Assistant on it. The fact that HA uses Docker in the background is probably something I knew way back when I first installed it but had completely forgotten. Regardless, until I uninstalled the 2022.3.1 version and installed the 2022.11.1 version, the command ‘docker exec -it [ ]’ failed with 'command not found. Hopefully this will be useful for someone else that finds this thread in the future. I have confirmed that the docker command works with the new version but I’m currently busy with all the device updates that the new Esphome version brought along with it.

So “sorry guys that I didn’t know Hassos used docker to run HA and its addons, I have learned something, thank you”

“You’re welcome.”

I certainly learned something, I always do on here. The #4 post from @mulcmu was very helpful AFTER figuring out why the docker exec command wasn’t working and returning the same failure as the esphome command. That is a valuable lesson for anyone who reads this thread in the future. The issue here isn’t in whether I remembered or connected with HassOS using Docker in the back end but in that I had missed the Feb and April changelogs where the shift in Esphome track had occured. If I had been on top of that one then the docker stuff would have run. Strangely, your #2 post still fails for me for some reason but the command in post #4 succeeds. It generates a user selection in the log but not in the console and hangs until selected (I have a DeConz USB and it needs input to choose between that and the esphome api) but then runs flawlessly.

Are you having a bad day, @nickrout ? It’s not like you to be so antagonistic. I’m always grateful for your help on here and that of others.