timer-bar-card
timer-bar-card copied to clipboard
Can this work with input_datetime sensors?
I love this card - works perfect on Alexa devices, but I would like to get this to work with an input_datetime sensor. I've tried a couple of different options, but I don't see a way to accomplish this.
My input_datetime sensor is set to NOT have a date, and only have a time.
has_date: false
has_time: true
editable: true
hour: 7
minute: 40
second: 0
timestamp: 27600
friendly_name: Weekday
Using the timestamp is rather worthless, since it's not at true timestamp, since I don't have a date in here. Basically, I want to tell the timer card that the timer will go off at 7:40am and countdown between now at 7:40am. Is there a way to accomplish this that I am missing?
What an interesting use case! Unfortunately the card really needs a date to function, so I think your best bet would be to use a template. You can either create a template entity or use another custom card to do the templating for you.
If you format the date in the same manner as dates in the timestamp and combine that with the time that the timer goes off in the template, then you can pass that timestamp to the end_time
. If you decide to use a custom card to create the template, I think end_time: { fixed: <your time> }
would do the trick. Let me know if any of that is unclear!
It would be great to make this functionality build into the card, but since you're the first so far to propose using it for a purely time-based function, I don't think adding some way to support these kinds of entities in the card would be worth the effort. Especially if the template works!
Thanks for the response. I think by converting this to a template sensor, this should work, but I'm still struggling.
I created a template sensor under devices > helpers. The template would be:
{{ today_at(states('input_datetime.night_light_on_weekend')) }}
which would give me a result like 2023-10-14T03:45:00+00:00
I would think I could then place that into this card without issue, but this isn't working.
type: custom:timer-bar-card
entities:
- sensor.night_light_on_weekend
end_time:
attribute: state
debug: true
That will output:
I figure at this point it's a matter of not understanding the options properly to get it to calculate the end time properly.
You're almost there! That today_at
function is cool. I didn't know such a thing existed.
Instead of attribute: state
, you should use state: true
—that's how you tell the card to grab the end time from the state rather than from an attribute. Hopefully with that small change it'll work!
Great, thanks for the pointer. I actually needed to also set guess_mode
to true for it to work, otherwise it simply displayed the value of the sensor.night_light_on_weekend
sensor.
Working example below.
type: custom:timer-bar-card
entities:
- sensor.night_light_on_weekend
end_time:
state: true
guess_mode: true
Actually, this does work, but then when it's complete, it will then show the value of the sensor. How would you customize this so that it will show "idle" or something similar? I see you can use filter: true
which will hide the card entirely, but hoping I can get it to show some custom text.
I was wondering how you were going to handle that :) I would use the state of the sensor to compute the text, then move the completion time to an attribute.
Something along the lines of:
name: "input_datetime template"
state: "template that returns either Idle or the input_datetime's state depending on the time"
attributes:
end_time: "{{ today_at(states('input_datetime.night_light_on_weekend')) }}"
for the template and for the card:
type: custom:timer-bar-card
entities:
- sensor.night_light_on_weekend
# end_time no longer needed as it's named appropriately in the template entity
guess_mode: true