D1Mini Lambda Code Issue Motor Window

Hi! This is more or less my first tinkering with a project to have an actuator opening and closing a window. In reference to this tutorial DrZzs Motor Window i have some problems.

The code which I use is this one:

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

switch:
  - platform: output
    name: "win1"
    output: 'win_1'
    id: win1
  - platform: output
    name: "win2"
    output: 'win_2'
    id: win2

cover:
  - platform: template
    name: "Window Control"
    id: win_open
    optimistic: true
    open_action:
      - switch.turn_off: win2
      - switch.turn_on: win1
      - delay: 360s
      - switch.turn_off: win1
    close_action:
      - switch.turn_off: win1
      - switch.turn_on: win2
      - delay: 360s
      - switch.turn_off: win2
    stop_action:
      - switch.turn_off: win1
      - switch.turn_off: win2
     

binary_sensor:
  - platform: gpio
    pin: D3
    name: "Window Control Button"
    filters:
      invert:
    on_press: 
      then:
        - lambda: |
            if (id(win_open).position == cover::COVER_OPEN) {
              if (id(win1).state){
                // window is opening
                id(win_open).make_call().set_command_stop();
              } else {
                // window is open and not moving
                id(win_open).make_call().set_command_close();
              }
            } else {
              if (id(win2).state){
                // window is closing
                id(win_open).make_call().set_command_stop();
              } else {
                // win is closed and not moving
                id(win_open).make_call().set_command_open();
              }
            }

When I power up everything (using a proper 12V 5A power suppy) I can see my D1 online and reacting to my template in Home Assistant. The motor although doesnt make a move at all. Also when I push the button, nothing happens. Just to double check, I changed the D1, the motor controller and tested the actuator directly on the power supply.

When I just copy and pasted the code from DrZzs, it gave me some errors. The first was this one:

Compiling /data/zimmer3-motor-oberlicht/.pioenvs/zimmer3-motor-oberlicht/src/main.cpp.o
/config/esphome/zimmer3-motor-oberlicht.yaml: In lambda function:
/config/esphome/zimmer3-motor-oberlicht.yaml:73:21: error: 'class esphome::template_::TemplateCover' has no member named 'state'
             if (id(win_open).state == cover::COVER_OPEN) {
                     ^
/config/esphome/zimmer3-motor-oberlicht.yaml:76:26: warning: 'void esphome::cover::Cover::stop()' is deprecated (declared at src/esphome/components/cover/cover.h:141): stop() is deprecated, use make_call().set_command_stop() instead. [-Wdeprecated-declarations]
                 id(win_open).stop();
                          ^
/config/esphome/zimmer3-motor-oberlicht.yaml:79:27: warning: 'void esphome::cover::Cover::close()' is deprecated (declared at src/esphome/components/cover/cover.h:135): close() is deprecated, use make_call().set_command_close() instead. [-Wdeprecated-declarations]
                 id(win_open).close();
                           ^
/config/esphome/zimmer3-motor-oberlicht.yaml:84:26: warning: 'void esphome::cover::Cover::stop()' is deprecated (declared at src/esphome/components/cover/cover.h:141): stop() is deprecated, use make_call().set_command_stop() instead. [-Wdeprecated-declarations]
                 id(win_open).stop();
                          ^
/config/esphome/zimmer3-motor-oberlicht.yaml:87:26: warning: 'void esphome::cover::Cover::open()' is deprecated (declared at src/esphome/components/cover/cover.h:129): open() is deprecated, use make_call().set_command_open() instead. [-Wdeprecated-declarations]
                 id(win_open).open();
                          ^
*** [/data/zimmer3-motor-oberlicht/.pioenvs/zimmer3-motor-oberlicht/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.66 seconds ==========================

Referring to @lawrencez and @birchman Profile - lawrencez - Home Assistant Community) post -click- i changed “state” to position. The other deprecated code parts i changed also.

So, can somebody point me in the right direction? This project is just too cool, to give up :wink:

Thanks and have a nice sunday!!

Tom

Hi.
I dont see anything obvious in the configuration except that the D3 is usually not a good pin to use if you are using a esp8266. It is connected to flash memory and may give you trouble to boot.
ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials for future pin selection. Use any of D5,D6 or D7. The D1 and D2 is good pin to use (and you already do)

What does the logs say when you are running.
(Logger Component — ESPHome)

Maybe it will be easier to spot what going wrong. The you can see that you are register the button presses.
/Mattias

Hi Mattias!!
Thank you for reviewing my code. So, the changes I made are correct? I’m really a bit confused. BTW, this is the board I use: -Klick- One customer complained about, that the Pins dont correlate with the Gpio, but as far as I can compare, it should be ok. Really strange, that the Push Button shows no reaction at all. Hm.

Tomorrow I will check out the logger function. Since im no expert at all with esp, please forgive me some silly questions ;-). Stay tuned :slight_smile:

Tom

Well, im an Idiot. I got 5 of those boards, and powered all on, to check if they are working properly. While I flashed the first one, I mixed it up with another unflashed one and left both powered on. So I had all those responses in the HA and wondered why I couldnt measure anything. Wow, I should stop do that stuff after a working day :sweat_smile:

Anyway, the D1 Mini works as expected, and shows me also in HA when I push the button. Since I reverted to the original code, the actuator isn’t moving. But I will debug this also.

Thank you @birchman! This project is extremely cool, because you can basically do anything with it.

Hi

Great that you found the issue. The best issues are the solved ones.
Esphome has found the balance with relative simple configuration and also the flexibility to do more advanced stuff with lambdas and actions.

I wish you luck with the rest of the project.

/Mattias

1 Like

Hello! I’m also trying to work through DrZzs video to control a transom window. I’ve run into a similar error when compiling.

Compiling /data/3fnw-transom/.pioenvs/3fnw-transom/src/main.cpp.o
/config/esphome/3fnw-transom.yaml: In lambda function:
/config/esphome/3fnw-transom.yaml:75:26: warning: 'void esphome::cover::Cover::stop()' is deprecated (declared at src/esphome/components/cover/cover.h:141): stop() is deprecated, use make_call().set_command_stop() instead. [-Wdeprecated-declarations]
                 id(win_open).stop();
                          ^
/config/esphome/3fnw-transom.yaml:78:27: warning: 'void esphome::cover::Cover::close()' is deprecated (declared at src/esphome/components/cover/cover.h:135): close() is deprecated, use make_call().set_command_close() instead. [-Wdeprecated-declarations]
                 id(win_open).close();
                           ^
/config/esphome/3fnw-transom.yaml:83:26: warning: 'void esphome::cover::Cover::stop()' is deprecated (declared at src/esphome/components/cover/cover.h:141): stop() is deprecated, use make_call().set_command_stop() instead. [-Wdeprecated-declarations]
                 id(win_open).stop();
                          ^
/config/esphome/3fnw-transom.yaml:86:26: warning: 'void esphome::cover::Cover::open()' is deprecated (declared at src/esphome/components/cover/cover.h:129): open() is deprecated, use make_call().set_command_open() instead. [-Wdeprecated-declarations]
                 id(win_open).open();
                          ^
Linking /data/3fnw-transom/.pioenvs/3fnw-transom/firmware.elf
Retrieving maximum program size /data/3fnw-transom/.pioenvs/3fnw-transom/firmware.elf
Checking size /data/3fnw-transom/.pioenvs/3fnw-transom/firmware.elf
Building /data/3fnw-transom/.pioenvs/3fnw-transom/firmware.bin
RAM:   [====      ]  38.6% (used 31588 bytes from 81920 bytes)
Flash: [====      ]  40.2% (used 411456 bytes from 1023984 bytes)
Creating BIN file "/data/3fnw-transom/.pioenvs/3fnw-transom/firmware.bin" using "/root/.platformio/packages/framework-arduinoespressif8266/bootloaders/eboot/eboot.elf" and "/data/3fnw-transom/.pioenvs/3fnw-transom/firmware.elf"

I did change .state to .position like mentioned in the post above but I’m unsure how to use the make_call().set_command_open() in my lambda to get this functioning correctly.

This is my current yaml

output:
  - platform: gpio
    id: 'win_1'
    pin: GPIO14
  - platform: gpio
    id: 'win_2'
    pin: GPIO12

switch:
  - platform: output
    name: "win1"
    output: 'win_1'
    id: win1
  - platform: output
    name: "win2"
    output: 'win_2'
    id: win2

cover:
  - platform: template
    name: "Window Control"
    id: win_open
    optimistic: true
    open_action:
      - switch.turn_off: win2
      - switch.turn_on: win1
      - delay: 360s
      - switch.turn_off: win1
    close_action:
      - switch.turn_off: win1
      - switch.turn_on: win2
      - delay: 360s
      - switch.turn_off: win2
    stop_action:
      - switch.turn_off: win1
      - switch.turn_off: win2
     
binary_sensor:
  - platform: gpio
    pin: GPIO13
    name: "Window Control Button"
    filters:
      invert:
    on_press: 
      then:
        - lambda: |
            if (id(win_open).position == cover::COVER_OPEN) {
              if (id(win1).state){
                // window is opening
                id(win_open).stop();
              } else {
                // window is open and not moving
                id(win_open).close();
              }
            } else {
              if (id(win2).state){
                // window is closing
                id(win_open).stop();
              } else {
                // win is closed and not moving
                id(win_open).open();
              }
            }

Any help is appreciated!
Thanks!

I feel like a goof. I answered my own problem by reading @hundsboog 's code at the top and noticing the implemented code. So I appreciate that being up there.

I am still having an issue where my button rapidly switches from on to off to on until I disconnect it. I’m going to try a different button I have and troubleshoot from there. Unless anyone else has ideas.

Thanks

***Edit
Here’s an example of what the button is doing. as soon as it powers on it begins switching rapidly. I attached a different button and get the same result.

One thing I did notice is that if I press and hold the button in, the log will show it holding in the On position then when I let go of the button it begins switching back and forth again.

Also to note is that none of this switching by the button is having an effect on the actuator. I can see and control it in home assistant but the button does nothing but flood the logs.

[14:40:41][D][api.connection:727]: Home Assistant 2021.10.4 (192.168.1.): Connected successfully
[14:40:41][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:41][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:41][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:41][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:42][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:42][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:43][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:43][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:44][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:44][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:44][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:44][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:45][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:45][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:45][D][binary_sensor:036]: 'Window Control Button': Sending state OFF
[14:40:45][D][binary_sensor:036]: 'Window Control Button': Sending state ON
[14:40:46][D][binary_sensor:036]: 'Window Control Button': Sending state OFF