-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the way the card checks whether it needs to be updated #307
Comments
Please test 3.3.0-0 and report back :) |
I can confirm that the beta works fine. I presume you went that auto discovery way to avoid breaking changes and asking people to add So basically everythig is fine and you just need to update the docs about new mechanism and tweak the card so 👍 Here's the link too my post with more details just in case. |
btw, here's an interesting example from my config. button_card_templates:
slave_row:
template: base_row
styles:
card:
- visibility: >-
[[[
let entity_id = variables.entity;
...
]]]
unit_of_measurement_row:
template: slave_row and then a button itself type: custom:button-card
template: unit_of_measurement_row
entity: {{ _input_entity_id() }}
variables:
entity: {{ _master_entity_id() }} and to get it updated as I want (i.e on variables.entity state change) I currently have to change the card's config type: custom:button-card
template: unit_of_measurement_row
entity: {{ _input_entity_id() }}
triggers_update: [ &master_entity_id {{ _master_entity_id() }} ]
variables:
entity: *master_entity_id I'd love to do it on template level (slave_row) but can see no way of doint that. button_card_templates:
slave_row:
template: base_row
triggers_update: >
[[[ return variables.entity ]]]
styles:
card:
- visibility: >-
[[[
let entity_id = variables.entity;
...
]]] |
I was thinking about adding templates to the triggers_update field... but this is going to introduce load again as it will have to be evaluated every time any entity in HA is updated as some people will do different things than just use variables, for eg: |
Single entry in |
yeah, you can set it aside until someone like Marius asks for it ;)
that's fab! I presume it'll be available in the next beta/release (cannot see a way to get an updated |
You'd have to compile it yourself but the next beta will have some more things inside (like multiple |
no worries at all, just checking as I have 0 experience in custom cards development ;) |
Released in |
Is your feature request related to a problem? Please describe.
Please note that It only makes sense when the card has template(s)
not really, it's just a nice feature that would decrease the number of unnecessary updates if
entity
is not specified as in this case the card will be updated every time any HA entity changes its state.the idea was born here
Describe the solution you'd like
I propose to introduce a new
entities
configuration variable that controls when the card is updated (instead ofentity
). It should accept a list of entity_ids or a string (one entity_id).If it is specified, the card should be updated only when at least one of the entities changed its state.
This variable should be independent from
entity
so it's possible to haveentities
specified without specifyingentity
, which will allow the card to be updated regardless.In case both
entity
andentities
are specified, during setup the card should addentity
's value toentities
(if it's not already there). I presume that to represententities
a list/array is used internally and on statrup it's empty.When the card needs to decide on updating (as it receives an updated hass object), it looks at internal list with
entities
and there are 2 cases:entity
and noentities
is specified)There are several things that need to be addresses to avoid breakages.
a. Updating when using existing configs, i.e when there is no
entities
specified.There are 2 cases possible:
entity
is specified (so the card should be updated only when that entity changes its state): add its content to the list representingentities
.entity
is specified (so the card should updated on every change of any HA entity): do nothing.b. Global templates are used.
In this case I propose to append content of template's
entities
to the card'sentities
list (internally, checking that all entities are unique before adding (just a nice touch)).c. If all the above is not enough, it's possible to introduce a new config variable like
update_mode
that will be used during the card's update: if it'sentity
(default mode) and the card hasentity
(so it's an old-style config) - update immediately, otherwise perform checks as described above (entities
mode). Consider issuing a warning ifupdate_mode: entity
but noentity
specified and the same withupdate_mode: entities
andentities
.I'm not a big fan of this idea as it makes things more complex but it might be useful in the long run if users are adamant they want the old update behaviour as it actually disables the new one.
Describe alternatives you've considered
do nothing, it works but consumes more resources as all button cards that do not have
entity
specified are updated much more frequently than they could have been.The text was updated successfully, but these errors were encountered: