New "created_at" & "modified_at" properties: expectations vs reality

Further investigations after this in blog thread.

Tested with “input_boolean”, “input_number”, “template sensor”.
My expectations are:

  1. When an entity is 1st created (when defined in yaml or UI) - “created_at” is set.
  2. When an entity is modified in yaml (for entities defined in yaml) - “modified_at” is updated.
  3. When an entity is modified in UI (for entities defined in UI) - “modified_at” is updated.
  4. When an entity is modified in UI (for entities defined in yaml - but with “unique_id”: we can modify SOME settings like “entity_id”, “area”, …) - “modified_at” is updated.

Currently not everything what I expected is available; let’s call it “bugs”.
So I created 3 issues in core for “input_boolean”, “input_number”, “template sensor” (behaviour is similar but with differences).
Then 2 of these 3 issues were closed as duplicates :rofl:.
OK, there could be same original reason of these “bugs”; for me fixing the original reason is more important than having those issues open or closed.

But there is one disturbing thing:

yaml defined helpers will never update the “modified at” value, since there configuration is not tracked between the reloads and reboots, so HA can not determine if it is the same as before

If this means that pt. 2 (see above) is impossible - then “modified_at” is not supposed to be supported for entities defined in yaml.

2 Likes

For yaml entities that support attributes you could add your own, and change the timestamp when you make a change.

This is understood, user-defined attributes may be created ))))
I am more interested in a core functionality.

BTW, seems that this user-defined attribute should be updated MANUALLY by a user after each change in yaml.
Smth like:
– make changes in yaml;
– raise a custom event like “yaml_entity_modified” with this “entity_id”;
– in this entity (which must be a template sensor, i.e. for yaml-defined helpers not applied): catch that event in a trigger (have to redesign all your template senors to trigger-based) and update the attribute.
Rather cumbersome, not worth it…

I was thinking more along the lines of hard-coding the value. And yes, you’d manually set the date/time in the attribute.

But either way, If I want to know what changed, I look at GIt. Then I know the date and what changed.

A possible way)))
Means:
– change an entity in yaml;
– right here - specify a timestamp value for some custom “custom_modified_at” attribute of this entity;
– save yaml file;
– reload template sensors;
– PROFIT )))
Much easier than that trigger-event way I described.

Yep. But as I edited in afterward: I look at git for changes. Then I know the date and what I changed. So I do not see the point for the attributes in HA about yaml entities anyway.

Assume some yaml file contains 10 entities, 10 automations/scripts, …
Today you changed smth in this file.
Tomorrow you will see that you changed:
– lines 23-40 - in file-1.yaml,
– lines 1, 34-50 - in file02.yaml.
If you do not have a habit to describe your changes like “corrections for sensor.xyz” - then how you will quickly know which entities are changed?
Having a Git definitely helps to track your changes, but it will require additional efforts for analysis.

git blame?

what do you mean?
How it may help?

The git blame command shows who edited witch line and when. The who you know, but the rest is your history. Visual tools are able to show it next to every line of your file.

If this is about documenting your changes (when & what for) - it is good/required and definitely more powerful than simple “modified_at” property; and ofc there are changes which are not covered by “modified_at” (like changes in lovelace).
Surely this thread is not about “how I should track my changes in HA”. There are professional tools like you mentioned for this.
This thread is about - “modified_at is added - but it is not working/supported for all entities in fact”.
Experienced user then will simply ignore that “modified_at” feature (just partially working) and will keep using professional tools like git.