pilotak/HomeAssistant-CustomComponents

Use attributes.py to get last_updated ?

Closed this issue · 6 comments

Hi,
I'm currently looking for a way to get the "last_updated" date for each of my sensors. I'm already using your attributes.py (thanks btw!) to extract the battery_level but can't figure out, how to get the last_updated value.
Most likely it does not work, because the last_updated value is saved as state and not attribute (?).

- platform: attributes
  friendly_name: "Last update"
  attribute: last_updated
  entities:
    - sensor.pressure_sensor_1_0
    - sensor.pressure_sensor_105_0

Do you seen any possibility to use your component to extract this value so I don't have to build a template for each sensor?

Thanks in advance

Hi,
if it's a state, than you don't need this attribute sensor. If it is an attribute, it will exctract it but only if the attribute exists, you need to check in developer tools under <> in HA.

What output do you have? does sensor exitst if you look into dev-state? you can turn on debug level in logging and see if there is any problem.
Just to let you know, you can add option for parsing time: ( have a look into documentation):

time_format: '%e %B - %H:%M:%S'

When i created this sensor i tested last_updated and last_triggered and they worked

Hi, thank you for your fast reply!

The thing is, that it's not possible to display a state inside a group without the round trip of setting up a template:

    last_updated:
      value_template: "{{states.sensor.pressure_sensor_1_0.last_updated}}"

I would like to avoid this and use a mechanism similiar to your attributes.py to autogenerate the required objects.

last_updated is a special part of the state object. I also opened a post in the home-assistant forum but did not get any other suggestions :(

Sure, can you post a screenshot from entity viewer <>? also what sensor do you use, i have not got any with last_updated only last_triggered

May there is a bug in my component, so i would like to sort this out but at the same time have you tried custom-ui? this shows xx minutes ago etc. i posted it on forum too

Silly me, I can see what you talking about, last_updated is not part of the attributes state. I will have a look, but it will probably be better to creat component like sensor.last_updated rather than mix it with sensor.attributes

Awesome thanks! I'll have a look!

Ok, I did a check, works great. I think, this request is no longer relevant :) Thanks!