Cowboy Home Assistant Integration

Welcome to the documentation for the Cowboy Home Assistant Integration. This integration allows you to connect your Cowboy electric bike with Home Assistant, enabling smart home automation and monitoring capabilities.

image

Features

The integration provides several sensors and capabilities:

Installation

  1. Ensure you have HACS installed
  2. Go to HACS > Integrations
  3. Click the “+” button and search for “Cowboy”
  4. Click Install
  5. Restart Home Assistant

Manual Installation

  1. Copy the custom_components/cowboy directory to your Home Assistant’s custom_components folder:
cd ~/.homeassistant
git clone https://github.com/elsbrock/cowboy-ha.git
cp -r cowboy-ha/custom_components/cowboy custom_components/
  1. Restart Home Assistant

Configuration

  1. Go to Settings > Devices & Services
  2. Click “Add Integration”
  3. Search for “Cowboy”
  4. Enter your credentials:
    • Username: Your Cowboy account email
    • Password: Your Cowboy account password

Note: The account password is stored securely to renew the session. It is not used for other purposes.

Available Entities

Sensors

Entity Description Unit
sensor.cowboy_total_distance Total distance traveled km
sensor.cowboy_remaining_range Estimated remaining range km
sensor.cowboy_battery_level Current battery level %
sensor.cowboy_battery_health Battery health status %
binary_sensor.cowboy_battery_docked Battery docking status -
sensor.cowboy_total_duration Total usage time seconds
sensor.cowboy_total_co2_saved Total CO2 saved grams
sensor.cowboy_pcb_battery_state_of_charge PCB battery state of charge %
binary_sensor.cowboy_stolen Stolen status -
binary_sensor.cowboy_crashed Crashed status -
binary_sensor.cowboy_battery_inserted Battery inserted status -
binary_sensor.cowboy_update_available Update available status -

Device Tracker

The integration creates a device tracker entity that shows your bike’s last known location:

Automations

Here are some example automations you can create:

# Get notified when battery is low
automation:
  - alias: "Notify on Low Battery"
    trigger:
      platform: numeric_state
      entity_id: sensor.cowboy_battery_level
      below: 20
    action:
      service: notify.mobile_app
      data:
        message: "Cowboy bike battery is low (%)"

# Log when bike leaves home
  - alias: "Bike Left Home"
    trigger:
      platform: state
      entity_id: device_tracker.cowboy_bike
      from: "home"
    action:
      service: notify.mobile_app
      data:
        message: "Bike has left home"

# Notify when an update is available
  - alias: "Notify on Update Available"
    trigger:
      platform: state
      entity_id: binary_sensor.cowboy_update_available
      to: "on"
    action:
      service: notify.mobile_app
      data:
        message: "A software update is available for your Cowboy bike."

Development

Prerequisites

  1. Install Nix
  2. Enable Flakes

Setting Up Development Environment

  1. Clone the repository:
git clone https://github.com/elsbrock/cowboy-ha.git
cd cowboy-ha
  1. Enter the development environment:
nix develop
  1. Start Home Assistant:
hass -c config

Running Tests

Run the test suite using pytest:

pytest tests/ -v

Troubleshooting

Common Issues

  1. Authentication Failed
    • Verify your Cowboy account credentials
    • Ensure your account is active
    • Check internet connectivity
  2. No Data Updates
    • The integration polls every minute
    • Check if your bike is powered on
    • Verify internet connectivity

Debug Logging

To enable debug logs, go to Settings > Integrations > Cowboy > Options > Debug Logging.

You can alternatively add this to your configuration.yaml:

logger:
  default: info
  logs:
    custom_components.cowboy: debug

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This integration is not officially affiliated with Cowboy. Use at your own risk.