Easy creation of sensors from attributes

By today you have to create a template sensor to extract values from devices attribute e.g. Current Consumption of a wall plug


It´d be great to just click a button an get this done without touching a yaml file again?

BR
Johannes

Actually you don’t.

State and numeric state triggers and conditions have been updated to use attributes. So have some Dashboard cards.

Particularly useful for when you want long term statistics from some attributes.

2 Likes

Seems that History Graph does not support Attributes, or documentation is not correct? My intention is more of a long term stats view.

So you don’t want to create a sensor you just want the History Graph to support attributes?

Can you edit your post and title to say that please.

Think having an easy way to create a template sensor will make it usable in a variety of cases. Another case was the deutsche_bahn integration

sensor:
  - platform: deutsche_bahn
    from: Sauerlach
    to: MuenchenOst
    offset: 00:02:00
    only_direct: true
  - platform: template
    sensors:
      next_train:
        value_template: "{{ states.sensor.sauerlach_to_muenchenost.attributes.next }}"
        friendly_name: "Nächste Sbahn nach München"
  - platform: template
    sensors:
      zug_delay:
        value_template: "{{ states.sensor.sauerlach_to_muenchenost.attributes.delay }}"
        friendly_name: "Verspätung nach München"
        unit_of_measurement: "min"

making template sensors easier to create it gets way more accessible to less experienced people out there.

2 Likes

Yes but what are you doing with those sensors?

I you are just displaying the next train on your dashboard the entities card supports that, so no need for a template sensor.

Also just FYI, you should use state_attr() for your template to prevent errors.

https://www.home-assistant.io/docs/configuration/templating/#states

3 Likes

I´m using it in an automation sending a notification to my mobile so it´s not sufficient to display the attribute on a dashboard. Thank you for the hint!

1 Like

You can put the template in the message data.

1 Like

Having a first-class sensor instead of just an attribute is useful for all kinds of reasons, even if there were some support for seeing history etc of attributes.

Lots of stuff in HA works based on entities with attributes being an afterthought. So either we’d have to clean up all those places, or add this one feature.

10 Likes

I’d like to use a attribute in statistics graph, now it doesn’t see it.

There’s a HACS integration:

A little easier than templates, though not as easy as just clicking a button, but thought it was worth a mention!

2 Likes

Thank you for mentioning it. Still I could imagine that it´d be way more comfy to get things done Way easier when it be directly integrated to get attributes addressable more easily all around HA.
Or like having an “automated” way to apply sum integrals to an attribute via UI and directly show results.

Yeah, something like a helper seems like it would be appropriate here. I like your idea about having a button right next to the attribute, though not sure how that would smoothly fit into the existing UI design.

it works perfectly thank you so much Cannot get data from entity · Issue #35 · pilotak/homeassistant-attributes · GitHub

1 Like