Initialization of array of array globals

Hi all!
I’m creating a variable in globals with:

globals:
  - id: timers
    type: long[7][2]
    initial_value: '{{25200, 72900}, {25200, 72900}, {25200, 72900}, {25200, 72900}, {25200, 73800}, {27000, 73800}, {28800, 72900}}'

but it seems the compiler has trouble digesting the initializer

/config/esphome/foo.yaml:146:175: error: no matching function for call to ‘esphome::globals::RestoringGlobalsComponent<long int [7][2]>::RestoringGlobalsComponent()’

any suggestions?
Thanks

Something similar if I use the globals.set action like

on_...:
  - globals.set:
      id: my_global_var[0]
      value: '10'

with

IDs must only consist of upper/lowercase characters, the underscorecharacter and numbers. The character ‘[’ cannot be used.

Are arrays supported as globals at all? :thinking:

I missed an extra brace level for the initialization. This compiles:

globals:
  - id: timers
    type: unsigned long[7][2]
    initial_value: '{{{25200, 72900}, {25200, 72900}, {25200, 72900}, {25200, 72900}, {25200, 73800}, {27000, 73800}, {28800, 72900}}}'
3 Likes

Thanks for sharing back the solution.

Curious what your use case is (something to do with different timers;), and syntax for accessing individual values of the array in a lambda (I assume it is something similar to timers[3][3]?)

Cheers.

Yes, correct…

It’s a custom night light with a couple of timers based on day of the week and time of the day…

1 Like

I am trying to do a similar thing:

        - globals.set:
            id: profile_colorvar_a_i_a_r[id(current_active_profile_o_a).state][0]
            value: !lambda return id(o_a_c_1).current_values.get_red()* id(o_a_c_1).current_values.get_brightness() * 255;


but when compiling I get the error above .

IDs must only consist of upper/lowercase characters, the underscorecharacter and numbers. The character ‘[’ cannot be used.

this is the global variable definition:

# Color Variables
  - id: profile_colorvar_a_i_a_r
    type: int[$profiles_num][$colorvar_num]
    restore_value: yes

Any clue? TX

One step closer.
lambda must be used to update global arrays (according to an issue in esphome’s github)

with this

    on_state:
      then:
        - lambda:  profile_colorvar_a_o_a_r[0][0] = id(o_a_c_1).current_values.get_red()* id(o_a_c_1).current_values.get_brightness() * 255;

compiler now throws:
/config/esphome/esphome-web-b658a0.yaml: In lambda function:
/config/esphome/esphome-web-b658a0.yaml:431:34: error: no match for ‘operator[]’ (operand types are ‘esphome::globals::RestoringGlobalsComponent<int [6][4]>’ and ‘int’)
- lambda: profile_colorvar_a_o_a_r[0][0] = id(o_a_c_1).current_values.get_red()* id(o_a_c_1).current_values.get_brightness() * 255;
^
*** [/data/the-circle/.pioenvs/the-circle/src/main.cpp.o] Error 1

a “No match for operator[] error”

looks like the array is interpreted as a list…