In an esphome script, is it possible to define an array / disctionary / list and then iterate through it instead of having to uses this very inefficient code.
So an array would be something like:
- id: items
type: String[]
initial_value: '{"AT+CFUN=1,1:OK","AT+CGSOCKCONT=1,\"IP\",\"hicard\":OK"}'
etc etc and then the pseudo code would be:
script:
id: loopall
then:
for item in items
- script.execute:
id: txrx
text: item.split(':')[0]
reply: item.split(':')[1]
- script.wait: txrx
This is how I am doing it now:
script:
- id: test
then:
- script.execute:
id: txrx
text: "AT+CFUN=1,1"
reply: "OK"
- script.wait: txrx
- wait_until:
condition:
lambda: |-
return id(ready);
timeout: 60s
# AT+CGSOCKCONT=1,"IP","hicard"
# OK
- script.execute:
id: txrx
text: "AT+CGSOCKCONT=1,\"IP\",\"hicard\""
reply: "OK"
- script.wait: txrx
- if:
condition:
lambda: return id(match);
then:
# AT+CMQTTSTART
# OK
- script.execute:
id: txrx
text: "AT+CMQTTSTART"
reply: "OK"
- script.wait: txrx