ESPHome TTGO display issues

Hi,
I’m playing with TTGO display running ESPhome. I have it running just fine but I’m struggling with one issue and I was hoping that someone her know how to address it or came across something similar in their HA journeys.

My Display will be acting as a basic Alarm display monitor - basically displaying if Alarm is on or off.
I have my alarms managed with automations

The bit I am struggling is I want to show in green when my siren automation is disabled (off state)
and in red when it is enabled (on state)

This is my config:

esphome:
  name: alarm-display
  platform: ESP32
  board: featheresp32


wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  - ssid: !secret wifi2_ssid
    password: !secret wifi_password

color:
  - id: my_red
    red: 100%
    green: 0%
    blue: 0%
  - id: my_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: my_green
    red: 0%
    green: 100%
    blue: 0%

font:
  - file: "Helvetica.ttf"
    id: helvetica_24
    size: 24

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      inverted: true
    name: ${devicename}top push
    id: tdisplay_button_input_0

  - platform: gpio
    pin:
      number: GPIO35
      inverted: true
    id: tdisplay_button_input_1
    name: ${devicename}bottom push

switch:
  - platform: restart
    name: ${devicename} restart

text_sensor:
  - platform: homeassistant
    id: alarm1
    entity_id: automation.alarm1
    name: "Alarm Door"
  - platform: homeassistant
    id: alarm2
    entity_id: automation.alarm2
    name: "iPhone Notification"
  - platform: homeassistant
    id: alarm3
    entity_id: automation.alarm3
    name: "Siren"

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

display:
  - platform: st7789v
    backlight_pin: GPIO4
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
    rotation: 270
    lambda: |-
      it.printf(4, 0, id(helvetica_24), id(my_yellow), "Door Alarm: %s", id(alarm1).state.c_str());
      it.printf(4, 28, id(helvetica_24), id(my_yellow), "Voice notification: %s", id(alarm2).state.c_str());
      if (id(alarm3).state=off) {
        it.printf(4, 56, id(helvetica_24), id(my_green), "Siren: %s", id(alarm3).state.c_str());
      } else {
        it.printf(4, 56, id(helvetica_24), id(my_red), "Siren: %s", id(alarm3).state.c_str());
      }
            

When I try to install that code on my display in ESPhome I get this error:


/config/esphome/alarm-display-szopa.yaml: In lambda function:
/config/esphome/alarm-display-szopa.yaml:119:25: error: 'off' was not declared in this scope
       if (id(alarm3).state=off) {
                         ^
Compiling /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/lib64d/WiFi/WiFiClient.cpp.o
Archiving /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/lib528/libAsyncTCP-esphome.a
Compiling /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/lib64d/WiFi/WiFiGeneric.cpp.o
*** [/data/alarm-display-szopa/.pioenvs/alarm-display-szopa/src/main.cpp.o] Error 1
========================= [FAILED] Took 20.18 seconds =========================

Any ideas how to address this issue?
Thanks

Probably because you forgot the quotes around off. It’s a string, but the compiler thinks it’s a variable.

      if (id(alarm3).state="off") {

that in return gives me this error:

/config/esphome/alarm-display-szopa.yaml: In lambda function:
/config/esphome/alarm-display-szopa.yaml:119:30: error: could not convert 'alarm3->esphome::homeassistant::HomeassistantTextSensor::<anonymous>.esphome::text_sensor::TextSensor::state.std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=<char, std::char_traits<char>, std::allocator<char> >(((const char*)"off"))' from 'std::__cxx11::basic_string<char>' to 'bool'
       if (id(alarm3).state="off") {
                              ^
Compiling /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/lib01c/FS/vfs_api.cpp.o
*** [/data/alarm-display-szopa/.pioenvs/alarm-display-szopa/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.19 seconds ==========================

Always get caught with that… :slight_smile: Try:

      if (id(alarm3).state.c_str()="off") {

that gives me:

/config/esphome/alarm-display-szopa.yaml: In lambda function:
/config/esphome/alarm-display-szopa.yaml:119:33: error: lvalue required as left operand of assignment
        if (id(alarm3).state.c_str()="off") {
                                 ^
Archiving /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/lib915/libESPmDNS.a
Compiling /data/alarm-display-szopa/.pioenvs/alarm-display-szopa/FrameworkArduino/HardwareSerial.cpp.o
*** [/data/alarm-display-szopa/.pioenvs/alarm-display-szopa/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.91 seconds ==========================

Is alarm3 a boolean value? Sorry I should have read further into the error message.

If it is - try:

      if (id(alarm3).state=false) {

Otherwise post your sensor definition.

alarm3 has two state values: on or off
it is defined in the esphome yaml config as a test sensor (see my initial post)
on the homeassistant side this is automation

Sorry it’s late (or early morning really) here - not firing on all cylinders.

Fairly certain the first suggestion should have worked, but I’m dumb and missed the other error:

      if (id(alarm3).state=="off") {

You were using an assignment operator - not a comparison.

ahh yes - that looks much better
thank you