Skip to content

Add visibility condition for lovelace cards based on an entity's last updated time #25864

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

LukeMondy
Copy link

Proposed change

This change adds a condition to lovelace cards, where you can decide if a card should be visible based on the time since the last change to an entity was made.

An example might be: I have a card show up on my dashboard when occupancy is detected at my front-door, showing a picture of who was there - but as soon as they leave, and the occupancy sensor is cleared, the picture immediately disappears.

This change allows me to set a visibility condition where I say display the picture for 5 minutes after the last update to the occupancy sensor.

I'm sure people will come up with other ideas too :).

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

type: entity
entity: light.kitchen_floor_lamp_light
visibility:
  - condition: last_updated_state
    entity: light.kitchen_floor_lamp_light
    within:
      hours: 0
      minutes: 1
      seconds: 25

Additional information

This PR is not yet ready for merge - apologies, it's my first time contributing here.

Some things that need fixing:

  • The HaDurationData_to_milliseconds I wrote is either: duplicating functionality from somewhere I couldn't find; or if not, is very much in the wrong place. Any advice on this would be great.
  • I'm not 100% sure where to put tests, a pointer would be much appreciated.
  • I'm having an issue with getting headings for the 'within' and 'after' sections. When I add:
              "last_updated_state": {
                "label": "Entity updated",
                "within": "Within",
                "after": "After"
              },

to the translations/en.json file, I get:

ERROR in ./src/resources/translations-metadata.ts 1:0-90
  × Module not found: Can't resolve '../../build/translations/translationMetadata.json' in '/home/lmondy/dev/frontend/src/resources'
   ╭─[1:38]
 1 │ import * as translationMetadata_ from "../../build/translations/translationMetadata.json";
   ·                                       ───────────────────────────────────────────────────
 2 │ export const translationMetadata = translationMetadata_.default;
   ╰────

and I don't know why yet.

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

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

Demo:

last_state_change_demo

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @OlympusMonds

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft June 21, 2025 12:34
@LukeMondy LukeMondy force-pushed the last_updated_lovelace_condition branch from 80a2cfc to d12b782 Compare June 21, 2025 12:39
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @LukeMondy

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@LukeMondy LukeMondy force-pushed the last_updated_lovelace_condition branch from d12b782 to 1aa6218 Compare June 21, 2025 12:40
@LukeMondy LukeMondy marked this pull request as ready for review June 21, 2025 12:42
@home-assistant home-assistant bot dismissed stale reviews from themself June 21, 2025 12:42

Stale

entityIds.add(condition.entity);
}
if (
typeof condition.within === "string" &&
Copy link
Author

Choose a reason for hiding this comment

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

Not really sure if this chunk is right..., I copied it from the NumericState condition

const within = condition.within;
const after = condition.after;

function HaDurationData_to_milliseconds(
Copy link
Author

Choose a reason for hiding this comment

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

As mentioned: I feel like this function must exist somewhere, but if it doesn't, this is not the right place for it. Any tips for where it should go?

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

Successfully merging this pull request may close these issues.

1 participant