Hello,
I try to set the actual datetime to a text field via automation (cron).
The yaml looks like:
alias: DeyeTime
description: Set Deye Time
trigger:
- platform: time_pattern
minutes: "15"
condition: []
action:
- device_id: ....
domain: text
entity_id: ....
type: set_value
value: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
mode: single
But this does not update the entity.
That this manually works as expected.
Best regards,
Can you give more details?
Does the automation not trigger as expected?
Does the automation trigger as expected, but the action doesn’t update the text
entity?
What does the automation’s debug trace show?
123
(Taras)
June 4, 2024, 12:04am
3
You’re using a Device Action. It doesn’t support templates.
Use a Service Call . It supports templates.
alias: DeyeTime
description: Set Deye Time
trigger:
- platform: time_pattern
minutes: "15"
condition: []
action:
- service: input_text.set_value
target:
entity_id: input_text.your_input_text
data:
value: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
Adding to Taras, this might be an interesting read:
Background
When you start writing automations, a device trigger seems the obvious choice. Everybody knows what a device is and it comes at the top of the UI dropdown list.
[image]
It works… but it is certainly not a “great way to start” because it is storing up problems for the future. Far better to use an entity, with state or numeric_state.
Device_id problems
The yaml will be longer and harder to follow, which may make maintenance difficult, especially a few months down the line when yo…
teskanoo
(Teska Noo)
June 5, 2024, 7:04am
5
I am guessing you were hoping this would update every 15 minutes, however this yaml trigger is configured to update at 15 minutes past each hour.
trigger:
- platform: time_pattern
minutes: "/15"
The example above will trigger every 15 minutes.