Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for battery temperature #27

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 51 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# VictronSmartShunt-ESPHOME
ESPHome component to monitor a Victron BMV and SmartShunt via ve.direct / UART TTL

ESPHome component to monitor a Victron BMV and SmartShunt via ve.direct / UART TTL.

## Supported devices

All BMV and SmartShunt providing a ve.direct port.

## Tested devices

* Victron SmartShunt 500A/50mV

* Victron SmartShunt 500A/50mV

## Requirements

Expand Down Expand Up @@ -38,18 +38,19 @@ If you are unsure about to pin order please measure the voltage between GND and

### JST-PH jack

| Pin | Purpose | ESP pin |
| :-----: | :----------- | :------------- |
| **1** | **GND** | GND |
| 2 | RX | |
| **3** | **TX** | D7 (RX) |
| 4 | 5V | |
| Pin | Purpose | ESP pin |
| :---: | :------ | :------ |
| **1** | **GND** | GND |
| 2 | RX | |
| **3** | **TX** | D7 (RX) |
| 4 | 5V | |

## Installation

You can install this component with [ESPHome external components feature](https://esphome.io/components/external_components.html) like this:
You can install this component with [ESPHome external components feature](https://esphome.io/components/external_components.html).

Example:

```yaml
external_components:
- source: github://KinDR007/VictronSmartShunt-ESPHOME@main
Expand All @@ -76,58 +77,62 @@ sensor:

The `uart_id` is optional.

All sensors are optional.
All sensors are optional (and go under the `sensor` section).

```yaml
- platform: victron_smart_shunt
battery_voltage:
name: "Battery Voltage"
name: "Battery Voltage"
id: bv

battery_current:
name: "Battery Current"
name: "Battery Current"
id: bc

battery_temperature:
name: "Battery Temperature"
id: bt

fw_version:
name: "fw"
name: "fw"
id: fw

pid:
name: "pid"
name: "pid"
id: pid

instantaneous_power:
name: "instantaneous power"
id: instantaneous_power
name: "instantaneous power"
id: instantaneous_power

time_to_go:
name: "time to go"
name: "time to go"
id: time_to_go

consumed_amp_hours:
name: "consumed amp hours"
id: consumed_amp_hours
id: consumed_amp_hours
unit_of_measurement: Ah

min_battery_voltage:
name: "Min battery voltage"
id: min_battery_voltage
id: min_battery_voltage

max_battery_voltage:
max_battery_voltage:
name: "Max battery voltage"
id: max_battery_voltage
id: max_battery_voltage

amount_of_charged:
name: "Amount of charged"
id: amount_of_charged
id: amount_of_charged
filters:
- multiply: 0.001
unit_of_measurement: kWh

bmv_alarm:
name: "BMV alarm"
id: bmv_alarm

bmv_pid:
name: "bmv - pid"
id: bmv_pid
Expand All @@ -138,7 +143,7 @@ All sensors are optional.

deepest_discharge:
name: "Depth of the deepest discharge"
id: deepest_discharge
id: deepest_discharge
unit_of_measurement: Ah

last_discharge:
Expand All @@ -148,47 +153,49 @@ All sensors are optional.

discharged_energy:
name: "Amount of discharged energy"
id: discharged_energy
id: discharged_energy
filters:
- multiply: 0.001
unit_of_measurement: kWh

state_of_charge:
id: state_of_charge
name: "SoC"
name: "SoC"
```

The available numeric sensors are:
- `instanteneous_power`
- `time_to_go`
- `state_of_charge`
- `consumed_amp_hours`
- `min_battery_voltage`
- `max_battery_voltage`

- `amount_of_charged`
- `last_full_charge`
- `battery_temperature`
- `consumed_amp_hours`
- `deepest_discharge`
- `last_discharge`
- `discharged_energy`
- `number_of_full_dis`
- `number_of_charge_cycles`
- `discharged_energy`

- `instanteneous_power`
- `last_discharge`
- `last_full_charge`
- `max_battery_voltage`
- `min_battery_voltage`
- `number_of_charge_cycles`
- `number_of_full_dis`
- `state_of_charge`
- `time_to_go`

The available text sensors are:

- `alarm_reason_text`
- `bmv_alarm_text`
- `bmv_text`
- `charger_text`
- `error_text`
- `alarm_reason_text`
- `tracker_text`
- `fw_version`
- `pid`
- `tracker_text`



Full example in `smartshunt.yaml`
See [`full example`](./esp8266-example-advanced.yaml).

`Big thanks for help to ssieb`

```
#victron #esphome #smartshunt #bmv #ve.direct
#victron #esphome #smartshunt #bmv #ve.direct
```
18 changes: 15 additions & 3 deletions components/victron_smart_shunt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_EMPTY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
ICON_CURRENT_AC,
ICON_EMPTY,
ICON_FLASH,
ICON_PERCENT,
ICON_POWER,
ICON_TIMELAPSE,
STATE_CLASS_MEASUREMENT,
UNIT_AMPERE,
UNIT_CELSIUS,
UNIT_EMPTY,
UNIT_MINUTE,
UNIT_PERCENT,
Expand All @@ -41,8 +44,6 @@
CONF_NUMBER_OF_FULL_DIS = "number_of_full_dis"
CONF_NUMBER_OF_CHARGE_CYCLES = "number_of_charge_cycles"
CONF_DISCHARGED_ENERGY = "discharged_energy"


CONF_MAX_POWER_YESTERDAY = "max_power_yesterday"
CONF_MAX_POWER_TODAY = "max_power_today"
CONF_YIELD_TOTAL = "yield_total"
Expand All @@ -51,12 +52,12 @@
CONF_PANEL_VOLTAGE = "panel_voltage"
CONF_PANEL_POWER = "panel_power"
CONF_BATTERY_CURRENT = "battery_current"
CONF_BATTERY_TEMPERATURE = "battery_temperature"
CONF_DAY_NUMBER = "day_number"
CONF_CHARGER_STATUS = "charger_status"
CONF_ERROR_CODE = "error_code"
CONF_TRACKER_OPERATION = "tracker_operation"
CONF_LOAD_CURRENT = "load_current"

CONF_CHARGER_TEXT = "charger_text"
CONF_ERROR_TEXT = "error_text"
CONF_ALARM_REASON_TEXT = "alarm_reason_text"
Expand Down Expand Up @@ -123,6 +124,13 @@
accuracy_decimals=3,
device_class=DEVICE_CLASS_CURRENT,
),
cv.Optional(CONF_BATTERY_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
icon=ICON_EMPTY,
accuracy_decimals=0,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_DAY_NUMBER): sensor.sensor_schema(
unit_of_measurement=UNIT_EMPTY,
icon=ICON_EMPTY,
Expand Down Expand Up @@ -298,6 +306,10 @@ def to_code(config):
sens = yield sensor.new_sensor(config[CONF_BATTERY_CURRENT])
cg.add(var.set_battery_current_sensor(sens))

if CONF_BATTERY_TEMPERATURE in config:
sens = yield sensor.new_sensor(config[CONF_BATTERY_TEMPERATURE])
cg.add(var.set_battery_temperature_sensor(sens))

if CONF_LOAD_CURRENT in config:
sens = yield sensor.new_sensor(config[CONF_LOAD_CURRENT])
cg.add(var.set_load_current_sensor(sens))
Expand Down
6 changes: 6 additions & 0 deletions components/victron_smart_shunt/victron_smart_shunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ void VictronSmartShuntComponent::handle_value_() {
} else if (label_ == "I") {
if (battery_current_sensor_ != nullptr)
battery_current_sensor_->publish_state(atoi(value_.c_str()) / 1000.0); // NOLINT(cert-err34-c)
} else if (label_ == "T") {
if (value_ == "---") {
battery_temperature_sensor_->publish_state(NAN);
} else {
battery_temperature_sensor_->publish_state(atoi(value_.c_str())); // NOLINT(cert-err34-c)
}
} else if (label_ == "IL") {
if (load_current_sensor_ != nullptr)
load_current_sensor_->publish_state(atoi(value_.c_str()) / 1000.0); // NOLINT(cert-err34-c)
Expand Down
4 changes: 4 additions & 0 deletions components/victron_smart_shunt/victron_smart_shunt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class VictronSmartShuntComponent : public uart::UARTDevice, public Component {
void set_battery_current_sensor(sensor::Sensor *battery_current_sensor) {
battery_current_sensor_ = battery_current_sensor;
} // MPPT + SS
void set_battery_temperature_sensor(sensor::Sensor *battery_temperature_sensor) {
battery_temperature_sensor_ = battery_temperature_sensor;
}
void set_load_current_sensor(sensor::Sensor *load_current_sensor) { load_current_sensor_ = load_current_sensor; }
void set_day_number_sensor(sensor::Sensor *day_number_sensor) { day_number_sensor_ = day_number_sensor; }
void set_charger_status_sensor(sensor::Sensor *charger_status_sensor) {
Expand Down Expand Up @@ -112,6 +115,7 @@ class VictronSmartShuntComponent : public uart::UARTDevice, public Component {
sensor::Sensor *panel_power_sensor_{nullptr};
sensor::Sensor *battery_voltage_sensor_{nullptr};
sensor::Sensor *battery_current_sensor_{nullptr};
sensor::Sensor *battery_temperature_sensor_{nullptr};
sensor::Sensor *load_current_sensor_{nullptr};
sensor::Sensor *day_number_sensor_{nullptr};
sensor::Sensor *charger_status_sensor_{nullptr};
Expand Down
4 changes: 4 additions & 0 deletions esp8266-example-advanced.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ sensor:
id: bc
accuracy_decimals: ${accuracy}

battery_temperature:
name: "Battery Temperature"
id: bt

fw_version:
name: "fw"
id: fw
Expand Down