esphome / issues

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

Is __FILE__ broken or not supported? #5449

Open michaelblight opened 7 months ago

michaelblight commented 7 months ago

The problem

I had this code a long time ago (as in a few years), and it worked to provide the source file in a sensor:

text_sensor:
  - platform: template
    name: "${name} Base"
    id: "${id}_base"
    lambda: |-
      return { __FILE__ };
    update_interval: 1h

However now it always produces "".

Which version of ESPHome has the issue?

2023.12.9

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.12.4

What platform are you using?

ESP32

Board

m5stick-c

Component causing the issue

text_sensor

Example YAML snippet

substitutions:
  name: m5stick-c-1
  id: m5stick_c_1
  logs_default: INFO
  logs_esp32_ble_tracker: INFO
  display_lambda: |-
    it.fill(color_orange_deep);
    it.print(80, 30, id(font1), color_black, TextAlign::TOP_CENTER, "Scale");

packages:
  device_base: !include include/m5stick-c-base.yaml

color:
  - id: color_orange_deep
    red: 93%
    green: 46%
    blue: 0%
  - id: color_black
    red: 0%
    green: 0%
    blue: 0%

font:
  - id: font1
    file: "gfonts://Roboto"
    size: 24

And this is the content of m5stick-c-base.yaml:

substitutions:
  logs_default: INFO
  logs_esp32_ble_tracker: INFO
  display_lambda: ""

external_components:
  - source: github://martydingo/esphome-axp192
    components: [axp192]

esphome:
  name: $name
  platform: ESP32
  board: m5stick-c

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

logger:
  level: ${logs_default}
  logs:
    esp32_ble_tracker: ${logs_esp32_ble_tracker}

ota:
  password: !secret wifi_password

api:
captive_portal:

spi:
  clk_pin: GPIO13
  mosi_pin: GPIO15

i2c:
  - id: bus_a
    sda: GPIO21
    scl: GPIO22
    scan: true

sensor:
  - platform: axp192
    model: M5STICKC
    address: 0x34
    i2c_id: bus_a
    update_interval: 30s

light:
  - platform: monochromatic
    output: builtin_led
    name: ${name} Led
    id: "${id}_led"

output:
  - platform: ledc
    pin: 10
    inverted: true
    id: builtin_led

text_sensor:
  - platform: template
    name: "${name} Compile Date"
    id: "${id}_compile_date"
    lambda: |-
      return { __DATE__ " " __TIME__ };
    update_interval: 1h
  - platform: template
    name: "${name} Base"
    id: "${id}_base"
    lambda: |-
      return { __FILE__ };
    update_interval: 1h

display:
  - platform: st7735
    model: "INITR_MINI160X80"
    device_height: 160
    device_width: 82
    col_start: 0
    row_start: 0
    eight_bit_color: false
    cs_pin: GPIO5
    dc_pin: GPIO23
    reset_pin: GPIO18
    invert_colors: true
    use_bgr: true
    rotation: 270
    update_interval: 2s
    lambda: |-
      ${display_lambda}

Anything in the logs that might be useful for us?

Additional information

I am also using the following and this works fine:

  - platform: template
    name: "${name} Compile Date"
    id: "${id}_compile_date"
    lambda: |-
      return { __DATE__ " " __TIME__ };
    update_interval: 1h

image

marshn commented 7 months ago

I use __FILE__ in exactly the same way, and it broke with ESPHome v2023.12. For me it has been resolved by PR https://github.com/esphome/esphome/pull/6139 which didn't make it into v2023.12.9, I'm hoping the fix will be included in v2023.12.10 or v2024.2. Also see https://github.com/esphome/issues/issues/5354 https://github.com/esphome/issues/issues/5377 https://github.com/esphome/issues/issues/5423.

marshn commented 6 months ago

esphome 2024.2 has has resolved this issue, for me at least.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.