Input_datetime initial value with time only

When trying to configure an input_datetime with only time I get a configuration error if I try to set an initial value with just a time value. It seems I can get around the issue by including a date in the intial value but it would be nice if it allowed date and time or just a date or just a time. It would be even better if it validated to the appropriate value based on how has_date and has_time are set.

Here is the error I got:

2017-10-08 07:21:13 ERROR (MainThread) [homeassistant.config] Invalid config for [input_datetime]: Invalid datetime specified: 06:30 for dictionary value @ data['input_datetime']['alarm_clock_time']['initial']. Got '06:30'. (See /home/homeassistant/.homeassistant/configuration.yaml, line 169). Please check the docs at https://home-assistant.io/components/input_datetime/
2017-10-08 07:21:13 ERROR (MainThread) [homeassistant.setup] Setup failed for input_datetime: Invalid config.

same issue here. still exploring other workarounds

hey there,

I got it working by this way:

input_datetime: 
  wakeup_alarm:
    name: Wake Up Alarm
    has_date: false
    has_time: true
    initial: '2017-06-01 06:00'

As the input_datetime is configured with has_time: true and has_date: false when I check the status I can only see the time.

My problem now if to fire an automation based on comparing this component with the current time.

Time Sensor: {{ states.sensor.time.state  }} 
Alarm: {{ states.input_datetime.wakeup_dads_alarm.state }}

first one gives me: 16:37 but the input_datetime returns 16:37:00 so something as simple as this below for an automation trigger actually gets complicated with formatting, etc:

{{ states.sensor.time.state == states.input_datetime.wakeup_alarm.state }}

any ideas? :slight_smile:

BTW, I solved the trigger with this:

  trigger:
  - platform: template
value_template: '{{ states.sensor.time.state == (states.input_datetime.wakeup_dads_alarm.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'

not the best, not the most elegant … but it works for now :slight_smile:

3 Likes

nice, think that’ll work for me too. Pity you can’t use variables in a trigger, something like

trigger:
  platform: time
  at: '{{ states.input_datetime.wakeup_dads_alarm.state }}'
5 Likes

It would still be nice if you could leave the date out of the initial value when has_date is false.

1 Like

Thanks for this @davedan.
I’ve been watching the input_datetime so I can set when I want my coffee machine to come on in the UI.
I tried a bunch of stuff before realing that what @proddy said (what I was trying) doesn’t work…

Does anyone know if there’s a plan to make at and for in platform: time templatable?
It would be very much nicer than having to create both a new time sensor and a template trigger to check if the two match.

1 Like

@jceloria thanks for sharing. I think that’ll work too. My only concern is how often the trigger is checked (for performance reasons). Is it on every state change of states.sensor.time.state which is every second? not sure.

I’m using the built in HA time and date sensor (HH:MM), and comparing that to a fixed value. I’m not sure how inefficient the built in sensor is, but triggering on state change I would guess that the worse case scenario is that it runs once every minute.

that’s my understanding as well … everytime the time sensor changes it’s evaluated.

the best solution for avoiding that is to use:

trigger:
platform: time
at: ‘{{ states.input_datetime.wakeup_dads_alarm.state }}’

but as mentioned before it’s not implemented :frowning:

It looks like the original request has been implemented in a recent change… that broke my config :slight_smile:

initial (Optional): Set the initial value of this input. Defaults to ‘1970-01-01 00:00’. If has_time is false this must be just a date (e.g.: ‘1970-01-01’). If has_date is false this must be just a time (e.g.: ‘15:16’).

great! I’ll check it out…

I finally got around to testing this out and it works exactly like I was hoping, so thank you to whoever ended up implementing this!

I am running 0.63.3 and struggling with a similar issue.

This is how the config looks like

start_night:
  name: Start Nacht
  has_date: false
  has_time: true
  initial: 23:15:00

start_day:
  name: Start Tag
  has_date: false
  has_time: true
  initial: 05:00:00

This results in

grafik

and the log tells

2018-02-21 10:35:13 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, entity_id=input_datetime.start_day, new_state=<state input_datetime.start_day=05:00:00; minute=0, has_date=False, second=0, has_time=True, hour=5, timestamp=18000, friendly_name=Start Tag @ 2018-02-21T09:35:13.948102+00:00>>
2018-02-21 10:35:13 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, entity_id=input_datetime.start_night, new_state=<state input_datetime.start_night=unknown; has_date=False, friendly_name=Start Nacht, has_time=True @ 2018-02-21T09:35:13.948918+00:00>>

Am I doing something wrong or is this a bug?

I can answer my own question …
Using

'23:15'

works.

2 Likes

Thanks for posting the solution - it really helps everyone else on the forum!