Seems like overlooked the examples in the documentation, there’s one for your exact use case (the second last one):
# Sets date and time to date and time from datetime object (current date and time in this example)
- service: input_datetime.set_datetime
entity_id: input_datetime.date_and_time
data_template:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
Hi fedot, thanks for your reply. I certainly tried it on the base of documentation, but did not work.
Expected a value of type {action,navigation_path,url_path,service,service_data} | undefined for tap_action.entity_id but received "input_datetime.jacu".
Ah yes, the frontend sometimes requires an entity_id even if you don’t need it.
Try the one you’ve just posted, add entity_id: sun.sun (eg. below “type”)
Expected a value of type {action,navigation_path,url_path,service,service_data} | undefined for tap_action.data_template but received {"datetime":"{{ now().strftime('%Y-%m-%d %H:%M:%S') }}","entity_id":"input_datetime.jacu"}.
Yes, you’re right.
I just looked it up again, you can’t template in Lovelace.
Create a new script that calls the service with the data_template and then call the service from the tap_action. Sorry for the inconvenience
Yes, he’s talking about the template you have to use in your script. You can’t template in Lovelace, as I said.
Need a few hints for the script? Can write it for you if you want to
That’s a generalization and it doesn’t reflect the facts. The ability to support templating is not determined by Lovelace but by the card used.
The current set of standard cards don’t support templating for tap_action. However, there are various custom cards that do support templating. For example, the Auto-Entities card.
Thank you @123 , but that script also cannot be saved. It does not show an error but it is not stored and hence cannot be run (not even in the UI editor).
So half a step closer but not there yet.
And why does it not throw an error for your code?
Mine is from the docs. Are the docs outdated or is my syntax wrong? I cannot see any problem.
Checking at the moment if it is a local issue with my supervisor setup (corrupted something) or if this is a problem with me using packages:
When I create the script as yaml in packages, it works.
When I create it manually in scripts.yaml or save it via UI(which is written to scripts.yaml) neither show in the UI.
So the scripts.yaml entries are not shown in the UI. So maybe incompatibility with packages? All scripts in packages worj flawlessly (including these datetimes).