Script calling failure from an automation but succeeds from developer tools

Dear community,

I’m trying to call a script ( script.send_notification_to_alexa ) from an automation with no success. The same script runs successfully from developer tools.

First the script:

send_notification_to_alexa:
  alias: Send notification from Alexa
  sequence:
  - choose:
    - conditions:
      - condition: time
        before: '19:00'
        after: "09:00"
      sequence:
      - service: notify.alexa_media_office_echo_dot
        data_template:
          message: "{{ what_to_announce }}"
          data:
            type: announce
    - conditions:
      - condition: time
        before: '09:00'
      sequence:
      - service: notify.alexa_media_kitchen_echo_dot
        data_template:
          message: "{{ what_to_announce }}"
          data:
            type: announce
    - conditions:
      - condition: time
        after: '18:00'
      sequence:
      - service: notify.alexa_media_living_room_echo_dot
        data_template:
          message: "{{ what_to_announce }}"
          data:
            type: announce
    default: []
  mode: single
  icon: mdi:script

Then, the automation:

- id: '1622552193007'
  alias: Close blinds at sunset
  description: Close left and right blinds from living room at sunset if I am at home
  trigger:
  - platform: sun
    event: sunset
    offset: 00:30:00
  condition:
  - condition: state
    entity_id: person.nicolas
    state: home
  action:
  - service: script.send_notification_to_alexa
    data:
      what_to_announce: Attention à la fermeture des store
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: cover.close_cover
    target:
      entity_id:
      - cover.sonesse_40_io_2
      - cover.sonesse_40_io_3
  mode: single

And finally the way I successfully call the script from developer tools:

service: script.send_notification_to_alexa
data:
  what_to_announce: Attention à la fermeture des store

Do you have any idea?

A big thanks in advance for your help,

Oh and BTW, here is the error output from the log

[1549488360] Error handling message: extra keys not allowed @ data[‘what_to_announce’]. Got None

Which is quite strange because the same thing works very well when invoked from the developer tools

Is the automation executed, i.e. do the cover close?
If so, what does the trace show?

Nice “BTW” :slight_smile:

Yes, the automation is triggered 30 minutes after sun set and the blinds close well.

Here is the trace…

Executed: 30 June 2021, 22:26:30
Step ConfigChanged VariablesRelated logbook entries
platform: sun
event: sunset
offset: ‘00:30:00’

Executed: 30 June 2021, 22:26:30
Result:
result: true

entity_id/0

Executed: 30 June 2021, 22:26:30
Result:
result: true state: home wanted_state: home

Executed: 30 June 2021, 22:26:30
Result:
params:
domain: script
service: send_notification_to_alexa
service_data:
what_to_announce: Attention à la fermeture des store
target: {}
running_script: true
limit: null
child_id:
domain: script
item_id: send_notification_to_alexa
run_id: ‘41’

Executed: 30 June 2021, 22:26:30
Result:
delay: 60 done: true

Executed: 30 June 2021, 22:27:30
Result:
params:
domain: cover
service: close_cover
service_data: {}
target:
entity_id:
- cover.sonesse_40_io_2
- cover.sonesse_40_io_3
running_script: false
limit: 10

or maybe it’s more clear from the trace timeline :wink:

Triggered by the sunset with offset at 30 June 2021, 22:26:30
Test state condition
Call service script.send_notification_to_alexa
Send notification from Alexa (script.send_notification_to_alexa) started
Send notification from Alexa (script.send_notification_to_alexa) turned on
Send notification from Alexa (script.send_notification_to_alexa) turned off
Delay for {“hours”:0,“minutes”:1,“seconds”:0,“milliseconds”:0}
1 minute later
Call service cover.close_cover on entities cover.sonesse_40_io_2, cover.sonesse_40_io_3
Sonesse 40 io (cover.sonesse_40_io_3) is closing
Sonesse 40 io (cover.sonesse_40_io_2) is closing
Cover (group.cover) changed to Closed
Finished at 30 June 2021, 22:27:30 (runtime: 60.30 seconds)

Not obvious.
Maybe try to put the “Attention…” message between quotes in the automation?

Hi Chris,

Thank you for your answer. Let’s give it a try tonight in real condition.

Regards,

Nicolas

Hi,

I just wanted to let you know that I magically did nothing and it magically worked yesterday evening…

Maybe a running condition or something but it seems ok for now…

Regards