Skip to content

Commit

Permalink
fix energie calulation, add Home-Assistant integration
Browse files Browse the repository at this point in the history
  • Loading branch information
raibisch committed Mar 11, 2024
1 parent 50f751b commit 39c113e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 54 deletions.
78 changes: 72 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- EVENT-LOG: Serial debug logging
- UPDATE: over-the-air (Wifi) Software update
- HISTORY: Set and Store total kW/h sum in internal FLASH
- INFO: Version, Build, Temp(ESP-intern), IP, Timeout, Charge-Cnt, RSSI


Monitor and control your ABL-Wallbox with an WEB-Application and integrate it (optional) in your homeautomation software with simple REST-Interface (see example for DOMOTICZ below) for less than 10€.

Expand All @@ -34,7 +36,8 @@ If the Box has a current-sensor it was automatic detected and the value is calcu

## Manual Charge-Current-Setting

The user interface was designed very simply to enable manual switching between two charging currents (possible application: reduced charging current for operation with a PV system).
The user interface was designed very simply to enable manual switching between two charging currents (possible application: ABL-Wallbox-kWh Gesamt
ABL-Wallbox-kWh Gesamtreduced charging current for operation with a PV system).
The two values could be individual defined in the 'config-data' page (for external setting use the WEB-API)

## External Charge-Current-Setting and reading values (WEB-API)
Expand All @@ -55,10 +58,64 @@ decoded:

`http:<your-ip>/fetch?imax=xx` (xx= 6,8,10,12,14,16)

### Domoticz Integration

## Home-Assistent Integration
...see above 'WEB-API' for other external integration (e.g. other homeautomation software)

![HOMEASSI](/pict/homeassi.png)

add to **configuration.yaml**:

```YAML
rest:
scan_interval: 20
resource: http://192.168.2.108/fetch
sensor:
- name: "ABL-Wallbox Imax"
unique_id : "sensor_abl_imax"
icon: "mdi:ev-station"
value_template: '{{value.split(",")[0]}}'
unit_of_measurement: "A"
device_class: current

- name: "ABL-Wallbox kw"
unique_id : "sensor_abl_kw"
icon: "mdi:ev-station"
value_template: '{{value.split(",")[1]}}'
unit_of_measurement: "kW"
device_class: power

- name: "ABL-Wallbox-Status"
unique_id : "sensor_abl_status"
icon: "mdi:ev-station"
value_template: '{{value.split(",")[2]}}'

- name: "ABL-Wallbox-kWh akt."
unique_id : "sensor_abl_kwhakt"
icon: "mdi:ev-station"
value_template: '{{float(value.split(",")[3])/1000}}'
unit_of_measurement: kWh
device_class: energy

- name: "ABL-Wallbox-kWh Gesamt"
unique_id : "sensor_abl_kwhsum"
icon: "mdi:ev-station"
value_template: '{{float(value.split(",")[4])/1000}}'
unit_of_measurement: kWh
device_class: energy
state_class: total

rest_command:
abl_set_imax_6a:
url: "http://192.168.2.108/fetch?imax=6"
method: GET
abl_set_imax_16a:
url: "http://192.168.2.108/fetch?imax=16"
method: GET
```
## Domoticz Integration
...see above 'WEB-API' for other external integration (e.g. other homeautomation software)
![Domoticz](/pict/domoticz.png)
#### Domoticz Configuration
Expand Down Expand Up @@ -188,7 +245,16 @@ V 1.2 index-page redesign, fixes for kW/h-calculation, fetch kW/h sum, Info-page

V1.2.2 Bugfix for 'virtual kW/h-calculation' and Modbus timeouts

## todo or options
- MQTT-client (does someone need this ?)
## Ideas:
- MQTT-client
- get actual Power [kW] and Work [kW/h] from external meter
- add connection to Tibber API
- get actual current from current sensor and calulate Power and Work
- store more history data (last charging data)
- get history-time from ntp (could work only in 'STA' network mode)


## other extentions:
- add Ethernet port to esp32
https://www.roboter-bausatz.de/p/wt32-eth01-esp32-modul-mit-ethernet-bluetooth-wifi
https://mischianti.org/esp32-ethernet-w5500-with-plain-http-and-ssl-https/

Binary file added icons/wallbox128_breit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pict/homeassi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 36 additions & 48 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ bool testTimeount()
#ifdef DEBUG_WITHOUT_ABL
#pragma message("Info : DEBUG_WITHOUT_ABL=1")
//ABL_rx_Ipwm = 16;
ABL_rx_Ipwm = 50;
ABL_rx_Ipwm = 10;
debug_printf("ABL_rx_timeoutcount:%d\r\n", ABL_rx_timeoutcount);
if (ABL_rx_timeoutcount < 2)
{
Expand All @@ -378,27 +378,27 @@ bool testTimeount()
ABL_rx_status = "?";
}
else
if (ABL_rx_timeoutcount < 5)
if (ABL_rx_timeoutcount < 8)
{
ABL_rx_status = ABL_STATUS_STRING[ABL_C2];
}
else
if (ABL_rx_timeoutcount < 6)
if (ABL_rx_timeoutcount < 9)
{
ABL_rx_status = ABL_STATUS_STRING[ABL_B2];
}
else
if (ABL_rx_timeoutcount < 7)
if (ABL_rx_timeoutcount < 10)
{
ABL_rx_status = "?";
}
else
if(ABL_rx_timeoutcount < 8)
if(ABL_rx_timeoutcount < 11)
{
ABL_rx_status = ABL_STATUS_STRING[ABL_A1];
}
else
if(ABL_rx_timeoutcount < 9)
if(ABL_rx_timeoutcount < 12)
{
ABL_rx_status = "F1"; // simulate Error Message
}
Expand Down Expand Up @@ -443,6 +443,7 @@ bool set_Wh_Sum(unsigned long whs)

bool saveHistory()
{
ABL_Wh_Sum_old = ABL_Wh_Sum_akt;
debug_printf("ABL_Wh_Sum_akt:%d\r\n",ABL_Wh_Sum_akt)
hist.putULong64("whsum",ABL_Wh_Sum_akt);
hist.putUInt("restart", SYS_RestartCount);
Expand All @@ -459,59 +460,44 @@ static double Wh = 0;
/////////////////////////////////////////////////////////
void calculate_kWh()
{

if (ABL_rx_status.startsWith("?")) // no calulation at unvalid data
{
return;
}

if (ABL_rx_status.startsWith("no")) // no calulation at timeout
{
return;
}

if (ABL_rx_status_old != ABL_rx_status) // Status is changing
{
// Handle old status
if (ABL_rx_status_old.startsWith("C") && (ABL_rx_status.startsWith("B")))

// end charging
if (ABL_rx_status_old.startsWith("C"))
{
saveHistory();
hist.putInt("charge",SYS_ChargeCount++);
}
else
if (ABL_rx_status_old.startsWith("no"))
{
hist.putInt("timeout",SYS_TimeoutCount++);
}
else
if (ABL_rx_status_old.startsWith("A"))
{
ABL_rx_Isum = 0;
ABL_rx_kW = 0;
ABL_rx_Wh = 0;
ABL_sChargeTime = " ";
Wh = 0;
}
else
if (ABL_rx_status_old.startsWith("B")) // Status Charging End

// start charging
if (ABL_rx_status.startsWith("C"))
{
ABL_rx_kW = 0;
ABL_rx_Isum = 0;
Wh = 0;
rtc.setTime(0);
saveHistory();
rtc.setTime(1);
ABL_PollTime_old = 1;
ABL_rx_Isum = 0;
ABL_rx_kW = 0;
}

// Handle new Status

if (ABL_rx_status.startsWith("A"))
{
saveHistory();
ABL_rx_Isum = 0;
ABL_rx_kW = 0;
ABL_rx_Wh = 0;
ABL_sChargeTime = " ";
Wh = 0;
}
else
if (ABL_rx_status.startsWith("B"))
{
ABL_rx_kW = 0;
ABL_rx_Isum = 0;
}


saveHistory();
// JG 20.1.2024 evt. Problem bei status '?'
// Wh = 0;
// rtc.setTime(0);

ABL_rx_status_old = ABL_rx_status;
} // End Status is changing

Expand Down Expand Up @@ -552,7 +538,7 @@ void calculate_kWh()

ABL_rx_Wh = round(Wh);
debug_printf("W/h:%d\r\n", ABL_rx_Wh);
ABL_Wh_Sum_akt = ABL_Wh_Sum_akt + ABL_rx_Wh;
ABL_Wh_Sum_akt = ABL_Wh_Sum_old + ABL_rx_Wh;

}
}
Expand Down Expand Up @@ -1306,17 +1292,19 @@ void loop()
s = ABL_sChargeTime + " Wh-akt:" + ABL_rx_Wh + " next Tx in:" + log_timer + "sec";
}
else
{s = "Next Tx in :" + String(log_timer) + "sec";}
{
s = "Next Tx in :" + String(log_timer) + "sec";
}
AsyncWebLog.println(s);

// Test if wifi is lost from router
if ((varStore.varWIFI_s_Mode == "STA") && (WiFi.status() != WL_CONNECTED))
{
debug_println("Reconnecting to WiFi...");
saveHistory();
delay(100);
if (!WiFi.reconnect())
{
saveHistory();
hist.putInt("restart",SYS_RestartCount++);
delay(200);
ESP.restart();
Expand Down

0 comments on commit 39c113e

Please sign in to comment.