Hi all,
Just after a quick hand with passing variables to a notify script.
Got most of it down but failing on the last two, displaytime and icon.
I think its todo with the structure somewhere
Script: (working)
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
Auto: (working)
action:
service: script.turn_on
entity_id: script.kodi_notification
data:
variables:
title: 'Xiaomi Cube Says'
message: 'Ouch!'
The kodi example script gives:
- service: notify.NOTIFIER_NAME
data:
title: "Home Assistant"
message: "Message to KODI from Home Assistant!"
data:
displaytime: 20000
icon: "warning"
and I think its todo with how the displaytime and icon are under a different data: to the message and title.
I was trying:
Script: (not working)
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
icon: "{{ icon }}"
displaytime: "{{ displaytime}}"
Auto: (not working)
action:
service: script.turn_on
entity_id: script.kodi_notification
data:
variables:
title: 'Xiaomi Cube Says'
message: 'Ouch!'
icon: 'error'
displaytime: 20000
With errors in the log of:
Invalid service data for notify.kodi__atv: extra keys not allowed @ data['displaytime']. Got ''
extra keys not allowed @ data['icon']. Got ''
so I dont think the above is not passing the variables across.
If I can get this working I have a single script entry that I can pass data to rather than having multiple entries
If any one can advise that would be brill!
I helped someone the other day with a similar problem. There definitely has to be another data level for icon and displaytime. So try:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
data:
icon: "{{ icon }}"
displaytime: "{{ displaytime}}"
I’ve never done something like this with a data inside a data, so I don’t know if the second data should be data_template instead, but my guess would be no. But if the above doesn’t work, then try changing the second data to a data_template, too.
BTW, @petro , that doc page does describe two ways of passing variables. The first, using the script.turn_on service, does use a map with variables as the keyword. The second way, using the script name as the service, does away with that level of indirection.
1 Like
Just tried with both data and data template and got the following:
https://hastebin.com/yebiqoyulu.py
Also tried for giggles in the Auto but no luck:
action:
service: script.turn_on
entity_id: script.kodi_notification
data:
variables:
title: 'Xiaomi Cube Says'
message: 'Ouch!'
data:
variables:
icon: 'error'
displaytime: 20000
Hmm, ok, try this:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
data: {icon: "{{ icon }}", displaytime: "{{ displaytime}}"}
Error again
https://hastebin.com/vebecizeti.py
It really doesnt like this lol
Please post your current script and automation actions. FWIW, I expect this:
automation:
- alias: blah
...
action:
service: script.turn_on
entity_id: script.kodi_notification
data:
variables:
title: 'Xiaomi Cube Says'
message: 'Ouch!'
icon: 'error'
displaytime: 20000
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
data: {icon: "{{ icon }}", displaytime: "{{ displaytime}}"}
Or, for the automation:
automation:
- alias: blah
...
action:
service: script.kodi_notification
data:
title: 'Xiaomi Cube Says'
message: 'Ouch!'
icon: 'error'
displaytime: 20000
Ive just through a couple of different combinations of the above testing, might make things a little clearer with the auto/script/results:
https://hastebin.com/buzozabuqa.pl
https://hastebin.com/itisedoluh.cs
https://hastebin.com/rimurucoxi.cs
This is an interesting one as the log shows that it seems to have passed/parsed all the correct data but the notification itself doesn’t work
https://hastebin.com/kodihaciti.pl
In the last link, you show the log entries for the automation, but you’re not showing the log entries for the kodi_notification script itself. It would be helpful to see that. To be specific, it would help to see the log entries for the service call to notify.kodi__atv and any resulting errors from that.
Just done a clean log and two button presses to trigger it:
https://hastebin.com/zaxuzugeni.pl
Sorry, still not seeing the details of script.kodi_notification running and its call to notify.kodi__atv, nor any error or debug messages. I only see the details of the automation running and it calling script.kodi_notification.
1 Like
Yeah thats all I get with this one, that logs not edited. Deleted the logfiles, waited for it to refresh with something, pressed the button twice then copied pasted.
Whoa! I see zillions of more lines in my log. Are you sure you haven’t turned the logging down? Specifically, what is your configuration for logger?
Ive just restarted the Pi and get a lot more come through now. Dont know why it stopped logging properly!
Heres the above combo with two button presses:
https://hastebin.com/ikeruzasav.coffeescript
Just so we’re not chasing our tail on this one, as a test, could you try this for the script temporarily:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
data: {icon: "error!", displaytime: "20000"}
And if that still causes an error, then:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"
data: {icon: "error!", displaytime: 20000}
Trying to narrow down on what is causing the problem.
So let’s make it real simple (i.e., get rid of templating) and see if it still works:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data:
title: "title"
message: "message"
data: {icon: "error", displaytime: 20000}
And if that fails:
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data:
title: "title"
message: "message"
data:
icon: "error"
displaytime: 20000
Hmm, wait a sec! Reading the kodi notification doc page more closely, it says icon can be error
, but you had error!
. I wonder if that is what’s giving it a heartache???
pnbruckner:
Hmm, wait a sec! Reading the kodi notification doc page more closely, it says icon can be error
, but you had error!
. I wonder if that is what’s giving it a heartache???
Oh, never mind. Looks like you did have error
the last time.
Yeah I noticed the ! so deleted it before I ran,
These two both worked fine though:
https://hastebin.com/ebijidinav.xml
https://hastebin.com/onebavikil.pl
(I changed the automation to ‘warning’ as well to avoid any issues and the notification showed the text from the script rather than the auto)
So it’s starting to sound like maybe the templating is the problem. E.g., notice this line from a previous log:
2018-07-12 19:30:20 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=notify, service=kodi__atv, service_data=title=Xiaomi Cube Says, message=Ouch!, data=icon=error, displaytime=20000, service_call_id=1972992272-25>
But then just below:
2018-07-12 19:30:20 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall notify.kodi__atv: title=<homeassistant.helpers.template.Template object at 0x73073870>, message=<homeassistant.helpers.template.Template object at 0x73073dd0>, data=icon=error, displaytime=20000>
Notice how title & message are pointing to template objects instead of the resulting strings (which showed up in the service call event line above)? Hmm.
How does this work (i.e., only use templates with title & message, and drop icon & displaytime for now):
script:
kodi_notification:
sequence:
- service: notify.kodi__atv
data_template:
title: "{{ title }}"
message: "{{ message }}"