『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1956|回复: 2

ESPHOME 编译错误请教

[复制链接]

25

主题

441

帖子

2348

积分

论坛积极会员

积分
2348
金钱
1907
HASS币
0
发表于 2022-4-22 23:24:27 | 显示全部楼层 |阅读模式
本帖最后由 13857781577 于 2022-4-22 23:30 编辑

7 segment clock by random1101 for ESPHome
d2b5ca33bd970f64a6301fa75ae2eb22_preview_card.jpg

源码:
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[10][ledsInDigitCount] = {
            {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[digitsCount] = {23 , 16, 7, 0};

          auto time = id(sntp_time).now();
          int colors[4][3] = {
            {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[digitsCount] = {};
          values[0] = time.hour / 10;
          values[1] = time.hour % 10;
          values[2] = time.minute / 10;
          values[3] = time.minute % 10;

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

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

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

            for (int ledI = 0; ledI < ledsInDigitCount; ledI++) {
              if(leds[ledI] > 0) {
                int ledIndex = ledI + ledsOffset;
                it[ledIndex] = Color(color[0], color[1], color[2]);
              }
            }
          }
错误提示:
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[14] = 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[15] = 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[ledIndex] = Color(color[0], color[1], color[2]);
                          ^
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
========================== [FAILED] Took 9.63 seconds ==========================


回复

使用道具 举报

25

主题

441

帖子

2348

积分

论坛积极会员

积分
2348
金钱
1907
HASS币
0
 楼主| 发表于 2022-4-22 23:33:34 | 显示全部楼层
不好意思 发错地方了
回复

使用道具 举报

25

主题

441

帖子

2348

积分

论坛积极会员

积分
2348
金钱
1907
HASS币
0
 楼主| 发表于 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/li ... sable-lambda-effect
I'll update the code in description/ thank you for pointing on this issue
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 01:01 , Processed in 0.048700 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表