junkfix / numberbox-card

Replace input_number sliders with plus and minus buttons
109 stars 9 forks source link

secondary_info not refreshing data #52

Closed murcin closed 1 year ago

murcin commented 2 years ago

when I set secondary info as some entities that automatically not refreshing In this example I`ve use browser_mod.popup and shows variables

- entity: > [[[ return variables.s_set ]]] name: 'Zadana temp.:' type: custom:numberbox-card secondary info: > [[[ return 'zapisana: ' + states[variables.s_set].state + '°C' ]]] I upload screen because formatting not works perfectly... image

image after press + or - variable one line below change with secondary_info "Teraz" - means "Now" but secondary info from numberbox-card not refreshing:

image

htmltiger commented 2 years ago

have you tried this? secondary info: "zapisana: %variables.s_set:state °C"

Murcin86 commented 2 years ago

yes I`ve try...

        - entity: > 
            [[[ return variables.s_set ]]] 
          name: 'Zadana temp.:' 
          type: custom:numberbox-card 
          secondary_info: > 
            [[[ return "zapisana: %variables.s_set:state °C" ]]]

here is two options: 1) what I have right now 2) your solution - shows text - not value from entity image

image

BTW - when I using in dashboard I can use direct access to entity - thats work... but I want to use like above with custom:button-card to have something like template

  - entity: input_number.therm_julia
    type: custom:numberbox-card
    secondary_info: |
      zapisana:<b style="color:white"> %sensor.tempset_julia:state °C</b>
htmltiger commented 2 years ago

try %% as it may be escaping [[[ return "zapisana: %%variables.s_set:state °C" ]]]

Murcin86 commented 2 years ago

add %% makes the same but with % sign

image

htmltiger commented 2 years ago

instead of

secondary_info: > 
            [[[ return "zapisana: %variables.s_set:state °C" ]]]

have you tried

secondary_info: "zapisana: %variables.s_set:state °C"

as the first one is sending the variables directly to the card and do not get the updated information

murcin commented 2 years ago

I try it - not working :( first entity - working - not refreshing data second entity - not working, everything what I put wit " " or ' ' sign - does it as text... image image

htmltiger commented 2 years ago

how about if you put this way?

secondary_info: |
        zapisana: %variables.s_set:state °C
murcin commented 2 years ago

without % we can see text... image image

with % got error with saving: image image

ildar170975 commented 2 years ago

@murcin You keep using "[[[ ... ]]]" - WHY ? And you have been proposed several times not to use it. These "[[[ ...]]]" brackets are NOT specified in the docs (as well as "return") - then probably you should not use it.

murcin commented 2 years ago

you mean on line where is -entity? - because Ive used variables from custom:button-card - and line like this doesnt work image image

and as I wrote above - when I try to use like this - shows me text: image image

and when I try to add % sign got error and can`t save file: image image

murcin commented 2 years ago

here I have small example and I think thats not problem with syntax... but your code cant read variable state, have a look below, first example WORKS and there is secondary_info: > that works: %input_number.therm_gabinet:state °C

second the same but should read variable state: secondary_info: > that works: %variables.s_set:state °C

image image

ildar170975 commented 2 years ago

you mean on line where is -entity?

No, I guessed that this is a part of button-card. And you should NOT test your issue with "secondary_info" inside ANOTHER card. A code for testing your issue should be as simple as possible.

Two things are probably here:

  1. If something is not updated inside button-card - then this is a button-card's issue, you must define entities as "monitored" - see docs for "button-card".
  2. Since button-card already has a template support - then you probably should use either a "pure button-card template" or a "pure numberbox template".

First test your numberbox card OUTSIDE button-card.

murcin commented 2 years ago

I dont think that custom:button-card have any problem because I set variable to custom:numberbox-card and that work, I made small experience:

image

1 entity as variable, secondary info from input_number - WORKS 2 entity as variable, secondary info from variable - DOESN`T work 3 entity as variable no custom:numberbox-card just entity - refreshing data works

image

so that`s mean custom:numberbox-card can read entity from variable correctly but reading secondary info not.

htmltiger commented 2 years ago

It looks like variables get out of scope or not available to numberbox.

I cannot test about the variables, if your first example works with input_number then numberbox is working correctly

ildar170975 commented 2 years ago

Consider this example:

type: vertical-stack
cards:
  - type: custom:button-card
    name: "[ static text ]"
    <<: &ref_settings
      variables:
        SENSOR: '[[[return entity.entity_id]]]'
      entity: input_number.test_parrots
      styles:
        grid:
          - grid-template-areas: '"i" "n" "numberbox"'
          - grid-template-columns: 1fr
          - grid-template-rows: 32px min-content min-content
    custom_fields:
      numberbox:
        card:
          type: custom:numberbox-card
          entity: input_number.test_parrots
          secondary_info: >-
            [[[ return "<b style='color:red'>" + "static" + "</b>"]]]
  - type: custom:button-card
    name: "[ variable.xxx ]"
    <<: *ref_settings
    custom_fields:
      numberbox:
        card:
          type: custom:numberbox-card
          entity: input_number.test_parrots
          secondary_info: >-
            [[[ return "<b style='color:red'>" + states[variables.SENSOR].state + "</b>"]]]
  - type: custom:button-card
    name: "%entity"
    <<: *ref_settings
    custom_fields:
      numberbox:
        card:
          type: custom:numberbox-card
          entity: input_number.test_parrots
          secondary_info: >-
            <b style='color:red'> %input_number.test_parrots:state </b>
  - type: custom:button-card
    name: "% [ variable ]"
    <<: *ref_settings
    custom_fields:
      numberbox:
        card:
          type: custom:numberbox-card
          entity: input_number.test_parrots
          secondary_info: >-
            <b style='color:red'> %[[[return variables.SENSOR]]]:state </b>

image

cases 1, 2 - button-card-like templates are used ("[[[ ... ]]]"). cases 3, 4 - numberbox-like templates are used ("% ... ").

Note that you may combine html-formatting from "numberbox" and button-card-like templates (cases 1, 2).

Case 4 - does not work. It happens probably due to an order of resolving: first numberbox-level template is resolved (and fails), then button-card-level template is resolved (which fails too).

Regarding "no refresh". In my test, when I press "+ / -" buttons, the "secondary_info" is refreshed too - after a couple of seconds. Earlier I wrote about "monitored entities" - I meant a bit different situation: pressing "+ / -" affects some entity which is NOT defined as the MAIN entity for the button card, check here.

As a conclusion - this is not a bug of numberbox!