Hello All,
Is it possible to add a service template to a script using the GUI, or do you need to manually create the script directly in scripts.yaml?
Hello All,
Is it possible to add a service template to a script using the GUI, or do you need to manually create the script directly in scripts.yaml?
This is the code for the script. This was working until I recently updated HA.
ha_notify_all_engines:
alias: Home Assistant Notification Engine
sequence:
- data:
data_template:
message: '{{ message }}'
title: Home Assistant Notification
data_template:
message: '{{ message }}'
notification_id: '{{ title }}'
title: '{{ title }}'
service: persistent_notification.create
- data_template:
message: '{{ message }}'
name: 'NOTIFY ALL:'
service: logbook.log
- service_template: "{%- if who is not string -%}{%- set who = 'user1'\
\ -%}{%- endif -%} {%- if who == 'user1' -%}\n notify.mobile_app_user1\n\
{%- elif who == 'user2' -%}\n notify.mobile_app_user2\n{%- elif who\
\ == 'family' -%}\n notify.family\n{%- elif who == 'parents' -%}\n notify.parents\n\
{%- elif who == 'kids' -%}\n notify.kids\n{%- elif who == 'Everyone' -%}\n\
\ notify.everyone\n{%- else -%}\n notify.mobile_app_notify_yy\n{%- endif -%}"
I’m getting an error:
Extra keys not allowed @data_template.
Any help is much appreciated!
Here you have data and a data_template without a service
actually, you have too many data sections. Remove the entire data: data_template stuff.
- data_template:
message: '{{ message }}'
notification_id: '{{ title }}'
title: '{{ title }}'
service: persistent_notification.create
To clarify, The - (dash) indicates each service call & data. You should only have 1 service and 1 data section per service call. Some services don’t require a data section, so you can omit that in those cases.
Thanks Petro & Francis. I made the changes, but still getting the error. Here is the revised code:
ha_notify_all_engines:
alias: Home Assistant Notification Engine
sequence:
- data_template:
message: '{{ message }}'
title: Home Assistant Notification
service: persistent_notification.create
- data_template:
message: '{{ message }}'
notification_id: '{{ title }}'
title: '{{ title }}'
service: logbook.log
- service_template:
"{%- if who is not string -%}{%- set who = 'user1'\
\ -%}{%- endif -%} {%- if who == 'user1' -%}\n notify.mobile_app_user1\n\
{%- elif who == 'user2' -%}\n notify.mobile_app_user2\n{%- elif who\
\ == 'family' -%}\n notify.family\n{%- elif who == 'parents' -%}\n notify.parents\n\
{%- elif who == 'kids' -%}\n notify.kids\n{%- elif who == 'Everyone' -%}\n\
\ notify.everyone\n{%- else -%}\n notify.mobile_app_notify_yy\n{%- endif -%}"
data_template:
message: '{{ message }}'
name: 'NOTIFY ALL:'
I think what happened is the code was scrambled when I opened this script in the script editor. Is that possible?
If I trim it down to just the one service call, I determined it is the service template that is causing the problem. Are you not supposed to use data_template with service_template?