piitaya / lovelace-mushroom

Build a beautiful Home Assistant dashboard easily
Apache License 2.0
3.53k stars 329 forks source link

[Feature]: Inverted slider for cover card #737

Open flobert8 opened 1 year ago

flobert8 commented 1 year ago

Is your feature request related to a problem?

I want to use the mushroom cover cards to control my KNX shutters in my house. In generell everything works. The problem is, that for the position slider, i need an inverted value, because in KNX 0% is fully open and for Home Assistant is 100% fully opened. Before i used the mushroom cover cards, i build the cards myself and for the slider is used a seperate entity with the following code:

cover:
  platform: template
  covers:
    cover_og_buero_inverted: ##Büro
      friendly_name: Buero Rolladen inverted
      position_template: >
        {{100 - (state_attr(‘cover.og_buero_rolladen’,‘current_position’)|int)}}
      set_cover_position:
        service: cover.set_cover_position
          data_template:
            entity_id: cover.og_buero_rolladen
            position: >
              {{100 - position}}

But in the mushroom cover card its not possible to use an seperate entity only for the slider. Up/down/hold works perfectly with the buttons.

Describe the solution you'd like

Seperate entity for the slider in the cover card

Describe alternatives you've considered

No response

Additional context

No response

piitaya commented 1 year ago

You can use your template cover for the whole cover card. Why not ?

flobert8 commented 1 year ago

Thank for your fast answer.

But then everything is wrong. Cover state say its closed, but its open. And up and down is twisted.

piitaya commented 1 year ago

I think you can do somethings like this :

open_cover:
  service: cover.close_cover
  data: {}
  target:
    entity_id: cover.og_buero_rolladen
close_cover:
  service: cover.open_cover
  data: {}
  target:
    entity_id: cover.og_buero_rolladen
stop_cover:
  service: cover.stop_cover
  data: {}
  target:
    entity_id: cover.og_buero_rolladen
value_template: "{{ is_state('cover.og_buero_rolladen', 'closed') }}"
flobert8 commented 1 year ago

You can use your template cover for the whole cover card. Why not ?

Got ya!

flobert8 commented 1 year ago
value_template: "{{ is_state('cover.og_buero_rolladen', 'closed') }}"

I have tested this scenario.

cover:
  - platform: template
    covers:
        cover_ug_schlafen1_tur_inverted:
        friendly_name: Schlafen1 Tür inverted
        position_template: >
          {{100 - (state_attr('cover.ug_schlafen_1_tur_rolladen_m6','current_position')|int)}}
        set_cover_position:
          service: cover.set_cover_position
          data_template:
            entity_id: cover.ug_schlafen_1_tur_rolladen_m6
            position: >
              {{100 - position}}
        open_cover:
          service: cover.open_cover
          data:
            entity_id: cover.ug_schlafen_1_tur_rolladen_m6
        close_cover:
          service: cover.close_cover
          data:
            entity_id: cover.ug_schlafen_1_tur_rolladen_m6
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.ug_schlafen_1_tur_rolladen_m6
        value_template: "{{ is_state('cover.ug_schlafen_1_tur_rolladen_m6', 'closed') }}"

The problem is, that he still thinks, that 100% is open, but it must be closed. Because of this, its not possible to use the buttons up/down correctly.

image

My shutter is fully closed. But he thinks the shutter is fully opened, so i only can use button down and stop.

The slider is correct. image

piitaya commented 1 year ago

Can you format your code using this https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks ? Indentation is very important in yaml 😅

flobert8 commented 1 year ago

Can you format your code using this https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks ? Indentation is very important in yaml sweat_smile

Should be better now.

spali commented 1 year ago

That shouldn't be required for KNX. The integration does the translation of the percentage. A closed cover shows 100% in KNX and 0% in Home Assistant. That's the default and I can confirm this in my installation. Are you sure you don't mix up anything?

Home Assistant definition:

knx:
  cover:
    - name: buro_jalousie_fenster
      move_long_address: 3/1/81
      move_short_address: 3/2/81
      position_address: 3/3/81
      angle_address: 3/4/81
      position_state_address: 3/6/81
      angle_state_address: 3/7/81
      travelling_time_down: 44
      travelling_time_up: 45

Home Assistant Status for closed (current_position: 0): image KNX Status for closed (100%): image

So this shouldn't be the case if setup by default.

I had a similar problem, but only because an exception for the vertical blinds (german: "Markise). For me it's natural that the button down would "open" it and the button up would close it (similar to the physical orientation). So the Buttons worked as expected. But the status felt wrong for me, because Open is for me when it's out (create shade). and closed when it's rolled up (no shade).

So i created my own card with inverted state in the GUI. It was not out of the box, but works well now for me. You need card-mod and stack-in-card. With them I created basically a template card, which shows the inverted icon and state. And below the default mushroom cover card with the buttons.

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    card_mod:
      style: |
        ha-card {
          padding-bottom: 0 !important;
        }
    primary: Markise
    secondary: |-
      {% set pos = state_attr(entity, 'current_position') %}
      {{
        'Geschlossen' if pos == 100 else
        'Schliesst' if states(entity) == 'opening' else
        'Öffnet' if states(entity) == 'closing' else
        'Offen'
      }}{{ (' - ' +  (100-pos) | string + '%') if pos > 0 and pos < 100 }}
    icon: |-
      {{
        'mdi:blinds-open' if state_attr(entity, 'current_position') == 100 else
        'mdi:arrow-down-box' if states(entity) == 'closing' else
        'mdi:arrow-up-box' if states(entity) == 'opening' else
        'mdi:blinds'
      }}
    entity: cover.aussen_sitzplatz_markise_sud_sitzplatz
    icon_color: '{{ ''grey'' if state_attr(entity, ''current_position'') == 100 else ''blue'' }}'
    layout: vertical
  - type: custom:mushroom-cover-card
    entity: cover.aussen_sitzplatz_markise_sud_sitzplatz
    show_buttons_control: true
    layout: vertical
    tap_action:
      action: more-info
    name: Markise
    primary_info: none
    secondary_info: none
    icon_type: none
    card_mod:
      style: >
        {% set color = '--rgb-disabled' if
        state_attr('cover.aussen_sitzplatz_markise_sud_sitzplatz',
        'current_position') == 100 else '--rgb-blue' %}

        :host {
          --rgb-state-cover-closed: var({{color}}) !important;
          --rgb-state-cover-closing: var({{color}}) !important;
          --rgb-state-cover-open: var({{color}}) !important;
          --rgb-state-cover-opening: var({{color}}) !important;
        }