Skip to content
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

Bring back countdown #14

Open
danieldifferential opened this issue Feb 22, 2023 · 2 comments
Open

Bring back countdown #14

danieldifferential opened this issue Feb 22, 2023 · 2 comments

Comments

@danieldifferential
Copy link

1.3

Not having countdown available any more severly limits the usage in a number of visualisations - bar cards with severity (like: red color if I can't make it from my behind to the station anyways, green if I can make it), placing the value in a custom map based on a picture,... all that does not seem to work (at least not for me) without a countdown-attribute.

prettyplease? ;-)

ahja: danke, tofuschnitzel, dass es dich gibt ;-))

log

Add your logs here.
@tofuSCHNITZEL
Copy link
Owner

Hi,
if I remember correctly the home assistant documentation states that an attribute of an entity should not "change too often" and that was a main reason for removing it...
but can't you use a template like this:
{{ as_timestamp(states('sensor.kardinal_nagl_platz_u3_ottakring_first_departure'))-as_timestamp(now()) }}
which will give you the difference in seconds between the next departure and now (which is basically a countdown?)

1.3 is only a beta release... and I'm not really happy with the way this component works right now (lots of issues behind the scenes - and its not very robust against the crazyness that is the wiener linien api)
so a complete overhaul with have to be done anyway if I ever find the time to do it.

cheers

@the01
Copy link

the01 commented Jun 22, 2023

I wanted to have this in a template card with easy dynamic formatting for 12 seconds, 5 minutes, .. etc. until departure, but relative time currently only works with times in the past. So it first calculates the time difference in seconds in the future and then creates a time in past with the exact same difference:

{{ relative_time(now() - timedelta(seconds=(as_datetime(states.sensor.kardinal_nagl_platz_u3_ottakring_first_departure.state) - now()).total_seconds())) }}

Not sure if there is a better way to achieve this (without coding the seconds/minutes/.. formatting myself), but wanted to share in case some one else needs it.
Sometimes it takes the api longer to update, in which case the new calculated time is again in the future and a full datetime is shown instead of the formatted time difference.
Also for night time it's helpful to include an if-block that tests if the value is set

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

No branches or pull requests

3 participants