thomasloven / lovelace-state-switch

🔹Dynamically replace lovelace cards depending on occasion
MIT License
382 stars 27 forks source link

Feature request: a template result is available as a variable #97

Open zulu64 opened 1 year ago

zulu64 commented 1 year ago

Hi @thomasloven I would like to request an enhancement to the "default" option.

Currently

If the entity: template option is used, the result is computed and the state switch mechanism directs to the appropriate "state". The default: x option takes care of unknown/unrecognised states.

Issue

If the state is unknown/unrecognised, the default code doesn't know what the actual state value is/was. This prevents at least 2 scenarios useful to developers:

Proposed solution

An implicit variable is available within the card and is accessed the same way as the existing variables. I propose the name: state.result (up to you of course). It may make sense to populate this variable with a result for all other entity types too to promote and facilitate generic code. e.g. hash, user, group, deviceID, and mediaquery

Thanks for this useful card. Guy