Hello everyone,
I have created an input_datetime
and would like the initial state to be the current time.
Is this possible somehow?
And would it also be possible to somehow reset it to now using a button (e.g. a service call or something)?
Simple input_datetime where I would like the end_time to be current time.
input_datetime:
start_datetime:
name: start_datetime
has_date: true
has_time: true
end_datetime:
name: end_datetime
has_date: true
has_time: true
Thank you
Alex
pedolsky
(Pedolsky)
October 29, 2022, 10:16am
2
If I recall correctly, the initial
field is not templatable. A workaround would be to use an automation that resets the helper on every HA restart and/or a specific time.
Create a small script and call it in both automation action and button action:
service: input_datetime.set_datetime
data:
datetime: "{{ now() }}"
target:
entity_id: input_datetime.xyz
3 Likes
I stumbled across this old thread because I could not get the fix examples working.
Found this old thread.
I am trying to do the same thing but actually with a script.
Somehow it is not working.
alias: New Script
sequence:
- service: input_datetime.set_datetime
data:
datetime: "{{ now().timestamp() | timestamp_local }}"
target:
entity_id: input_datetime.end_datetime
mode: single
[Screenshot_20221028_234449]
Does your code work for you?
Tested, not working:
alias: New Script
sequence:
- service: input_datetime.set_datetime
data:
datetime: "{{ now().timestamp() | timestamp_local }}"
target:
entity_id: input_datetime.end_datetime
mode: single
and
alias: New Script
sequence:
- service: input_datetime.set_datetime
data:
timestamp: "{{ now().timestamp() }}"
target:
entity_id: input_datetime.end_datetime
mode: single
pedolsky
(Pedolsky)
October 29, 2022, 10:50am
4
I’ve tested successfully with:
alias: 1 Test set datetime now
sequence:
- service: input_datetime.set_datetime
data:
datetime: "{{ now() }}"
target:
entity_id: input_datetime.both_date_and_time
mode: restart
1 Like
pedolsky
(Pedolsky)
October 29, 2022, 10:56am
5
Since
data:
timestamp: "{{ now().timestamp() }}"
is also working in my setup, maybe something went wrong with your script. Where did you create it? UI or packages/ extra file?
1 Like
UI only so far. And it does not save.
pedolsky
(Pedolsky)
October 29, 2022, 11:09am
7
Does the entity id already exist?
Same as with mine. I gut save and nothing happens.
Starting to think there is a system problem.
pedolsky
(Pedolsky)
October 29, 2022, 11:11am
9
Rename your script in scripts.yaml, reload and try again.
AleXSR700
(Alex)
October 29, 2022, 11:21am
10
Deleted scripts. yaml (I used packages approach for hand made scripts), restarted and created script via ui again. Scripts.yaml gets created with new script but does not show in ui.
Very, very strange.
pedolsky
(Pedolsky)
October 29, 2022, 11:27am
11
Again: Have you tried to rename your script in scripts.yaml and then reloaded?
AleXSR700
(Alex)
October 29, 2022, 11:32am
12
Tried all kinds of names including yours
Will try creating dedicated yaml in packages next. Maybe the mix is no longer working properly.
pedolsky
(Pedolsky)
October 29, 2022, 11:34am
13
Could be worth to raise an issue.
AleXSR700
(Alex)
October 29, 2022, 12:15pm
14
Depends on if this occurs for others also. You have no issues via UI?
AleXSR700
(Alex)
October 29, 2022, 12:24pm
15
Working as a package. Will have to test more to know if it is a problem with my machine or not.
script:
end_datetime_reset:
alias: End Datetime Reset
sequence:
- service: input_datetime.set_datetime
data:
timestamp: "{{ now().timestamp() }}"
target:
entity_id: input_datetime.end_datetime
mode: single
pedolsky
(Pedolsky)
October 29, 2022, 12:37pm
16
No. I’m running Supervised - but I jumped from 2022.10.4 to 2022.11 beta skipping core-2022.10.5. Maybe 10.5 has a problem?
ssams
(samiam)
October 29, 2022, 4:40pm
18
Thanks. Kind of surprising