YAML causing me problems!

Hi all,

I am trying to wrap up this clock code in ESPHome, but I am getting an error that I don’t understand how to resolve.

INFO ESPHome 2023.9.3
INFO Reading configuration /config/esphome/7-segment-clock.yaml...
ERROR Error while reading config: Invalid YAML syntax:

while parsing a block mapping
  in "/config/esphome/7-segment-clock.yaml", line 193, column 7:
          name: "${device_name} Time effect"
          ^
expected <block end>, but found '}'
  in "/config/esphome/7-segment-clock.yaml", line 249, column 7:
          }
          ^

Full YAML below. Any suggestions would be greatly appreciated!!

---
substitutions:
  device_name: poolclock

esphome:
  name: $device_name
  platform: ESP8266
  board: d1_mini
  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: "America/Los_Angeles"
    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: neopixelbus
    id: led_strip
    name: "Led strip"
    internal: True
    pin: GPIO2
    num_leds: 86
    variant: WS2812
    type: GRB

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

        int digitsLeds[10][ledsInDigitCount] = {
         // A B C D E F G
          {0,1,1,1,1,1,1}, // 0
          {0,0,0,1,1,0,0}, // 1
          {1,0,1,1,0,1,1}, // 2
          {1,0,1,1,1,1,0}, // 3
          {1,1,0,1,1,0,0}, // 4
          {1,1,1,0,1,1,0}, // 5
          {1,1,1,0,1,1,1}, // 6
          {0,0,1,1,1,0,0}, // 7
          {1,1,1,1,1,1,1}, // 8
          {1,1,1,1,1,1,0}, // 9
          #{0,0,0,0,0,0,0}, // 10 -> ALL_OFF!
          };

        int ledOffsets[digitsCount] = {0, 21, 44, 65};

        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]); }
          }
        }
      }
 

I think that the effects: block needs to be indented.

OK, I got my indentations correct. I am just getting one more set of errors, not sure why. Can anyone let me know what these mean?

Thanks!!

INFO ESPHome 2023.9.3
INFO Reading configuration /config/esphome/7-segment-clock.yaml...
WARNING Found '${displayname}' (see wifi->ap->ssid) which looks like a substitution, but 'displayname' was not declared
WARNING Found '${displayname} IP Address' (see text_sensor->0->ip_address->name) which looks like a substitution, but 'displayname' was not declared
WARNING Found '${displayname}' (see wifi->ap->ssid) which looks like a substitution, but 'displayname' was not declared
WARNING Found '${displayname} IP Address' (see text_sensor->0->ip_address->name) which looks like a substitution, but 'displayname' was not declared
substitutions:
  device_name: poolclock
esphome:
  name: poolclock
  on_boot:
  - then:
    - light.turn_on:
        id: led_strip
        brightness: 1.0
        red: 0.0
        green: 0.0
        blue: 0.0
        effect: poolclock Time effect
        state: true
    priority: 600.0
  build_path: build/poolclock
  friendly_name: ''
  platformio_options: {}
  includes: []
  libraries: []
  name_add_mac_suffix: false
  min_version: 2023.9.3
esp8266:
  board: d1_mini
  framework:
    version: 3.0.2
    source: ~3.30002.0
    platform_version: platformio/[email protected]
  restore_from_flash: false
  early_pin_init: true
  board_flash_mode: dout

The error is self explanatory.

Argh…you are right. I completely overlooked that. Thank you!

2 Likes