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 PIP8048 support #10

Open
wants to merge 114 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
84290bd
Add draft
syssi Mar 12, 2022
a093876
Apply @SeByDocKy PIP8048 improvements
syssi Mar 12, 2022
52d7c8c
Add esphome-2022.3.0b1 compatibility
syssi Mar 12, 2022
d2c1422
Enable the CI
syssi Mar 12, 2022
79d4488
Fix typo
syssi Mar 12, 2022
dd1746f
Add new sensors to the config examples
syssi Mar 12, 2022
5e1dcb6
Rename sensors
syssi Mar 12, 2022
bc02ee8
Change CRC method
syssi Mar 19, 2022
f5b1cb9
Merge improved pipsolar crc (#3316)
syssi Mar 21, 2022
b73aad2
Merge andreashergert1984/esphome/tree/enhance_pipsolar_select
syssi Mar 21, 2022
0fcd601
Add select example
syssi Mar 21, 2022
9ad6999
Use esphome::to_string
syssi Mar 21, 2022
5f40093
Drop jschema_composite
syssi Apr 30, 2022
a6fce4e
Merge some esphome 2022.9.0 tidys ups
syssi Sep 24, 2022
7e823fd
Migrate some minor changes from the official pipsolar component
syssi Sep 24, 2022
5bf8a53
Update __init__.py
SeByDocKy Nov 16, 2022
0aabac3
Update __init__.py
SeByDocKy Nov 17, 2022
6fccdf2
Update __init__.py
SeByDocKy Nov 23, 2022
c167c39
Update __init__.py
SeByDocKy Nov 26, 2022
1df593a
Update pipsolar.h
SeByDocKy Nov 26, 2022
2b41064
Update pipsolar.cpp
SeByDocKy Nov 26, 2022
d743332
Update __init__.py
SeByDocKy Nov 26, 2022
8fe0007
Update __init__.py
SeByDocKy Nov 26, 2022
6802764
Update __init__.py
SeByDocKy Nov 26, 2022
54d1005
Update __init__.py
SeByDocKy Nov 26, 2022
427634a
Update __init__.py
SeByDocKy Nov 26, 2022
4fc6046
Update __init__.py
SeByDocKy Nov 26, 2022
cf88adc
Update pipsolar.h
SeByDocKy Nov 26, 2022
ded2d4c
Update pipsolar.cpp
SeByDocKy Nov 26, 2022
8fe486c
Update __init__.py
SeByDocKy Nov 26, 2022
9ac29f5
Update __init__.py
SeByDocKy Nov 26, 2022
2d0d0f5
Update pipsolar.h
SeByDocKy Nov 26, 2022
7d8a0f2
Update pipsolar.h
SeByDocKy Nov 26, 2022
c04fe4a
Update pipsolar.cpp
SeByDocKy Nov 26, 2022
7748ef9
Update pipsolar.cpp
SeByDocKy Nov 26, 2022
2aca0b5
Update __init__.py
SeByDocKy Nov 26, 2022
7f6a2d1
Update pipsolar.h
SeByDocKy Nov 26, 2022
9a6657f
Update pipsolar.cpp
SeByDocKy Nov 26, 2022
b12c3aa
Introduce PIPSOLAR_VALUED_SELECT
syssi Nov 27, 2022
6fd253a
Clean-up
syssi Nov 27, 2022
6ce382d
Add new select entity
syssi Nov 27, 2022
1ebc89f
Update __init__.py
SeByDocKy Jan 8, 2023
24874ec
Update __init__.py
SeByDocKy Jan 8, 2023
784c83d
Update __init__.py
SeByDocKy Jan 8, 2023
38d0922
Update __init__.py
SeByDocKy Jan 8, 2023
1f33fcf
Update __init__.py
SeByDocKy Jan 8, 2023
642a1cd
Update __init__.py
SeByDocKy Jan 8, 2023
35c48d5
Update __init__.py
SeByDocKy Jan 8, 2023
aec1edb
Update __init__.py
SeByDocKy Jan 8, 2023
1946c88
Update pipsolar_output.cpp
SeByDocKy Jan 8, 2023
73cc844
Update pipsolar_output.cpp
SeByDocKy Jan 8, 2023
155e4e1
Update __init__.py
SeByDocKy Jan 8, 2023
212c97e
Update pipsolar.h
SeByDocKy Jan 8, 2023
df29f92
Update __init__.py
SeByDocKy Jan 8, 2023
76f46b0
Update pipsolar.cpp
SeByDocKy Jan 8, 2023
02ecaeb
Update pipsolar.cpp
SeByDocKy Jan 8, 2023
3f6d96d
Update pipsolar.cpp
SeByDocKy Jan 8, 2023
beef495
Update pipsolar.h
SeByDocKy Jan 8, 2023
9497bfd
Update pipsolar.h
SeByDocKy Jan 8, 2023
a845e7c
Update pipsolar.cpp
SeByDocKy Jan 8, 2023
5e822d0
Update __init__.py
SeByDocKy Jan 8, 2023
87071f6
Update __init__.py
SeByDocKy Jan 8, 2023
e89d229
Update __init__.py
SeByDocKy Jan 8, 2023
76a590e
Update __init__.py
SeByDocKy Jan 8, 2023
e308e10
Update __init__.py
SeByDocKy Jan 8, 2023
dd8dfca
Update __init__.py
SeByDocKy Jan 8, 2023
a4d9578
Update __init__.py
SeByDocKy Jan 8, 2023
78c07cc
Update __init__.py
SeByDocKy Jan 8, 2023
5065958
Update __init__.py
SeByDocKy Jan 8, 2023
12620a0
Update __init__.py
SeByDocKy Jan 8, 2023
043138d
Update __init__.py
SeByDocKy Jan 11, 2023
0029290
Update pipsolar_output.cpp
SeByDocKy Jan 11, 2023
f9d9ad7
Update pipsolar_output.cpp
SeByDocKy Jan 11, 2023
22f89e0
Update __init__.py
SeByDocKy Jan 11, 2023
18867d2
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
5d1f502
Update pipsolar.h
SeByDocKy Jan 11, 2023
a3fb321
Update __init__.py
SeByDocKy Jan 11, 2023
f34d371
Update __init__.py
SeByDocKy Jan 11, 2023
00ca45d
Update pipsolar.h
SeByDocKy Jan 11, 2023
9e3f26e
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
2347011
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
a9e343d
Update __init__.py
SeByDocKy Jan 11, 2023
333efac
Update pipsolar.h
SeByDocKy Jan 11, 2023
8b0d082
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
113c492
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
d8b94f3
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
8df95b1
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
91b920c
Update __init__.py
SeByDocKy Jan 11, 2023
ca740f1
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
4da2a8b
Update pipsolar.h
SeByDocKy Jan 11, 2023
ad7625b
Update pipsolar.h
SeByDocKy Jan 11, 2023
d8053ea
Update __init__.py
SeByDocKy Jan 11, 2023
1869cc4
Update __init__.py
SeByDocKy Jan 11, 2023
9490dea
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
3a0e13a
Update pipsolar.h
SeByDocKy Jan 11, 2023
859100d
Update __init__.py
SeByDocKy Jan 11, 2023
5bf0372
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
2fca5ae
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
0151c14
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
fb1a6a9
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
c50ff7e
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
33ddbc8
Update __init__.py
SeByDocKy Jan 11, 2023
9c39018
Update __init__.py
SeByDocKy Jan 11, 2023
6e0ecf8
Update pipsolar.cpp
SeByDocKy Jan 11, 2023
b559657
Update pipsolar.h
SeByDocKy Jan 11, 2023
8249f59
Update esp32-example.yaml
SeByDocKy Jan 11, 2023
4fe65b8
Update esp8266-example.yaml
SeByDocKy Jan 11, 2023
c8ef854
Fix yamllint issues
syssi Feb 2, 2023
02d293c
Support long QPIGS responses
syssi Feb 26, 2023
e114644
Prefer ESP-IDF framework over arduino
syssi Mar 30, 2024
1348d77
Rename uart0 to uart_0
syssi Mar 30, 2024
f8f925b
Fix CI
syssi Mar 30, 2024
16853dd
Add tests
syssi Mar 30, 2024
ee994d8
ename `binary_sensor.warnung_low_pv_energy` to `binary_sensor.warning…
almost-online Jun 14, 2024
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
15 changes: 11 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: # yamllint disable-line rule:truthy
push:
branches:
- main
- pip8048
pull_request:
schedule:
- cron: 0 12 * * *
Expand All @@ -23,10 +24,10 @@ jobs:
steps:
- name: ⤵️ Check out configuration from GitHub
uses: actions/checkout@v2
- name: Setup Python 3.8
- name: Setup Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand All @@ -36,10 +37,16 @@ jobs:
- name: Write secrets.yaml
shell: bash
run: 'echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password" > secrets.yaml'
- name: Write tests/secrets.yaml
shell: bash
run: 'echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password" > tests/secrets.yaml'
- run: |
esphome config esp32-example.yaml
- run: |
esphome config esp8266-example.yaml
esphome config tests/esp8266-test-ping.yaml
esphome config tests/esp8266-test-pong.yaml
esphome config tests/esp8266-test-protocols.yaml

esphome-compile:
runs-on: ubuntu-latest
Expand All @@ -59,10 +66,10 @@ jobs:
path: .pioenvs
key: esphome-compile-pioenvs-${{ hashFiles('*.yaml') }}
restore-keys: esphome-compile-pioenvs-
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea/
secret.yaml
secrets.yaml
.esphome/
**/.pioenvs/
**/.piolibdeps/
Expand Down
32 changes: 32 additions & 0 deletions components/pipsolar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import uart
from esphome.const import CONF_ID

DEPENDENCIES = ["uart"]
CODEOWNERS = ["@andreashergert1984"]
AUTO_LOAD = ["binary_sensor", "text_sensor", "sensor", "switch", "output", "select"]
MULTI_CONF = True

CONF_PIPSOLAR_ID = "pipsolar_id"

pipsolar_ns = cg.esphome_ns.namespace("pipsolar")
PipsolarComponent = pipsolar_ns.class_("Pipsolar", cg.Component)

PIPSOLAR_COMPONENT_SCHEMA = cv.Schema(
{
cv.Required(CONF_PIPSOLAR_ID): cv.use_id(PipsolarComponent),
}
)

CONFIG_SCHEMA = cv.All(
cv.Schema({cv.GenerateID(): cv.declare_id(PipsolarComponent)})
.extend(cv.polling_component_schema("1s"))
.extend(uart.UART_DEVICE_SCHEMA)
)


def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield uart.register_uart_device(var, config)
150 changes: 150 additions & 0 deletions components/pipsolar/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor

from .. import PIPSOLAR_COMPONENT_SCHEMA, CONF_PIPSOLAR_ID

DEPENDENCIES = ["uart"]

CONF_ADD_SBU_PRIORITY_VERSION = "add_sbu_priority_version"
CONF_CONFIGURATION_STATUS = "configuration_status"
CONF_SCC_FIRMWARE_VERSION = "scc_firmware_version"
CONF_LOAD_STATUS = "load_status"
CONF_BATTERY_VOLTAGE_TO_STEADY_WHILE_CHARGING = (
"battery_voltage_to_steady_while_charging"
)
CONF_CHARGING_STATUS = "charging_status"
CONF_SCC_CHARGING_STATUS = "scc_charging_status"
CONF_AC_CHARGING_STATUS = "ac_charging_status"
CONF_CHARGING_TO_FLOATING_MODE = "charging_to_floating_mode"
CONF_SWITCH_ON = "switch_on"
CONF_DUSTPROOF_INSTALLED = "dustproof_installed"
CONF_SILENCE_BUZZER_OPEN_BUZZER = "silence_buzzer_open_buzzer"
CONF_OVERLOAD_BYPASS_FUNCTION = "overload_bypass_function"
CONF_LCD_ESCAPE_TO_DEFAULT = "lcd_escape_to_default"
CONF_OVERLOAD_RESTART_FUNCTION = "overload_restart_function"
CONF_OVER_TEMPERATURE_RESTART_FUNCTION = "over_temperature_restart_function"
CONF_BACKLIGHT_ON = "backlight_on"
CONF_ALARM_ON_WHEN_PRIMARY_SOURCE_INTERRUPT = "alarm_on_when_primary_source_interrupt"
CONF_FAULT_CODE_RECORD = "fault_code_record"
CONF_POWER_SAVING = "power_saving"

CONF_WARNINGS_PRESENT = "warnings_present"
CONF_FAULTS_PRESENT = "faults_present"
CONF_WARNING_POWER_LOSS = "warning_power_loss"
CONF_FAULT_INVERTER_FAULT = "fault_inverter_fault"
CONF_FAULT_BUS_OVER = "fault_bus_over"
CONF_FAULT_BUS_UNDER = "fault_bus_under"
CONF_FAULT_BUS_SOFT_FAIL = "fault_bus_soft_fail"
CONF_WARNING_LINE_FAIL = "warning_line_fail"
CONF_FAULT_OPVSHORT = "fault_opvshort"
CONF_FAULT_INVERTER_VOLTAGE_TOO_LOW = "fault_inverter_voltage_too_low"
CONF_FAULT_INVERTER_VOLTAGE_TOO_HIGH = "fault_inverter_voltage_too_high"
CONF_WARNING_OVER_TEMPERATURE = "warning_over_temperature"
CONF_WARNING_FAN_LOCK = "warning_fan_lock"
CONF_WARNING_BATTERY_VOLTAGE_HIGH = "warning_battery_voltage_high"
CONF_WARNING_BATTERY_LOW_ALARM = "warning_battery_low_alarm"
CONF_WARNING_BATTERY_UNDER_SHUTDOWN = "warning_battery_under_shutdown"
CONF_WARNING_BATTERY_DERATING = "warning_battery_derating"
CONF_WARNING_OVER_LOAD = "warning_over_load"
CONF_WARNING_EEPROM_FAILED = "warning_eeprom_failed"
CONF_FAULT_INVERTER_OVER_CURRENT = "fault_inverter_over_current"
CONF_FAULT_INVERTER_SOFT_FAILED = "fault_inverter_soft_failed"
CONF_FAULT_SELF_TEST_FAILED = "fault_self_test_failed"
CONF_FAULT_OP_DC_VOLTAGE_OVER = "fault_op_dc_voltage_over"
CONF_FAULT_BATTERY_OPEN = "fault_battery_open"
CONF_FAULT_CURRENT_SENSOR_FAILED = "fault_current_sensor_failed"
CONF_FAULT_BATTERY_SHORT = "fault_battery_short"
CONF_WARNING_POWER_LIMIT = "warning_power_limit"
CONF_WARNING_PV_VOLTAGE_HIGH = "warning_pv_voltage_high"
CONF_FAULT_MPPT_OVERLOAD = "fault_mppt_overload"
CONF_WARNING_MPPT_OVERLOAD = "warning_mppt_overload"
CONF_WARNING_BATTERY_TOO_LOW_TO_CHARGE = "warning_battery_too_low_to_charge"
CONF_FAULT_DC_DC_OVER_CURRENT = "fault_dc_dc_over_current"
CONF_FAULT_CODE = "fault_code"
CONF_WARNING_LOW_PV_ENERGY = "warning_low_pv_energy"
CONF_WARNING_HIGH_AC_INPUT_DURING_BUS_SOFT_START = (
"warning_high_ac_input_during_bus_soft_start"
)
CONF_WARNING_BATTERY_EQUALIZATION = "warning_battery_equalization"

# QBATCD binary sensors

CONF_DISCHARGE_ONOFF = "discharge_onoff"
CONF_DISCHARGE_WITH_STANDBY_ONOFF = "discharge_with_standby_onoff"
CONF_CHARGE_ONOFF = "charge_onoff"

TYPES = [
CONF_ADD_SBU_PRIORITY_VERSION,
CONF_CONFIGURATION_STATUS,
CONF_SCC_FIRMWARE_VERSION,
CONF_LOAD_STATUS,
CONF_BATTERY_VOLTAGE_TO_STEADY_WHILE_CHARGING,
CONF_CHARGING_STATUS,
CONF_SCC_CHARGING_STATUS,
CONF_AC_CHARGING_STATUS,
CONF_CHARGING_TO_FLOATING_MODE,
CONF_SWITCH_ON,
CONF_DUSTPROOF_INSTALLED,
CONF_SILENCE_BUZZER_OPEN_BUZZER,
CONF_OVERLOAD_BYPASS_FUNCTION,
CONF_LCD_ESCAPE_TO_DEFAULT,
CONF_OVERLOAD_RESTART_FUNCTION,
CONF_OVER_TEMPERATURE_RESTART_FUNCTION,
CONF_BACKLIGHT_ON,
CONF_ALARM_ON_WHEN_PRIMARY_SOURCE_INTERRUPT,
CONF_FAULT_CODE_RECORD,
CONF_POWER_SAVING,
CONF_WARNINGS_PRESENT,
CONF_FAULTS_PRESENT,
CONF_WARNING_POWER_LOSS,
CONF_FAULT_INVERTER_FAULT,
CONF_FAULT_BUS_OVER,
CONF_FAULT_BUS_UNDER,
CONF_FAULT_BUS_SOFT_FAIL,
CONF_WARNING_LINE_FAIL,
CONF_FAULT_OPVSHORT,
CONF_FAULT_INVERTER_VOLTAGE_TOO_LOW,
CONF_FAULT_INVERTER_VOLTAGE_TOO_HIGH,
CONF_WARNING_OVER_TEMPERATURE,
CONF_WARNING_FAN_LOCK,
CONF_WARNING_BATTERY_VOLTAGE_HIGH,
CONF_WARNING_BATTERY_LOW_ALARM,
CONF_WARNING_BATTERY_UNDER_SHUTDOWN,
CONF_WARNING_BATTERY_DERATING,
CONF_WARNING_OVER_LOAD,
CONF_WARNING_EEPROM_FAILED,
CONF_FAULT_INVERTER_OVER_CURRENT,
CONF_FAULT_INVERTER_SOFT_FAILED,
CONF_FAULT_SELF_TEST_FAILED,
CONF_FAULT_OP_DC_VOLTAGE_OVER,
CONF_FAULT_BATTERY_OPEN,
CONF_FAULT_CURRENT_SENSOR_FAILED,
CONF_FAULT_BATTERY_SHORT,
CONF_WARNING_POWER_LIMIT,
CONF_WARNING_PV_VOLTAGE_HIGH,
CONF_FAULT_MPPT_OVERLOAD,
CONF_WARNING_MPPT_OVERLOAD,
CONF_WARNING_BATTERY_TOO_LOW_TO_CHARGE,
CONF_FAULT_DC_DC_OVER_CURRENT,
CONF_FAULT_CODE,
CONF_WARNING_LOW_PV_ENERGY,
CONF_WARNING_HIGH_AC_INPUT_DURING_BUS_SOFT_START,
CONF_WARNING_BATTERY_EQUALIZATION,
CONF_DISCHARGE_ONOFF,
CONF_DISCHARGE_WITH_STANDBY_ONOFF,
CONF_CHARGE_ONOFF,
]

CONFIG_SCHEMA = PIPSOLAR_COMPONENT_SCHEMA.extend(
{cv.Optional(type): binary_sensor.binary_sensor_schema() for type in TYPES}
)


async def to_code(config):
paren = await cg.get_variable(config[CONF_PIPSOLAR_ID])
for type in TYPES:
if type in config:
conf = config[type]
var = await binary_sensor.new_binary_sensor(conf)
cg.add(getattr(paren, f"set_{type}")(var))
111 changes: 111 additions & 0 deletions components/pipsolar/output/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import output
from esphome.const import CONF_ID, CONF_VALUE

from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA, pipsolar_ns

DEPENDENCIES = ["pipsolar"]

PipsolarOutput = pipsolar_ns.class_("PipsolarOutput", output.FloatOutput)
SetOutputAction = pipsolar_ns.class_("SetOutputAction", automation.Action)

CONF_POSSIBLE_VALUES = "possible_values"

# 3.11 PCVV<nn.n><cr>: Setting battery C.V. (constant voltage) charging voltage 48.0V ~ 58.4V for 48V unit
# battery_bulk_voltage;
# battery_recharge_voltage; 12V unit: 11V/11.3V/11.5V/11.8V/12V/12.3V/12.5V/12.8V
# 24V unit: 22V/22.5V/23V/23.5V/24V/24.5V/25V/25.5V
# 48V unit: 44V/45V/46V/47V/48V/49V/50V/51V
# battery_under_voltage; 40.0V ~ 48.0V for 48V unit
# battery_float_voltage; 48.0V ~ 58.4V for 48V unit
# battery_type; 00 for AGM, 01 for Flooded battery
# current_max_ac_charging_current;
# output_source_priority; 00 / 01 / 02
# charger_source_priority; For HS: 00 for utility first, 01 for solar first, 02 for solar and utility, 03 for only solar charging
# For MS/MSX: 00 for utility first, 01 for solar first, 03 for only solar charging
# battery_redischarge_voltage; 12V unit: 00.0V12V/12.3V/12.5V/12.8V/13V/13.3V/13.5V/13.8V/14V/14.3V/14.5
# 24V unit: 00.0V/24V/24.5V/25V/25.5V/26V/26.5V/27V/27.5V/28V/28.5V/29V
# 48V unit: 00.0V48V/49V/50V/51V/52V/53V/54V/55V/56V/57V/58V

CONF_BATTERY_BULK_VOLTAGE = "battery_bulk_voltage"
CONF_BATTERY_RECHARGE_VOLTAGE = "battery_recharge_voltage"
CONF_BATTERY_UNDER_VOLTAGE = "battery_under_voltage"
CONF_BATTERY_FLOAT_VOLTAGE = "battery_float_voltage"
CONF_BATTERY_TYPE = "battery_type"
CONF_CURRENT_MAX_AC_CHARGING_CURRENT = "current_max_ac_charging_current"
CONF_CURRENT_MAX_CHARGING_CURRENT = "current_max_charging_current"
CONF_OUTPUT_SOURCE_PRIORITY = "output_source_priority"
CONF_CHARGER_SOURCE_PRIORITY = "charger_source_priority"
CONF_BATTERY_REDISCHARGE_VOLTAGE = "battery_redischarge_voltage"

TYPES = {
CONF_BATTERY_BULK_VOLTAGE: (
[44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0],
"PCVV%02.1f",
),
CONF_BATTERY_RECHARGE_VOLTAGE: (
[44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0],
"PBCV%02.1f",
),
CONF_BATTERY_UNDER_VOLTAGE: (
[40.0, 40.1, 42, 43, 44, 45, 46, 47, 48.0],
"PSDV%02.1f",
),
CONF_BATTERY_FLOAT_VOLTAGE: ([48.0, 49.0, 50.0, 51.0], "PBFT%02.1f"),
CONF_BATTERY_TYPE: ([0, 1, 2], "PBT%02.0f"),
CONF_CURRENT_MAX_AC_CHARGING_CURRENT: ([2, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], "MUCHGC%04.0f"),
CONF_CURRENT_MAX_CHARGING_CURRENT: ([ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 ], "MCHGC%03.0f"),
CONF_OUTPUT_SOURCE_PRIORITY: ([0, 1, 2], "POP%02.0f"),
CONF_CHARGER_SOURCE_PRIORITY: ([0, 1, 2, 3], "PCP%02.0f"),
CONF_BATTERY_REDISCHARGE_VOLTAGE: (
[0, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58],
"PBDV%02.1f",
),
}

CONFIG_SCHEMA = PIPSOLAR_COMPONENT_SCHEMA.extend(
{
cv.Optional(type): output.FLOAT_OUTPUT_SCHEMA.extend(
{
cv.Required(CONF_ID): cv.declare_id(PipsolarOutput),
cv.Optional(CONF_POSSIBLE_VALUES, default=values): cv.All(
cv.ensure_list(cv.positive_float), cv.Length(min=1)
),
}
)
for type, (values, _) in TYPES.items()
}
)

async def to_code(config):
paren = await cg.get_variable(config[CONF_PIPSOLAR_ID])

for type, (_, command) in TYPES.items():
if type in config:
conf = config[type]
var = cg.new_Pvariable(conf[CONF_ID])
await output.register_output(var, conf)
cg.add(var.set_parent(paren))
cg.add(var.set_set_command(command))
if (CONF_POSSIBLE_VALUES) in conf:
cg.add(var.set_possible_values(conf[CONF_POSSIBLE_VALUES]))


@automation.register_action(
"output.pipsolar.set_level",
SetOutputAction,
cv.Schema(
{
cv.Required(CONF_ID): cv.use_id(CONF_ID),
cv.Required(CONF_VALUE): cv.templatable(cv.positive_float),
}
),
)
def output_pipsolar_set_level_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
template_ = yield cg.templatable(config[CONF_VALUE], args, float)
cg.add(var.set_level(template_))
yield var
22 changes: 22 additions & 0 deletions components/pipsolar/output/pipsolar_output.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "pipsolar_output.h"
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"

namespace esphome {
namespace pipsolar {

static const char *const TAG = "pipsolar.output";

void PipsolarOutput::write_state(float state) {
char tmp[12];
sprintf(tmp, this->set_command_.c_str(), state);

if (std::find(this->possible_values_.begin(), this->possible_values_.end(), state) != this->possible_values_.end()) {
ESP_LOGD(TAG, "Will write: %s out of value %f / %03.0f", tmp, state, state);
this->parent_->switch_command(std::string(tmp));
} else {
ESP_LOGD(TAG, "Will not write: %s as it is not in list of allowed values", tmp);
}
}
} // namespace pipsolar
} // namespace esphome
Loading
Loading