Advanced JS - Help needed

Hi there,

I am using my vacuum robot on 2 stories in our house. Running up & down with the unit a few times per week beats another €500 (for now).

The unit is rooted with Valetudo and have installed maploader which works great.

Also have this card in lovelace:

type: vertical-stack
cards:
  - type: custom:auto-entities
    card:
      type: entities
      state_color: true
      title: Rooms to Vacuum BGG
    filter:
      include:
        - group: group.vacuum_rooms_bgg
      exclude: []
    show_empty: true
    sort:
      method: entity_id
      reverse: false
      numeric: false
  - type: custom:button-card
    tap_action:
      action: call-service
      service: script.vacuum_clean_segments_bgg
      confirmation: true
      service_data: {}
      target: {}
    lock:
      enabled: >
        [[[return states['group.vacuum_rooms_bgg'].state !== 'on' ||
        states['vacuum.valetudo_z10pro'].state !== 'docked']]]
      exemptions: []
    entity: script.vacuum_clean_segments_bgg
    name: Vacuum selected segments BGG
    show_state: false
    show_icon: false

which has a lock based on the unit’s state and whether any individual segments are selected for cleaning. I’d now like to add the following condition as part of the locking conditions:

states['select.vacuum_maploader_map'].state !== 'main'

How do I add this with correct formatting?

Spoiler - this does not work:

        [[[return states['group.vacuum_rooms_bgg'].state !== 'on' ||
        states['vacuum.valetudo_z10pro'].state !== 'docked' ||
        states['select.vacuum_maploader_map'].state !== 'main']]]

Thanks in advance, Joost

That’s not Jinja. That’s JS.

How you added it is correct. Assuming you want or. If you want and, that’s different logic.

How about explaining what you want with words.

states[‘group.vacuum_rooms_bgg’].state !== ‘on’

or

states[‘vacuum.valetudo_z10pro’].state !== ‘docked’

and

states[‘select.vacuum_maploader_map’].state !== ‘main’
??

A simple working prototype:

type: vertical-stack
cards:
  - type: custom:button-card
    lock:
      enabled: >-
        [[[
          return states["input_boolean.testing_boolean"].state !== "on" ||
                 states["input_boolean.testing_boolean_2"].state !== "on"
        ]]]
      exemptions: []
    entity: sun.sun
  - type: entities
    entities:
      - entity: input_boolean.testing_boolean
      - entity: input_boolean.testing_boolean_2

изображение

What you need to do is defining a proper logic conditions.

Its all OR that’s needed -

states[‘group.vacuum_rooms_bgg’].state !== ‘on’

**or**

states[‘vacuum.valetudo_z10pro’].state !== ‘docked’

**or**

states[‘select.vacuum_maploader_map’].state !== ‘main’

As per the spoiler alert, the card does not display the button (locked or unlocked) if I add this extra condition…

I am I formatting this right?

JP

So just to be clear - the following results in the button-card NOT to display:

  - type: custom:button-card
    tap_action:
      action: call-service
      service: script.vacuum_clean_segments_bgg
      confirmation: true
      service_data: {}
      target: {}
    lock:
      enabled: |
        [[[
          return states['group.vacuum_rooms_bgg'].state !== 'on' ||
                 states['vacuum.valetudo_z10pro'].state !== 'docked' ||
                 states[‘select.vacuum_maploader_map’].state !== ‘main’
        ]]]
      exemptions: []
    entity: script.vacuum_clean_segments_bgg
    name: Vacuum selected segments BGG
    show_state: false
    show_icon: false

This DOES display the button card:

  - type: custom:button-card
    tap_action:
      action: call-service
      service: script.vacuum_clean_segments_bgg
      confirmation: true
      service_data: {}
      target: {}
    lock:
      enabled: |
        [[[
          return states['group.vacuum_rooms_bgg'].state !== 'on' ||
                 states['vacuum.valetudo_z10pro'].state !== 'docked'
        ]]]
      exemptions: []
    entity: script.vacuum_clean_segments_bgg
    name: Vacuum selected segments BGG
    show_state: false
    show_icon: false

I see strange “quotes” here.

To display or not to display a “lock” icon (& make this button “disabled”).

Good gracious. I wish everything in life was THIS easy. Just use the right quotes and… DONE! :slight_smile:
Thanks Ildar!

1 Like

So correct JS code as follows:

  - type: custom:button-card
    tap_action:
      action: call-service
      service: script.vacuum_clean_segments_bgg
      confirmation: true
      service_data: {}
      target: {}
    lock:
      enabled: |
        [[[
          return states['group.vacuum_rooms_bgg'].state !== 'on' ||
                 states['vacuum.valetudo_z10pro'].state !== 'docked' ||
                 states['select.vacuum_maploader_map'].state !== 'main'
        ]]]
      exemptions: []
    entity: script.vacuum_clean_segments_bgg
    name: Vacuum selected segments BGG
    show_state: false
    show_icon: false