# Home Assistant

Home Assistant is an open source home automation solution.

# Connect to Hapticlabs Studio

Within Home Assistant, it is possible to trigger haptic playback through Hapticlabs Studio's TCP-API:

TCP
../../api/tcp-port/

To set up haptic playback through Hapticlabs Studio on your Home Assistant installation, add the following shell_command entry to your configuration.yaml file:

shell_command:
  hapticlabs_start_track: "python3 -c \"import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(('', 64209)); s.send('startTrack(\\\"\\\");\\n'.encode()); s.close()\""

After restarting Home Assistant to load the updated configuration.yaml, hapticlabs_start_track should be available as a service:

Note that the service requires two arguments:

  • hostip is the IP address on the local network of the device running Hapticlabs Studio
  • trackname is the name of the track in Hapticlabs Studio. The track must be present in the currently selected project.

Note: The hostip and trackname arguments are injected directly into the shell command. Avoid special characters like ', ", {, }, \ in these arguments.

# Trigger the Satellite from your ESPHome device

ESPHome is a system to control microcontrollers for home automation. It integrates well with Home Assistant.

It is possible to trigger haptic playback on the Hapticlabs Satellite from a microcontroller running ESPHome. There's two main options: GPIOs and UART.

# Via GPIOs

Using your ESPHome device, you can operate the trigger pins of the Hapticlabs Satellite. To achieve this, add the following to your ESPHome's .yaml file's switch section:

switch:
  - platform: gpio
    pin: GPIOXX
    id: gpio_dXX
    name: "Hapticlabs Pin 1"
  - platform: gpio
    pin: GPIOXX
    id: gpio_dXX
    name: "Hapticlabs Pin 2"

Replace XX with the GPIO numbers on your ESPHome device that you connected to Pin 1 and Pin 2 on the Hapticlabs Satellite.

With this, you should see corresponding entities in your Home Assistant interface with which you can trigger the Hapticlabs Satellite:

Note that you can make use of all trigger modes, including loop, trigger, rising/falling edge, etc:

External Trigger
../../settingspanel/externaltrigger/

# Via UART   Pro

If you need more than two tracks for your project, you can use the UART mode of the Hapticlabs Satellite. To achieve this, set your Satellite to UART mode, upload your tracks, and add the following to your ESPHome's .yaml file's uart and switch sections:

uart:
  tx_pin: GPIOXX # Connect to Pin 2 on your Hapticlabs Satellite
  rx_pin: GPIOXX # Connect to Pin 1 on your Hapticlabs Satellite
  baud_rate: 9600

switch:
  - platform: template
    name: "Start Hapticlabs Track (Pulse ramp)"
    turn_on_action:
      - uart.write: startTrack("Pulse ramp");
  - platform: template
    name: "Start Hapticlabs Track (Frequency fun)"
    turn_on_action:
      - uart.write: startTrack("Frequency fun");
  - platform: template
    name: "Start Hapticlabs Track (Stereo Track)"
    turn_on_action:
      - uart.write: startTrack("Stereo Track");

UART setup:

UART
../../api/uart/

Replace XX with the GPIO numbers on your ESPHome device that you connected to Pin 1 and Pin 2 on the Hapticlabs Satellite.

The key point here is the uart.write action. The argument should be of the format startTrack(\"<track name>\");. Note that you are not limited to use that action in the switch for Home Assistant, but you can use it anywhere in your ESPHome project.

UART
../../api/uart/

With this, you should see corresponding entities in your Home Assistant interface with which you can trigger the Hapticlabs Satellite: