a-p-z / datetime-card

A minimalistic card for Home Assistant Lovelace UI which shows how many days it has been between any input_datetime and today.
21 stars 1 forks source link

Working with Future Date #24

Closed mzakharo closed 2 months ago

mzakharo commented 6 months ago

Hi,

Is there a way to make this card work with a future date? Max value configured is only used for setting the date/time to the future date with press/hold, otherwise, the card just simply shows how many days left until future date of the configured date/time entity.

Reason for working with future date is that it will be possible to trigger automations when future date triggers in home assistant. I find the current solution this card suggests using pyscript to be too hacky for my taste.

https://github.com/mzakharo/datetime-card/commit/471594b8319bb2b4d9d5d6f6a65695facf87482e seems to implement what is described. with the above change, I can now simply create automations with time platform trigger. No need for special pyscript.

trigger:
  - platform: time
    at: input_datetime.some_entitiy
a-p-z commented 6 months ago

Hi @mzakharo , it sounds good. Can you describe better, for my understanding, the use case(s) you have in mind? Thanks

mzakharo commented 6 months ago

The advantage of setting a future date (current date + entity.max) is that it allows for HA built-in time based trigger automations to trigger notifications when time expires. No need for custom pyscripts to trigger notifications, and everything is managed by HA GUI. https://github.com/mzakharo/datetime-card/commit/471594b8319bb2b4d9d5d6f6a65695facf87482e seems to work fine for me. It would be great if this could be made an option in the main repository.

a-p-z commented 6 months ago

I have just tested the current behaviour and the card already shows the correct day count down. image The max value is used only to calculate the size of the bar and the color. And the reset will set the helper to the current day.

What are the current limitation that you see in the current behavour?

mzakharo commented 6 months ago

with the helper set to current day you cannot enable trigger time notification, since those only trigger with current time matching the date set in the helper. The only way around the issue is setting the helper to a future day, where notification can work as expected. https://www.home-assistant.io/docs/automation/trigger/#time-trigger

erkr commented 4 months ago

@mzakharo I was struggling with similar wishes. The main thing is to get the max days configuration out of the card and have it available in the server. I went a different direction using auto entities to populate the card and have the max days configuration in a single template binary sensor. That sensor can be used to populate the card, and used in automations and/or alerts. See https://github.com/a-p-z/datetime-card/issues/25#issuecomment-1964738116 This works with the card as is today. Success Eric