esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 34 forks source link

ERROR Could not find auto generated code begin in file, either delete the main sketch file or insert the comment again. #4463

Open spitfire opened 1 year ago

spitfire commented 1 year ago

The problem

I'm getting: ERROR Could not find auto generated code begin in file, either delete the main sketch file or insert the comment again. I used to be able to compile it with versions <= 2023.4.0, but now it is failing.

Which version of ESPHome has the issue?

2023.4.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.4.6

What platform are you using?

ESP32

Board

esp32dev

Component causing the issue

No response

Example YAML snippet

esphome:
  name: foxess-inverter
  includes:
    - foxess_t_series.h

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: VERBOSE
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key 

ota:
  password: !secret esphome_ota

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret domain

  ap:
    ssid: "Inverter Fallback Hotspot"
    password: !secret esphome_ota

captive_portal:

#bluetooth_proxy:
  #active: true

uart:
  id: uart_bus
  tx_pin: 16
  rx_pin: 17
  baud_rate: 9600
  debug:

button:
  - platform: restart
    name: "Foxess inverter restart"

switch:
  - platform: gpio
    pin: 4
    name: "T-Series sending mode" #if "on" reading from inverter doesn't work!
    internal: true #switch is not exposed to HA frontend, should you ever need to write to the inverter, just comment this line

text_sensor:
  - platform: template
    name: "T-Series Inverter Mode"
    id: "inverter_mode_text_sensor"
    icon: mdi:solar-power-variant

sensor:
- platform: custom
  lambda: |-
    auto foxesssensors = new foxesscomponent(id(uart_bus));
    App.register_component(foxesssensors);
    return {\
    foxesssensors->grid_power, \
    foxesssensors->generation_power, \
    foxesssensors->loads_power, \
    foxesssensors->grid_voltage_r, \
    foxesssensors->grid_current_r, \
    foxesssensors->grid_frequency_r, \
    foxesssensors->grid_power_r, \
    foxesssensors->grid_voltage_s, \
    foxesssensors->grid_current_s, \
    foxesssensors->grid_frequency_s, \
    foxesssensors->grid_power_s, \
    foxesssensors->grid_voltage_T, \
    foxesssensors->grid_current_T, \
    foxesssensors->grid_frequency_T, \
    foxesssensors->grid_power_T, \
    foxesssensors->pv1_voltage, \
    foxesssensors->pv1_current, \
    foxesssensors->pv2_voltage, \
    foxesssensors->pv2_current, \
    foxesssensors->pv3_voltage, \
    foxesssensors->pv3_current, \
    foxesssensors->pv4_voltage, \
    foxesssensors->pv4_current, \
    foxesssensors->boost_temperature, \
    foxesssensors->inverter_temperature, \
    foxesssensors->ambient_temperature, \
    foxesssensors->today_yield, \
    foxesssensors->generation_total, \
    foxesssensors->pv1_power, \
    foxesssensors->pv2_power, \
    foxesssensors->pv3_power, \
    foxesssensors->pv4_power, \
    foxesssensors->inverter_state\
    };

  sensors:
  - name: "T-Series Grid Power"
    id: "grid_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series Generation Power"
    id: "generation_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series loads Power"
    id: "loads_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series Grid Voltage R"
    id: "grid_voltage_r"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Current R"
    id: "grid_current_r"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Frequency R"
    id: "grid_Frequency_r"
    unit_of_measurement: Hz
    accuracy_decimals: 2
    icon: mdi:sine-wave
    filters:
    - multiply: 0.01
    - throttle: 1h

  - name: "T-Series Grid Power R"
    id: "grid_power_r"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series Grid Voltage S"
    id: "grid_voltage_s"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Current S"
    id: "grid_current_s"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Frequency S"
    id: "grid_Frequency_s"
    unit_of_measurement: Hz
    accuracy_decimals: 2
    icon: mdi:sine-wave
    filters:
    - multiply: 0.01
    - throttle: 1h

  - name: "T-Series Grid Power S"
    id: "grid_power_s"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series Grid Voltage T"
    id: "grid_voltage_T"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Current T"
    id: "grid_current_t"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1
    - throttle: 1h

  - name: "T-Series Grid Frequency T"
    id: "grid_Frequency_t"
    unit_of_measurement: Hz
    accuracy_decimals: 2
    icon: mdi:sine-wave
    filters:
    - multiply: 0.01
    - throttle: 1h

  - name: "T-Series Grid Power T"
    id: "grid_power_t"
    unit_of_measurement: W
    icon: mdi:lightning-bolt

  - name: "T-Series PV1 Voltage"
    id: "pv1_voltage"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1

  - name: "T-Series PV1 Current"
    id: "pv1_current"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1

  - name: "T-Series PV2 Voltage"
    id: "pv2_voltage"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1

  - name: "T-Series PV2 Current"
    id: "pv2_current"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1

  - name: "T-Series PV3 Voltage" #only relevant for models T8dual-T12dual and T15-T25
    id: "pv3_voltage"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1

  - name: "T-Series PV3 Current" #only relevant for models T8dual-T12dual and T15-T25
    id: "pv3_current"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1

  - name: "T-Series PV4 Voltage" #only relevant for models T8dual-T12dual and T15-T25
    id: "pv4_voltage"
    unit_of_measurement: V
    accuracy_decimals: 1
    icon: mdi:flash
    filters:
    - multiply: 0.1

  - name: "T-Series PV4 Current" #only relevant for models T8dual-T12dual and T15-T25
    id: "pv4_current"
    unit_of_measurement: A
    accuracy_decimals: 1
    icon: mdi:current-ac
    filters:
    - multiply: 0.1

  - name: "T-Series Boost Temperature" #boost temperature and inverter temperature seem to be always the same
    id: "boost_temperature"
    unit_of_measurement: °C
    filters:
    - throttle: 10min

  - name: "T-Series Inverter Temperature" #boost temperature and inverter temperature seem to be always the same
    id: "inverter_temperature"
    unit_of_measurement: °C
    filters:
    - throttle: 10min

  - name: "T-Series Ambient Temperature"
    id: "ambient_temperature"
    unit_of_measurement: °C
    filters:
    - throttle: 10min

  - name: "T-Series Today Yield"
    id: "today_yield"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    icon: mdi:solar-power
    filters:
    - multiply: 0.1

  - name: "T-Series Generation Total"
    id: "generation_total"
    unit_of_measurement: kWh
    device_class: energy #for use in energy dashboard
    state_class: total_increasing #for use in energy dashboard
    accuracy_decimals: 1
    icon: mdi:solar-power
    filters:
    - multiply: 0.1

  - name: "T-Series PV1 Power" #rs485 comm says this is always 0W, so this is calculated in the .h file by voltage*current
    id: "pv1_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt
    accuracy_decimals: 1

  - name: "T-Series PV2 Power" #rs485 comm says this is always 0W, so this is calculated in the .h file by voltage*current
    id: "pv2_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt
    accuracy_decimals: 1

  - name: "T-Series PV3 Power" #rs485 comm says this is always 0W, so this is calculated in the .h file by voltage*current
    id: "pv3_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt
    accuracy_decimals: 1

  - name: "T-Series PV4 Power" #rs485 comm says this is always 0W, so this is calculated in the .h file by voltage*current
    id: "pv4_power"
    unit_of_measurement: W
    icon: mdi:lightning-bolt
    accuracy_decimals: 1

  - name: "T-Series Inverter State"
    id: "inverter_state"
    internal: true
    on_value:
      then:
        - lambda: |-
            if(x==0) {
              id(inverter_mode_text_sensor).publish_state("Offline");
            }
            else if(x==1) {
              id(inverter_mode_text_sensor).publish_state("Online");
            }
            else if(x==2) {
              id(inverter_mode_text_sensor).publish_state("Error");
            }
            else {
              id(inverter_mode_text_sensor).publish_state("Waiting for response...");
            }

Anything in the logs that might be useful for us?

No response

Additional information

The referenced/included .h file can be found at https://github.com/assembly12/Foxess-T-series-ESPHome-Home-Assistant/blob/main/foxess_t_series.h and also has not been changed.

ssieb commented 1 year ago

You didn't include the logs. If you haven't modified the main.cpp file, then try a clean build.

spitfire commented 1 year ago

@ssieb which logs should I include? How do I start a clean build?

ssieb commented 1 year ago

The compile logs, wherever you're seeing that error message. In the menu, there's an option to clean the build files.

spitfire commented 1 year ago

Tried cleaning build files, the issue persists. Here's the log output for installation:

INFO Reading configuration /config/esphome/foxess-inverter.yaml...
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Generating C++ source...
ERROR Could not find auto generated code begin in file, either delete the main sketch file or insert the comment again.
spitfire commented 1 year ago

@ssieb Any idea what that is? my other ESPHome devices seem to be updating fine, so it's probably a matter of some component used in this one.

huenemeca commented 1 year ago

I have 2 devices doing this now.

ssieb commented 1 year ago

@spitfire do you use the custom component in any other devices? Can you attach the main.cpp here if you can find it? I think the data directory is accessible from the HA base OS. @huenemeca are you using any custom components in those devices? Same request as well for the main.cpp file.

spitfire commented 1 year ago

@spitfire do you use the custom component in any other devices? Can you attach the main.cpp here if you can find it? I think the data directory is accessible from the HA base OS. @huenemeca are you using any custom components in those devices? Same request as well for the main.cpp file.

All that I have in that project is the yaml file with content pasted in bug description along with the header (.h) file (from https://github.com/assembly12/Foxess-T-series-ESPHome-Home-Assistant/blob/main/foxess_t_series.h) next to it, there is no .cpp file in there (the only C++ code is in the yaml, which I'm attaching here: foxess-inverter.yaml.zip). This project used to compile with ESPHome 2023.4.*

ssieb commented 1 year ago

You have to get it from the build directory.

spitfire commented 1 year ago

It doesn't even create one. After I've cleaned last build files (as suggested earlier) it doesn't create a new one. All other projects' files are there:

homeassistant01# pwd
/usr/share/hassio/addons/data/5c53de3b_esphome
homeassistant01# ls -l
total 4
drwxr-xr-x 1 root root 20 Apr 26 16:10 cache
drwxr-xr-x 1 root root 38 May 25 13:13 esp32-gabinet
drwxr-xr-x 1 root root 38 May 25 13:13 esp32-kotlownia
-rw------- 1 root root  2 May 29 03:24 options.json
drwxr-xr-x 1 root root 38 May 25 13:14 poziomwody-test
drwxr-xr-x 1 root root 38 May 25 13:14 t-can485-foxess
drwxr-xr-x 1 root root 38 May 29 09:41 ttgo01
drwxr-xr-x 1 root root 38 May 25 13:14 ttgo-dongle01
drwxr-xr-x 1 root root 38 May 29 09:42 ttgo-tdisplay-s3-01
drwxr-xr-x 1 root root 38 Apr 27 13:29 wodomierz

I guess it fails when generating source.

spitfire commented 1 year ago

Anything else I can check?

JohnBaumb commented 1 year ago

I am also getting this error with this very simple config:

substitutions:
  device_name: porch-light

esphome:
  name: porch-light
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 10.0.0.208
    gateway: 10.0.0.1
    subnet: 255.255.255.0
    dns1: 10.0.0.60
    dns2: 8.8.8.8
  #fast_connect: true
  ap:
    ssid: "Porch-Light Fallback Hotspot"
    password: !secret wifi_password

# Enable logging
logger:
  # default is DEBUG
  #level: VERBOSE

# Enable Home Assistant API
api:

ota:

web_server:

switch:
  - platform: restart
    name: "Porch Light Restart"

  - name: "Porch Light"
    platform: gpio
    pin: GPIO4
    id: relay
    #restore_mode: ALWAYS_OFF

sensor:
  - platform: uptime
    name: "Porch Light Uptime"
    update_interval: 60s

  - platform: wifi_signal
    name: "Porch Light WiFi Signal"
    update_interval: 60s

binary_sensor:
  - platform: gpio
    name: Porch Light Switch
    pin: GPIO5
    on_press:
      then:
        - switch.turn_on: relay
    on_release:
      then:
        - switch.turn_off: relay

I've deleted all additional files besides the yaml in an effort to diagnose, and clean build as well, no change.

EDIT: Renaming Hostname in the UI allowed me to compile and flash, but cannot rename back to the old name afterwards.

spitfire commented 11 months ago

Still doesn't work, and hasn't been for 3 months now. Anything else I can try?

1nterlud3 commented 8 months ago

I also got this error. Any fixes or causes? It seams that the generation crashes.

> INFO ESPHome 2023.10.0
> INFO Reading configuration /config/esphome/inside-garage.yaml...
> INFO Generating C++ source...
> ERROR Could not find auto generated code begin in file, either delete the main sketch file or insert the comment again.
spitfire commented 8 months ago

While cleaning the build files didn't help renaming hostname in ESPHome did ¯_(ツ)_/¯

noispe commented 3 weeks ago

Now I also got this error, but I was able to fix it without changing the hostname. I think my problem started with switching different versions of ESP-IDF.

Cleaning the build files has left some remains inside the build directory. Deleting the whole subdirectory of the device inside the build directory did the magic - my device now compiles fine again.

e.g.: build path: esphome/.esphome/build device name: foxess-inverter

-> delete directory (and everything inside): esphome/.esphome/build/foxess-inverter