ESPHOME Code

I am not very good with ESPHOME and would like some expertise assistance if possible resolving my issue with my Lambda code, which is working but I cannot upgrade because the syntax is no longer valid, and as I copied the code, I cannot work out how to fix it.

output:
  - platform: gpio
    id: 'win_1'
    pin: D2
  - platform: gpio
    id: 'win_2'
    pin: D1

switch:
  - platform: output
    name: "win1"
    output: 'win_1'
    id: win1
  
  - platform: output
    name: "win2"
    output: 'win_2'
    id: win2
    
  - platform: restart
    name: "Bath Restart"
    id: restart_bath
    
  - platform: gpio
    name: "Underfloor Heating"
    pin: D7
    inverted: True



cover:
  - platform: template
    name: "drawer Control"
    id: win_open
    optimistic: true
    assumed_state: true
    open_action:
      - switch.turn_off: win2
      - switch.turn_on: win1
      - delay: 14s
      - switch.turn_off: win1
    close_action:
      - switch.turn_off: win1
      - switch.turn_on: win2
      - delay: 14s
      - switch.turn_off: win2
    stop_action:
      - switch.turn_off: win1
      - switch.turn_off: win2
      
binary_sensor:
  - platform: gpio
    pin: RX
    name: "Limit Switch"
    device_class: door
    on_release:
      then:
        - switch.turn_off: win2
        - switch.turn_off: win1
        
  - platform: gpio
    pin: D5
    name: "drawer Control Button"
    filters:
      invert:
    on_press: 
      then:
        - lambda: |
            if (id(win_open).state == cover::COVER_OPEN) {
              if (id(win1).state){
                // drawer is opening
                id(win_open).stop();
              } else {
                // drawer is open and not moving
                id(win_open).close();
              }
            } else {
              if (id(win2).state){
                // drawer is closing
                id(win_open).stop();
              } else {
                // win is closed and not moving
                id(win_open).open();
              }
            }

Hi.

You need to format the yaml file. In your post.
If you do that and also add the compiler error. Then we can probably figure it out.

I see that you ar missing a - after the pipe in the lambda. But it can be an artifact of that you are not using the unformated block

Like this.
The icon is </>

Yaml is very picky with the wrong formatting.

/Mattias

Ok, I manage to rectify the fomatting.

It fails compling on this line:
`

if (id(win_open).state == cover::COVER_OPEN) {

I think maybe it should be like this

        - lambda: |-

Note the last dash.

If it is not that.
Then I need the actual compiler error.

/Mattias

Hi Mattias,

I tried

        - lambda: |-

but still got an error.
As requested compiler error:

Compiling /data/bathdrawer/.pioenvs/bathdrawer/lib189/ESPAsyncTCP-esphome/ESPAsyncTCP.cpp.o
/config/esphome/bath_drawer.yaml: In lambda function:
/config/esphome/bath_drawer.yaml:97:21: error: 'class esphome::template_::TemplateCover' has no member named 'state'
             if (id(win_open).state == cover::COVER_OPEN) {
                     ^
Compiling /data/bathdrawer/.pioenvs/bathdrawer/lib189/ESPAsyncTCP-esphome/ESPAsyncTCPbuffer.cpp.o
*** [/data/bathdrawer/.pioenvs/bathdrawer/src/main.cpp.o] Error 1
Archiving /data/bathdrawer/.pioenvs/bathdrawer/lib4d9/libESP8266WiFi.a

Hi

Maybe it should be position instead.

        - lambda: |
            if (id(win_open).position == cover::COVER_OPEN) {
     

/Mattias

Hi Mattias,

Yes that seems to have fixed it…Thanks for your help

Great.

Glad I could help.
/Mattias