Can not figure out what is wrong with script

Hello.
I have an automation which turns off bathroom lights. I have no idea why, but it stopped working in some point. Can not found what I have messed up.

Here is my automation:

- id: '1538321511928'
  alias: Bath off on door motion and light
  initial_state: 'on'
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d0001e5d691
    platform: state
    to: 'on'
  condition:
  - condition: time
    after: '4:30:00'
    before: '21:00:00'
  - condition: state
    entity_id: binary_sensor.motion_sensor_158d000224aa83
    state: 'on'
  - condition: state
    entity_id: switch.wall_switch_right_158d000245c5ca
    state: 'on'
  action:
  - entity_id: script.1556739575120
    service: script.turn_off
  - service: script.1556739575120

And here is a script:

'1556739575120':
  alias: Bath wait for humidity then off
  sequence:
  - delay: 0:0:1
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d0001e5d691
    state: 'on'
  - delay: 0:2:0
  - condition: state
    entity_id: binary_sensor.motion_sensor_158d000224aa83
    state: 'off'
  - wait_template: "{{ states('sensor.humidity_158d0002279c7d')|float < 65 }}"
    timeout: '00:30:00'
  - condition: state
    entity_id: binary_sensor.motion_sensor_158d000224aa83
    state: 'off'
  - condition: state
    entity_id: switch.wall_switch_right_158d000245c5ca
    state: 'on'
  - data:
      entity_id: switch.wall_switch_right_158d000245c5ca
    service: switch.turn_off

And here is the issue from logs.

Thu Oct 10 2019 09:09:24 GMT+0300 (Москва, стандартное время)
Error while executing automation automation.bath_off_on_door_motion_and_light. Unknown error for call_service at pos 2: 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 434, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 98, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1234, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 139, in service_handler
    if script.is_on:
AttributeError: 'NoneType' object has no attribute 'is_on'

As I can see, this script works just fine:

'1536739675112':
  alias: Bath wait for humidity then off (night)
  sequence:
  - delay: 0:0:1
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d0001e5d691
    state: 'on'
  - data:
      entity_id: switch.wall_switch_right_158d000245c5ca
    service: switch.turn_off

What exactly are you trying to do here?

  action:
  - entity_id: script.1556739575120
    service: script.turn_off
  - service: script.1556739575120

If you want to run the script this is all you need (scripts are services):

  action:
  - service: script.1556739575120

If you want to stop the script:

  action:
  - service: script.turn_off
    entity_id: script.1556739575120

I stop the script if it is already running and run again

@pnbruckner teached me that. It works as it should. I used that in different automations where I run a script with delay

Try it with a short delay between stopping and starting the script.

That error is very strange. It’s almost as if the script disappeared at run time. FWIW, I don’t see anything wrong with the automation, and I even tested something similar and didn’t have any issues.

The script, however, seems somewhat strange (although nothing to explain the exception.) E.g. you have a condition in the script near the beginning that binary_sensor.motion_sensor_158d000224aa83 should be off, however you have the exact opposite condition in the automation. This alone would seem to prevent the script from ever getting to the last step.

Script was working earlier. I am not sure when it stopped to work, and I can not remember if I changed anything there

binary_sensor.motion_sensor_158d000224aa83 - is motion in bathroom. It should be ‘on’ to run the automation, but in script I check motion after 2 minutes and it should be ‘off’ if I actually left bathroom

I could not figure out what is wrong, I reduced script to simple one:

  sequence:
  - delay: 0:0:1
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d0001e5d691
    state: 'on'
  - data:
      entity_id: switch.wall_switch_right_158d000245c5ca
    service: switch.turn_off

And that did not work (as I see from logs, script was not fired)! But I have the same script and the same automation but for night (so at night bathroom light turns off immediately after leaving it and at the day it waits 2 minutes and humidity. So, I was really confused. Home Assistant reboot fixed that, now everything is working. I have no idea what is wrong here.

i have the same Problem after HA restart it works but after a while if got the same error message.

One example for a lightloop script

alarm_licht_loop:
  alias: Alarm Licht Wiederholung
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: script.alarm_licht_an
    service: script.turn_off
  - delay: 00:00:03
  - service: script.alarm_licht_an
alarm_licht_an:
  alias: Alarm Licht an
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - device_id: a649f4db576049c4be532d61d2041513
    domain: light
    entity_id: light.eingang
    type: turn_on
  - device_id: ae153657c5c3495d8bb190b24e7fb1e2
    domain: light
    entity_id: light.kuechen_decke
    type: turn_on
  - device_id: ca6d74e907f342fea91cae5f2347dde0
    domain: light
    entity_id: light.treppe
    type: turn_on
  - data:
      brightness: 255
      entity_id: light.eingang
      flash: long
    service: light.turn_on
  - data:
      brightness: 255
      entity_id: light.kuechen_decke
      flash: long
    service: light.turn_on
  - data:
      brightness: 255
      entity_id: light.treppe
      flash: long
    service: light.turn_on
  - delay: 00:00:20
  - service: script.alarm_licht_loop

another example for an script with alexa_mediaplayer

alarm_sound1_loop:
  alias: Alarm Hundebellen Wiederholung
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: script.alarm_sound1_an
    service: script.turn_off
  - delay: 00:00:03
  - service: script.alarm_sound1_an
alarm_sound1_an:
  alias: Alarm Hundebellen an
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: media_player.radio_kuche
      volume_level: 0.5
    service: media_player.volume_set
  - data:
      entity_id: media_player.radio_kuche
      media_content_id: Hundebellen - 2 große Hunde bellen bei Türklingel, bellender
        Hund
      media_content_type: AMAZON_MUSIC
    service: media_player.play_media
  - delay: 00:00:35
  - service: script.alarm_sound1_an    

i use those scripts for an alarm automation.
at the light script it helps if it turn the lights on…

example light on

    domain: light
    entity_id: light.eingang
    type: turn_on

… befor i lets start the flash function

example for flash of hue lights

  - data:
      brightness: 255
      entity_id: light.eingang
      flash: long
    service: light.turn_on

But the problem is that i have no idea how i can solve this issue with the alexa_mediaplayer

Have anyone a idea what could going wrong with the script?