13857781577 发表于 2022-4-22 23:24:27

ESPHOME 编译错误请教

本帖最后由 13857781577 于 2022-4-22 23:30 编辑

7 segment clock by random1101 for ESPHome


源码:
ESPHome configuration
substitutions:
device_name: led_clock

esphome:
name: $device_name
platform: ESP8266
board: esp01_1m
on_boot:
    - light.turn_on:
      id: led_strip
      brightness: 100%
      red: 0
      green: 0
      blue: 0
      effect: "${device_name} Time effect"

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

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
    ssid: "${device_name} Fallback Hotspot"
    password: !secret wifi_fallback_api_password

logger:
level: DEBUG
# Enable Home Assistant API
api:
password: !secret hassio_api_password

ota:
password: !secret ota_password

globals:
- id: hours_red_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: hours_green_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: hours_blue_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: minutes_red_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: minutes_green_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: minutes_blue_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: dots_red_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: dots_green_value
    type: int
    restore_value: yes
    initial_value: '0'

- id: dots_blue_value
    type: int
    restore_value: yes
    initial_value: '0'

output:
#======== Hours ============
- platform: template
    id: hours_red_output
    type: float
    write_action:
      lambda: |-
      id(hours_red_value) = 255.0 * state;

- platform: template
    id: hours_green_output
    type: float
    write_action:
      - lambda: |-
          id(hours_green_value) = 255.0 * state;

- platform: template
    id: hours_blue_output
    type: float
    write_action:
      lambda: |-
      id(hours_blue_value) = 255.0 * state;

#========= Minutes ===========
- platform: template
    id: minutes_red_output
    type: float
    write_action:
      lambda: |-
      id(minutes_red_value) = 255.0 * state;

- platform: template
    id: minutes_green_output
    type: float
    write_action:
      lambda: |-
      id(minutes_green_value) = 255.0 * state;

- platform: template
    id: minutes_blue_output
    type: float
    write_action:
      lambda: |-
      id(minutes_blue_value) = 255.0 * state;

#========= dots ===========
- platform: template
    id: dots_red_output
    type: float
    write_action:
      lambda: |-
      id(dots_red_value) = 255.0 * state;

- platform: template
    id: dots_green_output
    type: float
    write_action:
      lambda: |-
      id(dots_green_value) = 255.0 * state;

- platform: template
    id: dots_blue_output
    type: float
    write_action:
      lambda: |-
      id(dots_blue_value) = 255.0 * state;

time:
- platform: sntp
    id: sntp_time
    timezone: "Europe/Moscow"
    servers:
      - 0.pool.ntp.org
      - 1.pool.ntp.org
      - 2.pool.ntp.org      

light:
- platform: rgb
    name: "${device_name} hours lights"
    id: 'hours_lights'
    red: hours_red_output
    green: hours_green_output
    blue: hours_blue_output

- platform: rgb
    name: "${device_name} minutes lights"
    id: 'minutes_lights'
    red: minutes_red_output
    green: minutes_green_output
    blue: minutes_blue_output

- platform: rgb
    name: "${device_name} dots lights"
    id: 'dots_lights'
    red: dots_red_output
    green: dots_green_output
    blue: dots_blue_output

#--------- LED strip ----------------
- platform: fastled_clockless
    id: led_strip
    name: "Led strip"
    internal: True
    pin: GPIO3
    num_leds: 30
    chipset: WS2812B
    rgb_order: GRB

    effects:
    - addressable_lambda:
      name: "${device_name} Time effect"
      update_interval: 200ms
      lambda: |-
          const int ledsInDigitCount = 7;
          const int digitsCount = 4;

          int digitsLeds = {
            {1,1,0,1,1,1,1},
            {0,0,0,1,0,0,1},
            {1,1,1,1,1,0,0},
            {1,0,1,1,1,0,1},
            {0,0,1,1,0,1,1},
            {1,0,1,0,1,1,1},
            {1,1,1,0,1,1,1},
            {0,0,0,1,1,0,1},
            {1,1,1,1,1,1,1},
            {1,0,1,1,1,1,1}
          };

          int ledOffsets = {23 , 16, 7, 0};

          auto time = id(sntp_time).now();
          int colors = {
            {id(hours_red_value), id(hours_green_value), id(hours_blue_value)},
            {id(hours_red_value), id(hours_green_value), id(hours_blue_value)},
            {id(minutes_red_value), id(minutes_green_value), id(minutes_blue_value)},
            {id(minutes_red_value), id(minutes_green_value), id(minutes_blue_value)}
          };

          int values = {};
          values = time.hour / 10;
          values = time.hour % 10;
          values = time.minute / 10;
          values = time.minute % 10;

          it.all() = Color(0,0,0);

          if ((time.second % 2) > 0) {
            it = Color(id(dots_red_value), id(dots_green_value), id(dots_blue_value));
            it = Color(id(dots_red_value), id(dots_green_value), id(dots_blue_value));
          }

          for (int valueI = 0; valueI < digitsCount; valueI++) {
            int ledsOffset = ledOffsets;
            int timeValue = values;
            int *color = colors;
            int *leds = digitsLeds;

            for (int ledI = 0; ledI < ledsInDigitCount; ledI++) {
            if(leds > 0) {
                int ledIndex = ledI + ledsOffset;
                it = Color(color, color, color);
            }
            }
          }错误提示:INFO Reading configuration /config/ledclock2.yaml...
INFO Detected timezone 'MSK' with UTC offset 3
INFO Generating C++ source...
INFO Compiling app...
INFO Running:platformio run -d /config/ledclock2
Processing ledclock2 (board: d1_mini; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
- framework-arduinoespressif8266 3.20704.0 (2.7.4)
- tool-esptool 1.413.0 (4.13)
- tool-esptoolpy 1.20800.0 (2.8.0)
- toolchain-xtensa 2.40802.200502 (4.8.2)
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <FastLED> 3.3.2
|   |-- <SPI> 1.0
|   |-- <EspSoftwareSerial> 6.8.5
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
Compiling .pioenvs/ledclock2/src/main.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/ESP8266WiFiGratuitous.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/ESP8266WiFiMulti.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/ESP8266WiFiSTA-WPS.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/ESP8266WiFiSTA.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/ESP8266WiFiScan.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/WiFiClient.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:603:16: error: no match for 'operator=' (operand types are 'esphome::light::ESPRangeView' and 'esphome::Color')
       it.all() = Color(0,0,0);
                ^
src/main.cpp:603:16: note: candidates are:
In file included from src/esphome/components/fastled_base/fastled_light.h:5:0,
               from src/esphome.h:14,
               from src/main.cpp:3:
src/esphome/components/light/addressable_light.h:374:17: note: esphome::light::ESPRangeView& esphome::light::ESPRangeView::operator=(const esphome::light::ESPColor&)
   ESPRangeView &operator=(const ESPColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:374:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPColor&'
src/esphome/components/light/addressable_light.h:378:17: note: esphome::light::ESPRangeView& esphome::light::ESPRangeView::operator=(const esphome::light::ESPColorView&)
   ESPRangeView &operator=(const ESPColorView &rhs) {
               ^
src/esphome/components/light/addressable_light.h:378:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPColorView&'
src/esphome/components/light/addressable_light.h:382:17: note: esphome::light::ESPRangeView& esphome::light::ESPRangeView::operator=(const esphome::light::ESPHSVColor&)
   ESPRangeView &operator=(const ESPHSVColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:382:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPHSVColor&'
src/esphome/components/light/addressable_light.h:386:17: note: esphome::light::ESPRangeView& esphome::light::ESPRangeView::operator=(const esphome::light::ESPRangeView&)
   ESPRangeView &operator=(const ESPRangeView &rhs);
               ^
src/esphome/components/light/addressable_light.h:386:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPRangeView&'
src/main.cpp:606:16: error: no match for 'operator=' (operand types are 'esphome::light::ESPColorView' and 'esphome::Color')
         it = Color(dots_red_value->value(), dots_green_value->value(), dots_blue_value->value());
                ^
src/main.cpp:606:16: note: candidates are:
In file included from src/esphome/components/fastled_base/fastled_light.h:5:0,
               from src/esphome.h:14,
               from src/main.cpp:3:
src/esphome/components/light/addressable_light.h:294:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPColor&)
   ESPColorView &operator=(const ESPColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:294:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPColor&'
src/esphome/components/light/addressable_light.h:298:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPHSVColor&)
   ESPColorView &operator=(const ESPHSVColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:298:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPHSVColor&'
src/main.cpp:607:16: error: no match for 'operator=' (operand types are 'esphome::light::ESPColorView' and 'esphome::Color')
         it = Color(dots_red_value->value(), dots_green_value->value(), dots_blue_value->value());
                ^
src/main.cpp:607:16: note: candidates are:
In file included from src/esphome/components/fastled_base/fastled_light.h:5:0,
               from src/esphome.h:14,
               from src/main.cpp:3:
src/esphome/components/light/addressable_light.h:294:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPColor&)
   ESPColorView &operator=(const ESPColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:294:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPColor&'
src/esphome/components/light/addressable_light.h:298:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPHSVColor&)
   ESPColorView &operator=(const ESPHSVColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:298:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPHSVColor&'
src/main.cpp:619:26: error: no match for 'operator=' (operand types are 'esphome::light::ESPColorView' and 'esphome::Color')
             it = Color(color, color, color);
                        ^
src/main.cpp:619:26: note: candidates are:
In file included from src/esphome/components/fastled_base/fastled_light.h:5:0,
               from src/esphome.h:14,
               from src/main.cpp:3:
src/esphome/components/light/addressable_light.h:294:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPColor&)
   ESPColorView &operator=(const ESPColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:294:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPColor&'
src/esphome/components/light/addressable_light.h:298:17: note: esphome::light::ESPColorView& esphome::light::ESPColorView::operator=(const esphome::light::ESPHSVColor&)
   ESPColorView &operator=(const ESPHSVColor &rhs) {
               ^
src/esphome/components/light/addressable_light.h:298:17: note:   no known conversion for argument 1 from 'esphome::Color' to 'const esphome::light::ESPHSVColor&'
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/WiFiClientSecureAxTLS.cpp.o
Compiling .pioenvs/ledclock2/lib4d9/ESP8266WiFi/WiFiClientSecureBearSSL.cpp.o
*** [.pioenvs/ledclock2/src/main.cpp.o] Error 1
========================== Took 9.63 seconds ==========================

13857781577 发表于 2022-4-22 23:33:34

不好意思 发错地方了

13857781577 发表于 2022-4-23 16:32:50

终于解决了

Replace ESPColor with Color. In newer version s of ESPHome they migrated to the "Color" class. There's a note about it in the documentation: https://esphome.io/components/light/index.html#addressable-lambda-effect
I'll update the code in description/ thank you for pointing on this issue
页: [1]
查看完整版本: ESPHOME 编译错误请教