Skip to content
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

Objects available for the value_template not listed. #32

Open
gribouk opened this issue Sep 16, 2021 · 7 comments
Open

Objects available for the value_template not listed. #32

gribouk opened this issue Sep 16, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@gribouk
Copy link

gribouk commented Sep 16, 2021

Hello!

This is a request for the information. We all know that templating is simple, fast and fun way to achieve fantastic results, but your docs lack the list of objects accessible from the value_template section, namelly how to retrive the entity's attribute's value to process it, what is the name of that variable (attr/attribute/value...)?

Example: I have an couple of entities with an attribute's name A. How to address this attribute's value in the value_template (I belive there should be a variable to store the value, shouldn't it?)

Tiny example of value_template would explain it all...

Thanks!

@pilotak
Copy link
Owner

pilotak commented Sep 17, 2021

Hi yes the documentation doesn't cover it, i will fix it. Aynyway here is the answer #23

@pilotak pilotak added the documentation Improvements or additions to documentation label Sep 17, 2021
@gribouk
Copy link
Author

gribouk commented Sep 17, 2021

Thanks for reply!

Did not expect such syntax... I need to apply 'split' procedure to a string, then take n-th element out of the array/list, how would I do that?

To be specific:
I have an attribute Val in a form:
val_float#write_timestamp
To show on the frontend I need value only...

@pilotak
Copy link
Owner

pilotak commented Sep 17, 2021

you could try .split("#")[0] | float

here is test

{% set test = "1.2345#write_timestamp" %}

{{ test.split("#")[0] | float  }}

I don't have such an entity to try out, you could try to turn on the debug and see the result template and play with it in HA dev tools

@gribouk
Copy link
Author

gribouk commented Sep 17, 2021

Thanks for the reply!

There is a confusion. The question was not how to use split, since already use it in my templates, but how to apply split in your value_template section, if there is no name of the variable which stores the attribute value?
Just follow your example:
test.split... What name should I use in the value_template instead of 'test'? Val/attr/attr_val...?
In the sample you've referenced, the syntax was:
'* 100' for the multiplication... What is the name of the variable * operand is applied to?
This was the question.
Thanks!

@pilotak
Copy link
Owner

pilotak commented Sep 17, 2021

I understand what you ask for. All what value_template does is appending it just after extracted value, there is no exposed variable name. If following setting doesn't work, than this is not possible with this component

value_template: ".split("#")[0] | float"

@gribouk
Copy link
Author

gribouk commented Sep 17, 2021

Unfortunatelly, it is not valid:
Could not attribute sensor for variable.engineerineg_irrigation_zone_test_5: TemplateSyntaxError: expected token 'end of print statement', got '.'

Thus, I guess, it shiuld transform into feature request at this stage.

Motivation:
Though it can be emplemented using standard template sensor integration, your component has vital feature - batch declaration from the list of entities of similar nature, which drastically decreases the copy-paste size of a code (when vlue template is a complex script of ~20-30 lines or more it does metter), along with mistakes probability.

Thus, having a variable, which stores a string value of the attribute would be usefull to unleash the full scale access to templating.

@pilotak
Copy link
Owner

pilotak commented Sep 17, 2021

Rather then making a future request, you could propose a code via PR. I'm busy at the moment so this will park at the bottom of my todo list unless you write and test the code in which case I will review it asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants