How can I fix it. On service call I get the following error: extra keys not allowed @ data[‘data_template’]
That is my automation:
- id: benachrichtigung_batterie_higrow
alias: Benachrichtigung Batterie HiGrow
trigger:
- below: '3.00'
entity_id: sensor.higrow_battery
for: 00:00:03
platform: numeric_state
condition:
- condition: template
value_template: '{{ trigger.to_state.state != nan }}'
action:
- data:
data_template:
tag: higrow_battery_notification
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
title: '{ trigger.to_state.attributes.friendly_name }} Aufladen!'
service: notify.html
- data:
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name
}} Akku aufladen!'
notification_id: esp01_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
data_template:
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
notification_id: higrow_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
service: persistent_notification.create
initial_state: true
Thanks for help
~Marlon
123
(Taras)
May 13, 2019, 7:00pm
2
You’re using both data:
and data_template:
You use one or the other. In your case, because you have templates, you should use data_template
.
- id: benachrichtigung_batterie_higrow
alias: Benachrichtigung Batterie HiGrow
trigger:
- below: '3.00'
entity_id: sensor.higrow_battery
for: 00:00:03
platform: numeric_state
condition:
- condition: template
value_template: '{{ trigger.to_state.state != nan }}'
action:
- service: notify.html
data_template:
tag: higrow_battery_notification
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
title: '{{ trigger.to_state.attributes.friendly_name }} Aufladen!'
- service: persistent_notification.create
data_template:
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name
}} Akku aufladen!'
notification_id: esp01_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
- service: persistent_notification.create
data_template:
message: '{{ now().strftime(''%d.%m.%Y %H:%M:%S'') }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
notification_id: higrow_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
initial_state: true
EDIT
Corrected syntax error copied from the original automation.
2019-05-13 21:05:17 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined
123
(Taras)
May 13, 2019, 7:11pm
4
That error message is a result of a syntax error in the original automation (I simply used whatever you provided).
This line is missing an initial {
title: '{ trigger.to_state.attributes.friendly_name }} Aufladen!'
Change it to {{
like this:
title: '{{ trigger.to_state.attributes.friendly_name }} Aufladen!'
2019-05-13 21:14:36 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined
123
(Taras)
May 13, 2019, 7:18pm
7
Did you ‘Reload Automations’ after making the correction?
Yes. I have restarted complete hassio
123
(Taras)
May 13, 2019, 7:27pm
9
The automation passes Config Check on my system and Visual Studio Code reports no other errors.
I can’t test the automation for you because my system does not have any of the sensors it uses.
As a side-note, this is not the usual way to delimit a string:
(''%d.%m.%Y %H:%M:%S'')
I suggest using a double-quote "
in this situation and not two consecutive single-quotes ''
("%d.%m.%Y %H:%M:%S")
123
(Taras)
May 13, 2019, 7:34pm
11
Try this. It uses double-quotes to delimit the strings (and delimits the time-string '00:00:03'
). After making the change, you don’t have to restart Home Assistant, just use ‘Reload Automations’ (it’s faster).
- id: benachrichtigung_batterie_higrow
alias: Benachrichtigung Batterie HiGrow
trigger:
- below: '3.00'
entity_id: sensor.higrow_battery
for: '00:00:03'
platform: numeric_state
condition:
- condition: template
value_template: '{{ trigger.to_state.state != nan }}'
action:
- service: notify.html
data_template:
tag: higrow_battery_notification
message: '{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
title: '{{ trigger.to_state.attributes.friendly_name }} Aufladen!'
- service: persistent_notification.create
data_template:
message: '{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name
}} Akku aufladen!'
notification_id: esp01_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
- service: persistent_notification.create
data_template:
message: '{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!'
notification_id: higrow_battery_notification
title: '{{ trigger.to_state.attributes.friendly_name }}'
initial_state: true
2019-05-13 21:14:36 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined
Same error
123
(Taras)
May 13, 2019, 7:52pm
14
How are you testing this automation?
Are you using the Services page (dev-service) to manually execute it?
you can make life a bit easier to reorder somewhat, and use multiline notation (using ‘>’ ) to prevent issues with quotes:
- id: benachrichtigung_batterie_higrow
alias: Benachrichtigung Batterie HiGrow
initial_state: true
trigger:
platform: numeric_state
entity_id: sensor.higrow_battery
below: 3.00
for:
seconds: 3
condition:
condition: template
value_template: >
{{ trigger.to_state.state != nan }}
action:
- service: notify.html
data_template:
title: >
{{ trigger.to_state.attributes.friendly_name }} Aufladen!
message: >
{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!
tag: higrow_battery_notification
- service: persistent_notification.create
data_template:
title: >
{{ trigger.to_state.attributes.friendly_name }}
message: >
{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name
}} Akku aufladen!
notification_id: esp01_battery_notification
- service: persistent_notification.create
data_template:
title: >
{{ trigger.to_state.attributes.friendly_name }}
message: >
{{ now().strftime("%d.%m.%Y %H:%M:%S") }} Achtung!: {{ trigger.to_state.attributes.friendly_name }} Akku aufladen!
notification_id: higrow_battery_notification
not familiar with your trigger, but the ‘below’ seems a bit awkward?
as @123 points out, triggers aren’t populated when testing in the dev-service or dev-template, since you trigger them manually …
tom_l
May 13, 2019, 11:32pm
16
You used a string for a numeric_state trigger as per Marius’ post, change
- below: '3.00'
to
below: 3.00
what isnt working? see any errors? does it trigger but dont pass the condition. wont the action take place. In other words, give us more…
you could for testing purposes replace the
{{ trigger.to_state.attributes.friendly_name }}
with the actual name in your actions, since these are all for the same sensor, no need to use templates there. Makes debugging a bit easier
thats not possible, if you do as I suggested.