Hey all,
I have a relay module that uses esp32s3 and I’m trying to restore my relay state (with id relay1) to ‘OFF’ after a power reboot, if it was ‘OFF’ prior to the reboot. I’m using global variables for this. Here’s my attempt:
esphome:
name: waveshare-6ch-relay
on_boot:
then:
if:
condition:
lambda: "return id(relay1_status).state == 'false';"
then:
- switch.turn_off: relay1
esp32:
board: esp32-s3-devkitc-1
flash_size: 8MB
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
ota:
- platform: esphome
wifi:
ap:
ssid: "6CH-Relay"
captive_portal:
mqtt:
broker: 1.1.1.1
username: test1
password: test0
keepalive: 4s
globals:
- id: relay1_status
type: bool
restore_value: true
initial_value: 'false'
switch:
- platform: gpio
pin: GPIO1
id: relay1
name: Relay 1
restore_mode: RESTORE_DEFAULT_ON
on_turn_on:
then:
- globals.set:
id: relay1_status
value: 'true'
on_turn_off:
then:
- globals.set:
id: relay1_status
value: 'false'
I’m getting the following error during compile:
Compiling .pioenvs/waveshare-6ch-relay/src/main.cpp.o
/config/esphome/waveshare-6ch-relay-wifi-mqtt-only.yaml:7:46: warning: character constant too long for its type
lambda: "return id(relay1_status).state == 'false';"
^~~~~~~
/config/esphome/waveshare-6ch-relay-wifi-mqtt-only.yaml: In lambda function:
/config/esphome/waveshare-6ch-relay-wifi-mqtt-only.yaml:7:37: error: request for member 'state' in 'relay1_status->esphome::globals::RestoringGlobalsComponent<bool>::value()', which is of non-class type 'bool'
lambda: "return id(relay1_status).state == 'false';"
^~~~~
*** [.pioenvs/waveshare-6ch-relay/src/main.cpp.o] Error 1
========================== [FAILED] Took 9.31 seconds ==========================
Not sure what this means,
I also tried :
on_boot:
then:
- lambda: |-
if (!id(relay1_status)) {
id(relay1).turn_off();
}
And this compiled but for some odd reason that I’m struggling to figure out, it didn’t work. relay1 turned on even when it was off prior to a reboot.
Thanks.