No problem, by the way this is ‘almost exactly’ what the link @pniewiadowski pointed you to in the documentation.
Try search for other threads on your topic, and then search the documentation (goto integrations and search from there) failing all that feel free to ask of the community.
By the way please read the “guidelines” (search) and Tinkerer’s very good sticky thread at the top of the forum, it will stand you in good stead.
Good Luck
Edit: By the way, this assumes that you have created two input_datetime 's
e.g. : -
input_datetime:
id_boiler_on_time:
name: Boiler Last On Time
has_date: true
has_time: true
id_boiler_off_time:
name: Boiler Last Off Time
has_date: true
has_time: true
Well, I’ve been trying this now for almost 5 hours tonight and nothing seems to work, I’ve tried loads and loads of permutations and I can’t get it to like anything. It complains if I use data_template anywhere.
The only thing that worked was getting them to show up on the Lovelace UI. It always changes to ‘[object Object]’: null. I’ve tried in the automations UI and also editing the automations.yaml.
Try not to post pictures, they are huge in comparison to text and it’s hard to copy and paste into a template editor to check/diagnose.
From what I see the object bit is your problem but I have never used the automation editor so I’m going to have to transfer to a workstation (unless someone else comes back before then, circa 2-3 hours)
I tried what you gave me editing the automation.yaml and it complained about the use of data_template in the log. I’ll take the pictures posting comment on board, sometimes it says more than words, however I’ll stick to code tags.
I don’t use the Automation Editor but I believe you are correct. The Automation Editor has certain limitations and can’t be used to create the example I posted above.
- id: on_off_boiler
alias: Boiler state time
trigger:
- entity_id: switch.boiler
platform: state
action:
service: input_datetime.set_datetime
data_template:
entity_id: input_datetime.boiler_last_{{ trigger.to_state.state }}
datetime: "{{ now().strftime('%d-%m-%Y %H:%M:%S') }}"
I can’t get the value of entity_id: input_datetime.boiler_last_ to show dd-mmm-yyyy (%d-%m-%Y) should have done it I thought, however it always shows as yyy-mmm-dd, both in the states checker and lovelace.
States checker shows the following
editable: false
has_date: true
has_time: true
year: 2020
month: 5
day: 17
hour: 13
minute: 41
second: 0
timestamp: 1589719260
friendly_name: Boiler Last On Time