# ExecuteHandler | Local Home SDK

# - [smarthome](https://developers.home.google.com/reference/local-home/modules/smarthome.html).
- [IntentFlow](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html).
- ExecuteHandler

Callback registered with the [App](https://developers.home.google.com/reference/local-home/classes/smarthome.app.html) via [App.onExecute](https://developers.home.google.com/reference/local-home/classes/smarthome.app.html#onexecute) to process
requests to update device state.

To support local fulfillment, the local home platform must first
establish a local fulfillment path. For more details, see the
[developer guide](https://developers.home.google.com/local-home/overview).

    const executeHandler = (request: IntentFlow.ExecuteRequest):
      Promise<IntentFlow.ExecuteResponse> => {

        // Extract command(s) and device target(s) from request
        const command = request.inputs[0].payload.commands[0];
        const execution = command.execution[0];

        const response = new Execute.Response.Builder()
          .setRequestId(request.requestId);

        const result = command.devices.map((device) => {
          // Construct a local device command
          const deviceCommand = new DataFlow.TcpRequestData();
          // ...

          // Send command to the local device
          return localHomeApp.getDeviceManager()
            .send(deviceCommand)
            .then((result) => {
              response.setSuccessState(result.deviceId, state);
            })
            .catch((err: IntentFlow.HandlerError) => {
              // Please specify the right error code in setErrorState()
              response.setErrorState(
                device.id, IntentFlow.ExecuteErrorCode.HARD_ERROR);
            });
        });

        // Respond once all commands complete
        return Promise.all(result)
          .then(() => response.build());
      };

### Callable

- __call ( request : [ExecuteRequest](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executerequest) ) : Promise \< [ExecuteResponse](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executeresponse) \> \| [ExecuteResponse](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executeresponse)
- Callback function for the intent.

  Implement this function to handle each intent request and return
  a response.

  #### Parameters

  -

    ##### request: [ExecuteRequest](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executerequest)

  #### Returns Promise\<[ExecuteResponse](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executeresponse)\> \| [ExecuteResponse](https://developers.home.google.com/reference/local-home/modules/smarthome.intentflow.html#executeresponse)