Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Cover example does not work #27

Closed
brandond opened this issue Jun 1, 2018 · 0 comments
Closed

Template Cover example does not work #27

brandond opened this issue Jun 1, 2018 · 0 comments

Comments

@brandond
Copy link
Collaborator

brandond commented Jun 1, 2018

The example specifies both lambda and optimistic, which is not allowed:

  cover.template:
    - Invalid config for [cover.template]: Cannot specify more than one of lambda, optimistic.

Additionally, the generated c++ code (if I remove optimistic) does not seem to be valid:

binary_sensor:
  - platform: gpio
    id: garage_door
    device_class: garage_door
    name: Garage Door
    pin:
      number: 12
      inverted: False
      mode: INPUT_PULLUP

switch:
  - platform: gpio
    id: garage_door_switch
    name: Garage Door Switch
    pin: 27

cover:
  - platform: template
    id: garage_door_opener
    name: "Garage Door Opener"
    lambda: >-
      if (id(garage_door).value) {
        return cover::COVER_CLOSED;
      } else {
        return cover::COVER_OPEN;
      }
    open_action:
      - switch.turn_on:
          id: garage_door_switch
      - delay: 1s
      - switch.turn_off:
          id: garage_door_switch
    close_action:
      - switch.turn_on:
          id: garage_door_switch
      - delay: 1s
      - switch.turn_off:
          id: garage_door_switch
      - delay: 1s
      - switch.turn_on:
          id: garage_door_switch
      - delay: 1s
      - switch.turn_off:
          id: garage_door_switch
    stop_action:
      - switch.turn_on:
          id: garage_door_switch
      - delay: 1s
      - switch.turn_off:
          id: garage_door_switch

results in:

Compiling .pioenvs/garage/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:24:26: error: expected unqualified-id before '->' token
template_cover.template->set_state_lambda([=]() {
^
*** [.pioenvs/garage/src/main.cpp.o] Error 1

from the following code:

  auto template_cover = App.make_template_cover("Garage Door Opener");
  auto gpio_switch = App.make_gpio_switch("Garage Door Switch", 27);
  auto *garage_door_switch = gpio_switch.switch_;
  auto gpio_binary_sensor = App.make_gpio_binary_sensor("Garage Door", GPIOInputPin(12, INPUT_PULLUP, false));
  auto *garage_door = gpio_binary_sensor.gpio;
  garage_door->set_device_class("garage_door");
  template_cover.template->set_state_lambda([=]() {
      if (garage_door->value) {
        return cover::COVER_CLOSED;
      } else {
        return cover::COVER_OPEN;
      }
  });
brandond added a commit to brandond/esphome that referenced this issue Jun 1, 2018
brandond added a commit to brandond/esphome that referenced this issue Jun 1, 2018
@esphome esphome locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant