CSS script not working for covers

Hi all,

My covers repeat open when they are actually closed. That’s because the fact that they only close to 29%. In my HA-floorplanner, I’m trying to make my blinds visible when they are closed, and invisible when they are open (obviously). For some reason, my if then else statement is not working:

- name: Cover Controls
                    entities:
                      - element: cover.front
                        entity: group.living_covers
                    tap_action:
                      action: more-info
                    state_action:
                      - action: call-service
                        service: floorplan.class_set
                        class: >
                          {% if state_attr('cover.192_168_1_xx',
                          'current_position') <= 30 and 
                                state_attr('cover.192_168_1_xx', 'current_position') <= 30 %}
                            cover.closed
                          {% else %}
                            cover.open
                          {% endif %}

And this is the css part:

.cover-open {
  visibility: hidden !important;
}

.cover-closed {
  visibility: visible;
  opacity: 0.9;
}

Does anyone have an idea what I’m doing wrong ?

Kr,

Bart

You may need to convert your cover position to an integer.

| int(0)

That was my initial thought too, but the developer tools say the attribute is a float. So that should work. I know too little about floorplan to say anything else.

If I google though, I see ${ templates, not {{ so are you sure you can use jinja2 templates here? if it is a frontend thing, it may require something else. It seems to require javascript, which makes sense in the fronend.

1 Like

I was just looking at that too🧐 It is JavaScript based on what I see.

@weemaba999 Examples are also showing a different format with service_data as well…

- entities:
    - binary_sensor.kitchen
    - binary_sensor.laundry
  state_action:
    action: call-service
    service: floorplan.class_set
    service_data:
      class:  '${....}'

Thanks Guys,

Unfortunately, that didn’t do the trick:

state_action:
                      - action: call-service
                        service: floorplan.class_set
                        service_data:
                          class: >-
                            {% if state_attr('cover.192_168_1_19',
                            'current_position') <= 30 and 
                                  state_attr('cover.192_168_1_62', 'current_position') <= 30 %}
                              cover.closed
                            {% else %}
                              cover.open
                            {% endif %}

As Edwin pointed out and I agree, I don’t think you can use Jinja2.

Strange,

I think you can use jinja2 here, but still can’t get it to work

Test some simpler code to be sure jinja works

Did you convert the position to an integer?