Table of Contents

5.4 Using BLOX with Home Assistant and ESPHome

OpenBuilds BLOX can be used with https://esphome.io/ and https://www.home-assistant.io/ as a Home Automation controller


5.4.1 Requirements


5.4.2 Example YAML

Here's a basic example configuration YAML file for a BLOX under ESPHome, that you can use as a baseline configuration to build from

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

# Enable Home Assistant API: Use your own API KEY
api:
  encryption:
    key: "gb7rLDFCs79aFDLm2xhphwcm3ViVhnxnJkMtqF7yGoQ="

esphome:
  name: blox-sample-config # Please change
  friendly_name: BLOX Example # Please change

  # Set DAC output levels on boot
  on_boot:
    priority: -10  # Lower priority ensures that outputs are set after ESPHome is fully initialized
    then:
      - output.set_level:
          id: stepper_current_1
          level: 0.3  # Set Stepper 1's default Current to 30%
      - output.set_level:
          id: stepper_current_2
          level: 0.3  # Set Stepper 2's default Current to 30%

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Blox Example Fallback Hotspot"
    password: "zTRqU4qZtwkd"  # Please change
captive_portal: # Enable Captive Portal on fallback hotspot

ota:
  password: "b99d5b4df91e72f2bff548ca73c57010" # Use your own

logger: # Enable Logs

web_server: # Show local web interface
  port: 80

spi:
  mosi_pin: 35
  clk_pin: 36
  miso_pin: 37

i2c:
  sda: 3
  scl: 4
  scan: true

light: # RGB LEDs
  - platform: neopixelbus
    type: GRB
    variant: WS2811
    pin: 48
    num_leds: 2 # Update count if you add external LEDs
    name: "RGB LEDs"

number:
  - platform: template
    name: "Stepper Motor 1"
    min_value: 0
    max_value: 10000 # Set Max Travel Steps
    step: 1
    set_action:
      then:
        - stepper.set_target:
            id: stepper_motor_1
            target: !lambda 'return x;'

  - platform: template
    name: "Stepper Motor 2"
    min_value: 0
    max_value: 10000 # Set Max Travel Steps
    step: 1
    set_action:
      then:
        - stepper.set_target:
            id: stepper_motor_2
            target: !lambda 'return x;'
  - platform: template
    name: Servo
    min_value: -100
    initial_value: 0
    max_value: 100
    step: 1
    optimistic: true
    set_action:
      then:
        - servo.write:
            id: rc_servo
            level: !lambda 'return x / 100.0;'
  - platform: template
    name: "Current: Stepper Motor 1"
    min_value: 0
    max_value: 3200
    step: 1
    set_action:
      then:
        - lambda: |-
            float millivolt = x / 5.0 / 0.22;
            int dacValue = (int) (millivolt / 3300.0 * 4096);
            id(stepper_current_1).set_level(dacValue / 4096.0);

  - platform: template
    name: "Current: Stepper Motor 2"
    min_value: 0
    max_value: 3200
    step: 1
    set_action:
      then:
        - lambda: |-
            float millivolt = x / 5.0 / 0.22;
            int dacValue = (int) (millivolt / 3300.0 * 4096);
            id(stepper_current_2).set_level(dacValue / 4096.0);

stepper:
  - platform: a4988
    id: stepper_motor_1
    step_pin: 9
    dir_pin: 8
    max_speed: 250 steps/s
    sleep_pin: 10
    acceleration: inf
    deceleration: inf
  - platform: a4988
    id: stepper_motor_2
    step_pin: 13
    dir_pin: 12
    max_speed: 250 steps/s
    sleep_pin: 14
    acceleration: inf
    deceleration: inf

binary_sensor:
  - platform: gpio
    pin:
      number: 39
      inverted: true
    name: "Input: Limit: X"
  - platform: gpio
    pin:
      number: 40
      inverted: true
    name: "Input: Limit: Y"
  - platform: gpio
    pin:
      number: 11
      inverted: true
    name: "Input: Fault: X"
  - platform: gpio
    pin:
      number: 15
      inverted: true
    name: "Input: Fault: Y"

output:
  - platform: ledc
    pin: 47
    id: servo_output
    frequency: 50Hz
  - platform: mcp4725
    id: stepper_current_1
    address: 0x60
  - platform: mcp4725
    id: stepper_current_2
    address: 0x61

switch:
  - platform: gpio
    pin: 41
    name: "Output: Switched Output 1"
  - platform: gpio
    pin: 42
    name: "Output: Switched Output 2"

servo:
  - id: rc_servo
    output: servo_output
    transition_length: 2s
    auto_detach_time: 0.1s