This was an exercise in Github Copilot AI coding. The entire integration was created and coded by Copilot using prompts.
This integration will be made public and archived, so that someone else may fork and expand on this.
A Home Assistant custom integration for controlling Lionel LionChief Bluetooth locomotives.
- Throttle Control: Use a number slider to control train speed (0-100%)
- Direction Control: Switch between forward and reverse
- Sound Effects: Control horn, bell, and announcements
- Lighting: Train lights control
- Volume Controls: Individual volume control for horn, bell, speech, and engine sounds
- Connection Status: Monitor Bluetooth connection status
- Auto-Discovery: Automatically discover locomotives when powered on
- HACS Compatible: Easy installation through HACS
- Throttle: Variable speed control slider from 0-100%
- Master Volume: Overall volume control (0-7)
- Horn Volume: Horn sound volume (0-7)
- Bell Volume: Bell sound volume (0-7)
- Speech Volume: Announcement volume (0-7)
- Engine Volume: Engine sound volume (0-7)
- Lights: Control locomotive lighting (defaults to on)
- Auto Reconnect: Enable/disable automatic reconnection when train becomes available
- Stop: Emergency stop button (sets throttle to 0)
- Forward: Set locomotive direction to forward
- Reverse: Set locomotive direction to reverse
- Horn: Sound the horn
- Bell: Ring the bell
- Disconnect: Disconnect from locomotive
- Announcements: Various conductor announcements
- Random, Ready to Roll, Hey There, Squeaky
- Water and Fire, Fastest Freight, Penna Flyer
- Connection: Shows Bluetooth connection status
- Open HACS in Home Assistant
- Go to "Integrations"
- Click the three dots menu and select "Custom repositories"
- Add
https://github.com/BlackandBlue1908/ha_lionel_controlleras an Integration - Install "Lionel Train Controller"
- Restart Home Assistant
- Copy the
custom_components/lionel_controllerfolder to your Home Assistantcustom_componentsdirectory - Restart Home Assistant
- Power on your Lionel LionChief locomotive near your Home Assistant device
- The integration will automatically detect the train and show a notification
- Go to Settings → Devices & Services to see the discovered train
- Click "Configure" to add it to Home Assistant
- Go to Settings → Devices & Services
- Click "Add Integration"
- Search for "Lionel Train Controller"
- Enter your locomotive's Bluetooth MAC address
- Optionally customize the name and service UUID
- Click Submit
You can find your locomotive's MAC address by:
- Using a Bluetooth scanner app on your phone
- Looking in Home Assistant Developer Tools → States for bluetooth devices
- Using the ESPHome logs if you have the reference implementation
- Using Home Assistant's built-in Bluetooth integration to scan for devices
FC:1F:C3:9F:A5:4A (format: XX:XX:XX:XX:XX:XX)
This integration implements the complete Lionel LionChief Bluetooth protocol based on multiple reverse-engineering efforts:
- Primary Service UUID:
e20a39f4-73f5-4bc4-a12f-17d1ad07a961(LionChief control) - Device Info Service:
0000180a-0000-1000-8000-00805f9b34fb(standard BLE device information) - Write Characteristic:
08590f7e-db05-467e-8757-72f6faeb13d4(LionelCommand) - Notify Characteristic:
08590f7e-db05-467e-8757-72f6faeb14d3(LionelData)
The integration now uses the proper Lionel command format:
- Byte 0: Always
0x00(command prefix) - Byte 1: Command code (e.g.,
0x45for speed,0x46for direction) - Byte 2+: Parameters specific to each command
- Last Byte: Checksum (simplified to
0x00for compatibility)
The integration automatically reads and displays:
- Model number
- Serial number
- Firmware revision
- Hardware revision
- Software revision
- Manufacturer name
This information is displayed in Home Assistant's device registry for better identification.
- Tested with Pennsylvania Flyer locomotive
- Should work with other LionChief Bluetooth locomotives
- Requires Home Assistant 2023.8.0 or later
- Requires Python bleak 0.20.0 or later
The integration includes a custom Lovelace card for a train-themed control interface.
- Go to Settings → Dashboards → Resources (or click the three dots menu → Resources)
- Click Add Resource
- Enter URL:
/lionel_controller/lionel-train-card.js - Select JavaScript Module
- Click Create
- Edit your dashboard
- Click Add Card
- Search for "Lionel Train Controller" or scroll to find it
- Configure the card:
- Entity: Select your train's throttle entity (e.g.,
number.lc_1234_throttle) - Name: Optional display name for the card
- Entity: Select your train's throttle entity (e.g.,
- Large throttle slider for easy speed control
- Direction buttons (Forward/Reverse)
- Quick access buttons for Horn, Bell, Lights
- Emergency Stop button
- Connection status indicator
- Disconnect button
- Ensure locomotive is powered on and in Bluetooth pairing mode
- Check that locomotive is within Bluetooth range (typically 10-30 feet)
- Verify MAC address is correct
- Try restarting Home Assistant if connection issues persist
The integration uses bleak-retry-connector for enhanced connection stability:
- Automatic Retries: Failed connections are automatically retried up to 3 times
- Exponential Backoff: Increasing delays between retry attempts to avoid overwhelming the device
- Service Caching: Bluetooth service information is cached for faster subsequent connections
- Better Error Handling: More informative error messages for connection troubleshooting
Different locomotive models may use different service UUIDs. If the default doesn't work:
- Use a Bluetooth scanner to find your locomotive's service UUID
- Reconfigure the integration with the correct UUID
- Protocol reverse engineering by Property404
- ESPHome reference implementation by @iamjoshk
- Additional protocol details from pedasmith's BluetoothDeviceController