Davecl
(Dave Clarke)
August 19, 2023, 4:51pm
1
I’ve cobbled together this automation in yaml mode but when i go to save it it gives the following error
Message malformed: extra keys not allowed @ data[‘0’]
Any ideas thanks?
- alias: Turn on Gecko1 at 00:01
trigger:
platform: time
at: '00:01:00'
condition:
condition: template
value_template: "{{ (now().date() - states('input_datetime.gecko1_on_time').date() | as_datetime).days >= 4 }}"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.gecko1
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.gecko1_on_time
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
Edwin_D
(Edwin D.)
August 19, 2023, 4:57pm
2
At first glance I’d say triggers and conditions should be an array, so preceded by -
But to be sure, create one in the UI and you’ll see the structure you should have had.
You need to use data
or target
for the entity ID…
- service: input_boolean.turn_on
target:
entity_id: input_boolean.gecko1
Davecl
(Dave Clarke)
August 19, 2023, 5:24pm
4
thanks guys… this is now what i have and it seems to work how i want it
alias: tester
description: ""
trigger:
- platform: time
at: "18:30:00"
condition:
- condition: template
value_template: >-
"{{ (now().date() - states('input_datetime.gecko1_on_time').date() | as_datetime).days >= 4 }}"
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.gecko1
data: {}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.gecko1_on_time
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
mode: single
Edwin_D
(Edwin D.)
August 19, 2023, 5:29pm
5
Are you sure this does what you want? Because the quotes are for single line templates, if you use >- I think the quotes should go.
Edwin_D
(Edwin D.)
August 19, 2023, 5:29pm
6
… and this no longer names the entity
Davecl
(Dave Clarke)
August 19, 2023, 5:32pm
7
yeah sorry just noticed that and edited
Davecl
(Dave Clarke)
August 19, 2023, 5:35pm
8
mmmm, tested it with developer tools > states and the input boolean is turning on and the date is being updated, however I will try it without quotes
123
(Taras)
August 19, 2023, 5:53pm
9
What’s the purpose of this automation?
It appears to turn on an Input Boolean every 4 days at 18:30.
If that’s all it does then it’s possible to do that without an Input Datetime.
Example
Turn on Input Boolean every 4 days at 18:30.
alias: tester
description: ""
trigger:
- platform: time
at: "18:30:00"
condition:
- condition: template
value_template: "{{ (now() - as_datetime(0)).days % 4 == 0 }}"
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.gecko1
mode: single
Davecl
(Dave Clarke)
August 19, 2023, 6:00pm
10
123:
What’s the purpose of this automation?
It appears to turn on an Input Boolean every 4 days at 18:30.
If that’s all it does then it’s possible to do that without an Input Datetime
Hi
Yes it just turns on the input boolean but only if it’s 4 days since it was last turned on, hence why i was trying to use input datetime to store the last time it was turned on, maybe i’m making it more complicated than it needs to be?
Davecl
(Dave Clarke)
August 19, 2023, 6:04pm
11
I was testing it by just running it, forgetting that this overrides the condition.
when i have tried it in a real world situation the condition doesn’t pass because there is an error in my template
Error: In ‘template’ condition: UndefinedError: ‘str object’ has no attribute ‘date’
Davecl
(Dave Clarke)
August 19, 2023, 7:01pm
12
Ok @Didgeridrew @123 @Edwin_D
I now have this which has been tested in a real world situation and seems to work fine, I have added another action which turns the input boolean off again just before midnight.
My next task is to set 2 more conditions so that it only runs if it’s 4 days since last running but if it’s 16 days then dont turn the boolean on but DO set the input datetime.
Thanks for your help so far… I’ll be back
alias: Turn Gecko1 On Every 4 Days
description: ""
trigger:
- platform: time
at: "00:01:00"
condition:
- condition: template
value_template: >-
{{ (now().date() - strptime(states('input_datetime.gecko1_on_time'),
'%Y-%m-%d %H:%M:%S').date()).days >= 4 }}
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.gecko1
data: {}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.gecko1_on_time
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
- wait_for_trigger:
- platform: time
at: "23:59:00"
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.gecko1
mode: single
123
(Taras)
August 19, 2023, 8:23pm
13
Yes.
See the example I posted above which does what you want without an Input Datetime.
If you want the automation to turn on the Input Boolean every 4 days at one time and off at another time (later on the same day), then I suggest this:
alias: tester
description: ""
trigger:
- id: 'on'
platform: time
at: '01:00:00'
- id: 'off'
platform: time
at: '23:59:00'
condition:
- condition: template
value_template: "{{ (now() - as_datetime(0)).days % 4 == 0 }}"
action:
- service: 'input_boolean.turn_{{ trigger.id }}'
target:
entity_id: input_boolean.gecko1
mode: single