This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
docs:blox:firmware-esphome [2024/08/15 13:53] admin created |
docs:blox:firmware-esphome [2024/08/19 17:39] (current) admin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 5.4 Using BLOX with Home Assistant and ESPHome ====== | ||
| + | OpenBuilds BLOX can be used with [[https:// | ||
| + | {{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 5.4.1 Requirements ===== | ||
| + | |||
| + | * A working Home Assistant installation with the ESPHome Add-On | ||
| + | * Working knowledge of ESPHome | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 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: " | ||
| + | |||
| + | esphome: | ||
| + | name: blox-sample-config # Please change | ||
| + | friendly_name: | ||
| + | |||
| + | # 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: " | ||
| + | captive_portal: | ||
| + | |||
| + | ota: | ||
| + | password: " | ||
| + | |||
| + | 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: " | ||
| + | min_value: 0 | ||
| + | max_value: 10000 # Set Max Travel Steps | ||
| + | step: 1 | ||
| + | set_action: | ||
| + | then: | ||
| + | - stepper.set_target: | ||
| + | id: stepper_motor_1 | ||
| + | target: !lambda ' | ||
| + | |||
| + | - platform: template | ||
| + | name: " | ||
| + | min_value: 0 | ||
| + | max_value: 10000 # Set Max Travel Steps | ||
| + | step: 1 | ||
| + | set_action: | ||
| + | then: | ||
| + | - stepper.set_target: | ||
| + | id: stepper_motor_2 | ||
| + | target: !lambda ' | ||
| + | - platform: template | ||
| + | name: Servo | ||
| + | min_value: -100 | ||
| + | initial_value: | ||
| + | max_value: 100 | ||
| + | step: 1 | ||
| + | optimistic: true | ||
| + | set_action: | ||
| + | then: | ||
| + | - servo.write: | ||
| + | id: rc_servo | ||
| + | level: !lambda ' | ||
| + | - platform: template | ||
| + | name: " | ||
| + | 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: " | ||
| + | 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: | ||
| + | deceleration: | ||
| + | - platform: a4988 | ||
| + | id: stepper_motor_2 | ||
| + | step_pin: 13 | ||
| + | dir_pin: 12 | ||
| + | max_speed: 250 steps/s | ||
| + | sleep_pin: 14 | ||
| + | acceleration: | ||
| + | deceleration: | ||
| + | |||
| + | binary_sensor: | ||
| + | - platform: gpio | ||
| + | pin: | ||
| + | number: 39 | ||
| + | inverted: true | ||
| + | name: " | ||
| + | - platform: gpio | ||
| + | pin: | ||
| + | number: 40 | ||
| + | inverted: true | ||
| + | name: " | ||
| + | - platform: gpio | ||
| + | pin: | ||
| + | number: 11 | ||
| + | inverted: true | ||
| + | name: " | ||
| + | - platform: gpio | ||
| + | pin: | ||
| + | number: 15 | ||
| + | inverted: true | ||
| + | name: " | ||
| + | |||
| + | 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: " | ||
| + | - platform: gpio | ||
| + | pin: 42 | ||
| + | name: " | ||
| + | |||
| + | servo: | ||
| + | - id: rc_servo | ||
| + | output: servo_output | ||
| + | transition_length: | ||
| + | auto_detach_time: | ||
| + | |||
| + | </ | ||
| + | |||
| + | ---- | ||
| - | {{: | ||
| - | Compiling | ||