> For the complete documentation index, see [llms.txt](https://sryvkver.gitbook.io/cobi.bike/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sryvkver.gitbook.io/cobi.bike/namespaces/battery-two/state.md).

# State

Represents the external battery condition (Hub or E-bike battery respectively). I.e. charging level in % and status.

{% tabs %}
{% tab title="Typescript" %}

```typescript
const onBatteryStateChange = (value: BatteryCondition, timestamp?: Date) => {
    console.log(value, timestamp);
};

COBI.batteryTwo.state.read(onBatteryStateChange); // Instantly get the current value
COBI.batteryTwo.state.subscribe(onBatteryStateChange);
COBI.batteryTwo.state.unsubscribe(onBatteryStateChange);
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const onBatteryStateChange = (value, timestamp) => {
    console.log(value, timestamp);
};

COBI.batteryTwo.state.read(onBatteryStateChange); // Instantly get the current value
COBI.batteryTwo.state.subscribe(onBatteryStateChange);
COBI.batteryTwo.state.unsubscribe(onBatteryStateChange);
```

{% endtab %}
{% endtabs %}

{% content-ref url="/pages/XLnX8RA4PTcpyWkZt8hI" %}
[BatteryCondition](/cobi.bike/entities/batterycondition.md)
{% endcontent-ref %}

<details>

<summary>Example Response</summary>

```json
{
    "batteryLevel": 0.0,
    "state": "CHARGING"
}
```

</details>
