Script problem

I have the following script. It uses the ADS service to write to a ADS variable.
After one second delay, it writes the same variable with another value.

ads_momentary_switch_nc:
  alias: Pushbutton ADS NC
  sequence:
  - data_template:
      adstype: byte
      adsvar: "{{ adsvariable }}"
      value: 0
    service: ads.write_data_by_name
  - delay: 00:00:01
  - data_template:
      adstype: byte
      adsvar: "{{ adsvariable }}"
      value: 1
    service: ads.write_data_by_name

Problem is that I’m unable to pass the variable to the script.
I want to trigger it from a switch, the code gets triggered but nothing happens.
If I change the {{ adsvariable }} to a fixed known variable, it functions. But I want to make it dynamic.
What am I missing here?

How are you passing the variable?

From a template, switch:

    bediening_osmose:
  friendly_name: "Osmose"
  value_template: "{{ is_state('status_osmose_productie', 'on') }}"
  turn_on:
    service: script.ads_momentary_switch_no
    data:
      adsvariable: "gvlHomeAssistant.bBedOsmoseStart"
  turn_off:
    service: script.ads_momentary_switch_nc
    data:
      adsvariable: "gvlHomeAssistant.bBedOsmoseStop"

it also outputs the following error in the log:

2019-01-14 22:54:40 INFO (MainThread) [homeassistant.helpers.script] Running script

2019-01-14 22:54:40 INFO (MainThread) [homeassistant.helpers.script] Executing step call service

2019-01-14 22:54:40 INFO (MainThread) [homeassistant.helpers.script] Script Pushbutton ADS NO: Running script

2019-01-14 22:54:40 INFO (MainThread) [homeassistant.helpers.script] Script Pushbutton ADS NO: Executing step call service
2019-01-14 22:54:40 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 287, in _handle_service_platform_call
await getattr(entity, func)(**data)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/template.py”, line 154, in async_turn_on
await self._on_script.async_run(context=self._context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 131, in async_run
await self._handle_action(action, variables, context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 210, in _handle_action
action, variables, context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 299, in _async_call_service
context=context
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 85, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1121, in async_call
self._execute_service(handler, service_call))
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1143, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/script.py”, line 123, in service_handler
context=service.context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/script.py”, line 181, in async_turn_on
kwargs.get(ATTR_VARIABLES), context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 131, in async_run
await self._handle_action(action, variables, context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 210, in _handle_action
action, variables, context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 299, in _async_call_service
context=context
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 85, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1121, in async_call
self._execute_service(handler, service_call))
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1145, in _execute_service
await self._hass.async_add_executor_job(handler.func, service_call)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/ads/init.py”, line 96, in handle_write_data_by_name
ads.write_by_name(ads_var, value, ads.ADS_TYPEMAP[ads_type])
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/ads/init.py”, line 153, in write_by_name
return self._client.write_by_name(name, value, plc_datatype)
File “/srv/homeassistant/lib/python3.5/site-packages/pyads/ads.py”, line 533, in write_by_name
value, plc_datatype)
File “/srv/homeassistant/lib/python3.5/site-packages/pyads/pyads_ex.py”, line 502, in adsSyncWriteByNameEx
port, address, ADSIGRP_SYM_VALBYHND, handle, value, data_type
File “/srv/homeassistant/lib/python3.5/site-packages/pyads/pyads_ex.py”, line 301, in adsSyncWriteReqEx
data = plc_data_type(value)
TypeError: an integer is required (got type str)

Seems it’s complaining about the data type, that int is expected, and string received. But the script sends an integer as value?

try with “0” “1”

also i havent seen anyone using ```
adsvariable

But who knows maybe it's implemented here

Edit: your are not "telling" anywhere that it should an "int" , you just type 0 , 1