# 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="../../entities/batterycondition" %}
[batterycondition](https://sryvkver.gitbook.io/cobi.bike/entities/batterycondition)
{% endcontent-ref %}

<details>

<summary>Example Response</summary>

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

</details>
