Skip to content

Commit

Permalink
Merge branch 'release/0.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Nov 8, 2024
2 parents 2d0749a + 60979ef commit 03f56c0
Show file tree
Hide file tree
Showing 6 changed files with 5,623 additions and 5,691 deletions.
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.2)
activesupport (8.0.0)
base64
benchmark (>= 0.3)
bigdecimal
Expand All @@ -13,11 +13,12 @@ GEM
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
benchmark (0.3.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
Expand Down Expand Up @@ -70,7 +71,7 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.34.0)
rubocop-ast (1.34.1)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
Expand All @@ -89,6 +90,7 @@ GEM
tzinfo-data (1.2024.2)
tzinfo (>= 1.0.0)
unicode-display_width (2.6.0)
uri (1.0.1)
vcr (6.3.1)
base64
webmock (3.24.0)
Expand Down
60 changes: 21 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,31 @@ docker exec -it solectrus-redis-1 redis-cli FLUSHALL

Check the `.env` variable `INSTALLATION_DATE`. This must be set to the day your PV system was installed.

### SENEC: Dealing with missing wallbox measurements

The CSV data from mein-senec.de is not complete, there are no measurements for the wallbox. To get around this, wallbox charges are **estimated** using the following formula:

```
wallbox_charge_power = inverter_power (Stromerzeugung)
+ grid_power_plus (Netzbezug)
+ bat_power_minus (Akkuentnahme)
- grid_power_minus (Netzeinspeisung)
- house_power (Stromverbrauch)
- bat_power_plus (Akkubeladung)
```

Please note that this method appears to be ineffective for processing CSV files that were created from July 2022 onwards. This is because wallbox charges are now being included in the overall house consumption since that time. Therefore, it seems that there is currently no way to import wallbox measurements.

The [senec-collector](https://github.com/solectrus/senec-collector) does not have this problem, as it obtains the wallbox measurements directly.

### Configuration

The following environment variables can be used to configure the importer:

| Variable | Description | Default |
| --------------------------------------- | ----------------------------------------------- | ---------------------------- |
| `INFLUX_HOST` | Hostname of InfluxDB | |
| `INFLUX_SCHEMA` | Schema (http/https) of InfluxDB | `http` |
| `INFLUX_PORT` | Port of InfluxDB | `8086` |
| `INFLUX_TOKEN_WRITE` or `INFLUX_TOKEN` | Token for InfluxDB (requires write permissions) | |
| `INFLUX_ORG` | Organization for InfluxDB | |
| `INFLUX_BUCKET` | Bucket for InfluxDB | |
| `INFLUX_OPEN_TIMEOUT` | Timeout for InfluxDB connection (in seconds) | `30` |
| `INFLUX_READ_TIMEOUT` | Timeout for InfluxDB read (in seconds) | `30` |
| `INFLUX_WRITE_TIMEOUT` | Timeout for InfluxDB write (in seconds) | `30` |
| `INFLUX_SENSOR_INVERTER_POWER` | Measurement/field for inverter power | `SENEC:inverter_power` |
| `INFLUX_SENSOR_HOUSE_POWER` | Measurement/field for house power | `SENEC:house_power` |
| `INFLUX_SENSOR_GRID_IMPORT_POWER` | Measurement/field for grid import power | `SENEC:grid_power_plus` |
| `INFLUX_SENSOR_GRID_EXPORT_POWER` | Measurement/field for grid export power | `SENEC:grid_power_minus` |
| `INFLUX_SENSOR_BATTERY_CHARGE_POWER` | Measurement/field for battery charge power | `SENEC:bat_power_plus` |
| `INFLUX_SENSOR_BATTERY_DISCHARGE_POWER` | Measurement/field for battery discharge power | `SENEC:bat_power_minus` |
| `INFLUX_SENSOR_WALLBOX_POWER` | Measurement/field for wallbox power | `SENEC:wallbox_charge_power` |
| `SENEC_IGNORE` | Optionally ignore some fields (comma-separated) | |
| `IMPORT_FOLDER` | Folder where CSV files are located | `/data` |
| `IMPORT_PAUSE` | Pause after each imported file (in seconds) | `0` |
| `TZ` | Time zone to use when parsing times | `Europe/Berlin` |
| Variable | Description | Default |
| --------------------------------------- | ----------------------------------------------- | ------------------------ |
| `INFLUX_HOST` | Hostname of InfluxDB | |
| `INFLUX_SCHEMA` | Schema (http/https) of InfluxDB | `http` |
| `INFLUX_PORT` | Port of InfluxDB | `8086` |
| `INFLUX_TOKEN_WRITE` or `INFLUX_TOKEN` | Token for InfluxDB (requires write permissions) | |
| `INFLUX_ORG` | Organization for InfluxDB | |
| `INFLUX_BUCKET` | Bucket for InfluxDB | |
| `INFLUX_OPEN_TIMEOUT` | Timeout for InfluxDB connection (in seconds) | `30` |
| `INFLUX_READ_TIMEOUT` | Timeout for InfluxDB read (in seconds) | `30` |
| `INFLUX_WRITE_TIMEOUT` | Timeout for InfluxDB write (in seconds) | `30` |
| `INFLUX_SENSOR_INVERTER_POWER` | Measurement/field for inverter power | `SENEC:inverter_power` |
| `INFLUX_SENSOR_HOUSE_POWER` | Measurement/field for house power | `SENEC:house_power` |
| `INFLUX_SENSOR_GRID_IMPORT_POWER` | Measurement/field for grid import power | `SENEC:grid_power_plus` |
| `INFLUX_SENSOR_GRID_EXPORT_POWER` | Measurement/field for grid export power | `SENEC:grid_power_minus` |
| `INFLUX_SENSOR_BATTERY_CHARGE_POWER` | Measurement/field for battery charge power | `SENEC:bat_power_plus` |
| `INFLUX_SENSOR_BATTERY_DISCHARGE_POWER` | Measurement/field for battery discharge power | `SENEC:bat_power_minus` |
| `SENEC_IGNORE` | Optionally ignore some fields (comma-separated) | |
| `IMPORT_FOLDER` | Folder where CSV files are located | `/data` |
| `IMPORT_PAUSE` | Pause after each imported file (in seconds) | `0` |
| `TZ` | Time zone to use when parsing times | `Europe/Berlin` |

## License

Expand Down
10 changes: 0 additions & 10 deletions app/adapters/senec_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def data
battery_discharging_power
grid_import_power
grid_export_power
wallbox_power
].filter_map do |sensor_name|
next if config.senec_ignore.include?(config.field(sensor_name))

Expand Down Expand Up @@ -76,15 +75,6 @@ def grid_export_power
parse_kw(row, 'Netzeinspeisung [kW]', 'Netzeinspeisung [kWh]')
end

# Estimate wallbox power based on the other values
def wallbox_power
incoming = inverter_power + grid_import_power + battery_discharging_power
outgoing = grid_export_power + house_power + battery_charging_power
diff = incoming - outgoing

diff < 50 ? 0 : diff
end

# KiloWatt
def parse_kw(row, *)
(cell(row, *).sub(',', '.').to_f * 1_000).round
Expand Down
3 changes: 0 additions & 3 deletions app/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
grid_export_power
battery_charging_power
battery_discharging_power
wallbox_power
].freeze

Config =
Expand All @@ -30,7 +29,6 @@
:influx_sensor_grid_export_power,
:influx_sensor_battery_charging_power,
:influx_sensor_battery_discharging_power,
:influx_sensor_wallbox_power,
### SENEC only: Optionally ignore some fields
:senec_ignore,
###
Expand Down Expand Up @@ -95,7 +93,6 @@ def self.sensors_from_env
influx_sensor_battery_discharging_power: ENV.fetch(
'INFLUX_SENSOR_BATTERY_DISCHARGING_POWER', 'SENEC:bat_power_minus',
),
influx_sensor_wallbox_power: ENV.fetch('INFLUX_SENSOR_WALLBOX_POWER', 'SENEC:wallbox_charge_power'),
senec_ignore: ENV.fetch('SENEC_IGNORE', '').split(',').map(&:to_sym),
}
end
Expand Down
95 changes: 28 additions & 67 deletions spec/adapters/senec_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,76 +50,37 @@
describe '#to_a' do
subject(:to_a) { record.to_a }

context 'without wallbox calculation' do
let(:fields) do
[
'14.03.2022 00:13:13',
'0,197754',
'0',
'0,199219',
'0',
'0',
'0',
'0',
'0',
]
end

let(:expected_fields) do
{
inverter_power: 0,
house_power: 199,
bat_power_plus: 0,
bat_power_minus: 0,
grid_power_plus: 198,
grid_power_minus: 0,
wallbox_charge_power: 0,
}
end

it do
expect(to_a).to eq([
time: 1_647_213_193,
name: 'SENEC',
fields: expected_fields,
])
end
let(:fields) do
[
'14.03.2022 00:13:13',
'0,197754',
'0',
'0,199219',
'0',
'0',
'0',
'0',
'0',
]
end

context 'with wallbox calculation' do
let(:fields) do
[
'21.03.2022 13:00:46',
'0,00146',
'0,840947',
'0,227756',
'0',
'0',
'7,311566',
'0',
'0',
]
end

let(:expected_fields) do
{
inverter_power: 7312,
house_power: 228,
bat_power_plus: 0,
bat_power_minus: 0,
grid_power_plus: 1,
grid_power_minus: 841,
wallbox_charge_power: 6244,
}
end

it {
expect(to_a).to eq([
time: 1_647_864_046,
name: 'SENEC',
fields: expected_fields,
])
let(:expected_fields) do
{
inverter_power: 0,
house_power: 199,
bat_power_plus: 0,
bat_power_minus: 0,
grid_power_plus: 198,
grid_power_minus: 0,
}
end

it do
expect(to_a).to eq([
time: 1_647_213_193,
name: 'SENEC',
fields: expected_fields,
])
end
end
end
Loading

0 comments on commit 03f56c0

Please sign in to comment.