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

add friendly_name_template to template sensor #12268

Conversation

NovapaX
Copy link
Contributor

@NovapaX NovapaX commented Feb 10, 2018

Description:

This makes the friendly_name 'templateable' like just like the icon.
Use case (for the template sensor) is probably a bit limited. But it can be things like: Changing the name of a calculated power consumption (value_template) from 'Consumption' to 'Production'
(see example yaml below)

friendly_name can still bet set, but the friendly_name_template will override that if set.

Will update documentation as soon as this gets approved.

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: template
    sensors:
      net_power:
        friendly_name_template: >
          {% if (states('sensor.power_consumption')|float) - (states('sensor.power_production')|float) < 0 %}
            Production
          {% else %}
            Consumption
          {% endif %}
        value_template: "{{ (states('sensor.power_consumption')|float) - (states('sensor.power_production')|float) }}"
        unit_of_measurement: 'kW'

Checklist:

  • The code change is tested and works locally.

If user exposed functionality or configuration variables are added/changed:

If set, overrides friendly_name setting.
@balloob
Copy link
Member

balloob commented Feb 10, 2018

Names are used to identify the entity you're looking at. Icons are used to identify the class of an entity and sometimes the state of that class (like a colored light bulb for lights that are on).

Having the name be templatable means that being able to identify it, is lost.

I find the use case even far fetched and definitely an edge case. I don't think that we should add this.

@arsaboo
Copy link
Contributor

arsaboo commented Feb 10, 2018

@balloob This only makes the friendly_name templatable and there is a need for something like that. Folks can still search based on entity_id or other attributes. Templates are for advanced users and they should know what they are doing :)

See this thread for a use case. The whole solution was complicated by the fact that we could not use templates for friendly_name.

I understand you may want to keep things simple, but just wanted to highlight the need for something like this.

@rexyiy
Copy link

rexyiy commented Feb 10, 2018

I think this is a really useful feature!
You don't have to use it, if you don't want to (or don't know how) - but if you want you can clean up your frontend by combining more (cohesive) information into one sensor.
@NovapaX's example is IMHO a really good example which I could use (adapted to my needs) several times in my smart home.

@balloob
Copy link
Member

balloob commented Feb 10, 2018

You don't have to use it, if you don't want to

This is a bad argument. Every feature we add needs to be maintained, adds runtime overhead, adds tests and so increases the runtime of the test suite that runs for every new feature, adds to the docs etc etc

@balloob
Copy link
Member

balloob commented Feb 10, 2018

@arsaboo that seems like an oke use case

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests

@NovapaX
Copy link
Contributor Author

NovapaX commented Feb 11, 2018

I was thinking to add similar functionality to rest_sensor. But I guess adding it to template sensor should be enough to cover the use cases. (template sensor can 'pull' from the rest_sensors)
Takes a little more configuration for those who want to use in in combination with other sensors, but this addition should be enough.
If there really is need for this in other sensors it should be solved on another level anyway.

@NovapaX
Copy link
Contributor Author

NovapaX commented Feb 12, 2018 via email

@balloob balloob mentioned this pull request Feb 22, 2018
@jadowse
Copy link

jadowse commented Mar 2, 2018

seems this does not work on 0.64 on hassio?

@NovapaX
Copy link
Contributor Author

NovapaX commented Mar 2, 2018

seems this does not work on 0.64 on hassio?

please file an issue with your configuration and other details.
https://github.com/home-assistant/home-assistant/issues/new

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Mar 2, 2018
@NovapaX NovapaX deleted the feature/template_sensor-friendly_name_template branch March 29, 2018 19:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants