Problem with setting up automation for cover

Hi folks,

next question from my side. Learning, learning, learning…

I have an enocean switch (Eltako FT55) and a qubino roller shutter.
With the example from the documentation https://www.home-assistant.io/integrations/enocean/ I came up with this one, working fine.

- id: '1575468037003'
  alias: cover living room
  description: ''
  trigger:
  - event_data:
      id: [254, 242, 255, 31]
    event_type: button_pressed
    platform: event
  condition: []
  action:
  - alias: ''
    data:
      entity_id: cover.qubino_goap_zmnhcdx_flush_shutter_switch
    service_template: "{% if trigger.event.data.onoff %} cover.close_cover {% else %} cover.open_cover {% endif %}"

Now I want to use the reading of the qubino for power consumption and, if the motor is moving, stop the motion when a button is pressed.

Look at this.

- id: '1575468037003'
  alias: cover living room
  description: ''
  trigger:
  - event_data:
      id: [254, 242, 255, 31]
      pushed: 1
    event_type: button_pressed
    platform: event
  condition: []
  action:
  - alias: ''
    data:
      entity_id: cover.qubino_goap_zmnhcdx_flush_shutter_switch
    service_template: >-
      "{% if ((trigger.event.data.onoff) and ((state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float) > 0)) %} cover.stop_cover 
      {% elif ((trigger.event.data.onoff) and ((state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float) == 0)) %} cover.close_cover 
      {% elif (!(trigger.event.data.onoff) and ((state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float) > 0)) %} cover.stop_cover 
      {% elif (!(trigger.event.data.onoff) and ((state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float) == 0)) %} cover.open_cover 
      {% endif %}"

When doing this I get so many errors when checking the config I can’t even go back to the first line to see what is the first error.

I’ve also tried with is_state_attr but also too many errors.

I know for sure, one of you will look at it, spot it and then I can just hit my head for being blind but I’m trying now for several days with this.

Help or even a small hint is highly appreciated :slight_smile:
Thanks upfront
Ralf

You don’t need to surround the template with quotation marks when you’re using the > notation for multi-line templates. I think that’s probably your issue

Hi Steve,

thanks for your reply.
Unfortunately this did not solve the problem. Error messages during check of config remain.

The first and the third if/elif statement can be combined as the service is always cover.stop_cover if the power consumption is above 0. Can you try like this and report the errors you get:

- id: '1575468037003'
  alias: cover living room
  description: ''
  trigger:
  - event_data:
      id: [254, 242, 255, 31]
      pushed: 1
    event_type: button_pressed
    platform: event
  condition: []
  action:
  - alias: ''
    data:
      entity_id: cover.qubino_goap_zmnhcdx_flush_shutter_switch
    service_template: >-
      {% set button_press = trigger.event.data.onoff %}
      {% set power_consumption = state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float %}
        {% if power_consumption > 0 %}
          cover.stop_cover
        {% elif not button_press and power_consumption == 0 %}
          cover.close_cover
        {% else %}
          cover.open_cover
        {% endif %}

Thanks, Burningstone!!

No more error messages when checking the config!

Will try if it is working when back home tonight. (Don’t want to scare my wife too much by playing around with the covers from remote while she is home…)

Regards
Ralf

Let me know if it works.

The problem with your code was first the quotation marks as pointed out by @SteveDinn and second this is not allowed

!(trigger.event.data.onoff)

it needs to be

not trigger.event.data.onoff

Back with test results:

WORKING!!

Once again cudos to Burningstone and of course to SteveDinn

What I still had to figure out was that I was using the wrong entity (shutter_switch <-> shutter_level) :woozy_face: and I had to switch the logic in the elif branch. Just for readability and clarity I added braces around the and and the power_consumption == 0 part.

So for all interested, please find the correct version of the automation below:

- id: '1575468037003'
  alias: cover living room
  description: ''
  trigger:
  - event_data:
      id:
      - 254
      - 242
      - 255
      - 31
    event_type: button_pressed
    platform: event
  condition: []
  action:
  - alias: ''
    data:
      entity_id: cover.qubino_goap_zmnhcdx_flush_shutter_level
    service_template: >-
      {% set button_press = trigger.event.data.onoff %} 
      {% set power_consumption = state_attr('cover.qubino_goap_zmnhcdx_flush_shutter_level', 'power_consumption') | float %}
        {% if power_consumption > 0 %}
          cover.stop_cover
        {% elif (button_press and (power_consumption == 0)) %}
          cover.close_cover
        {% else %}
          cover.open_cover
        {% endif %}

Glad that it works now :slight_smile:
Just two small optimizations. You can remove the condition part if you don’t have any conditions.
And I think you don’t need the and (power_consumption == 0) part, because if the power_consumption is not larger 0 then it is 0.

1 Like

I think that the GUI editor puts that empty condition in there by default.

Steve, that’s right.
The empty condition comes with the gui editor.