Skip to content

Commit

Permalink
Merge pull request #38 from DanteWinters/develop
Browse files Browse the repository at this point in the history
Feature update
  • Loading branch information
DanteWinters authored Oct 1, 2023
2 parents 2c8c07f + c180cc2 commit bdefccd
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 112 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ The following is a list of configs for the card:
| grid_indicator | dot | bool | If this is set to true and the grid voltage drops to 0, a red indicator will be added next to the grid voltage text. (Requires a grid voltage entity.) |
| update_time | show_last_update | bool | If the update time entity has a timestamp attribute, it can be used to show how long since the last update. |
| status_codes | no_grid_is_warning | bool | Some status codes (64, 136 and 192) are shown when grid is not available. If this value is true, these codes will show up as a warning on the status. If the value is false, these values will show up as normal. |
| parallel | average_voltage | bool | When using multiple inverters, there is a default created item on the list of inverters called "Parallel" that averages all the values from the different inverters. If *average_voltage* is true, the battery and grid voltages will be averaged and shown on the Parallel setting. Otherwise it will not show the voltages there. |
| parallel | parallel_first | bool | When using multiple inverters, there is a default created item on the list of inverters called "Parallel" that averages all the values from the different inverters. If *parallel_first* is true, the "Parallel" option will be shown first of the list, otherwise it will be last. |

# LuxpowerTek integration

Expand All @@ -80,6 +82,9 @@ If you have the Luxpower integration, you can use the following code directly (e
```yaml
type: custom:lux-power-distribution-card
inverter_count: 1
parallel:
average_voltage: true
parallel_first: true
battery_soc:
entities:
- sensor.lux_battery
Expand Down Expand Up @@ -170,9 +175,7 @@ The four entity images on the card can be clicked to display the history of the
With v1.0.0, support for parallel inverters have arrived! In order to use parallel inverters, simply indicate the number of inverters you are using in the config, and add the additional inverter's entities under their corresponding headers. Take note of the *inverter_alias* and *lux_dongle* config values when using parallel inverters.
### Known issues
- Currently there is no option to mix the values, but that is on the roadmap.
- The refresh button only works on the first dongle value added.
- The status that is shown is for the first inverter. The next update will hopefully
# Developer's note
Expand Down
80 changes: 59 additions & 21 deletions config-entity-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ export function buildConfig(config) {
}
}

// Check parallel settings
if (config.parallel) {
if (config.parallel.average_voltage) {
new_config.parallel.average_voltage = true;
}
if (config.parallel.parallel_first) {
new_config.parallel.parallel_first = true;
} else {
new_config.parallel.parallel_first = false;
}
}

validateConfig(new_config);

return new_config;
Expand Down Expand Up @@ -141,38 +153,64 @@ function importConfigValues(config, new_config, inverter_count, object_name) {
}

export function getEntitiesState(config, hass, config_entity, index) {
const entity = hass.states[config[config_entity].entities[index]];
const entity_name = config[config_entity].entities[index];
try {
const entity = hass.states[entity_name];
if (entity.state) {
if (entity.state === "unavailable" || entity.state === "unknown") {
return "-";
} else {
return entity.state;
}
}
return "-";
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
}
}

if (entity.state) {
if (entity.state === "unavailable" || entity.state === "unknown") {
return "-";
} else if (isNaN(entity.state)) {
return entity.state;
} else {
return entity.state;
export function getEntitiesNumState(config, hass, config_entity, index, is_int = true) {
let value = 0;
if (index == -1) {
for (let i = 0; i < config.inverter_count; i++) {
value += parseFloat(getEntitiesState(config, hass, config_entity, i));
}
value = value / config.inverter_count;
} else {
value = parseFloat(getEntitiesState(config, hass, config_entity, index));
}
if (is_int) {
return parseInt(value);
}
return "-";
return value;
}

export function getEntitiesAttribute(config, hass, config_entity, attribute_name, index) {
const entity = hass.states[config[config_entity].entities[index]];

if (entity.attributes && entity.attributes[attribute_name]) {
return entity.attributes[attribute_name];
} else {
return "-";
const entity_name = config[config_entity].entities[index];
try {
const entity = hass.states[entity_name];
if (entity.attributes && entity.attributes[attribute_name]) {
return entity.attributes[attribute_name];
} else {
return "-";
}
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
}
}

export function getEntitiesUnit(config, hass, config_entity, index) {
const entity = hass.states[config[config_entity].entities[index]];

if (entity.state) {
if (isNaN(entity.state)) return "-";
else return entity.attributes.unit_of_measurement ?? "";
const entity_name = config[config_entity].entities[index];
try {
const entity = hass.states[config[config_entity].entities[index]];
if (entity.state) {
if (isNaN(entity.state)) return "-";
else return entity.attributes.unit_of_measurement ?? "";
}
return "";
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
}
return "";
}

export function getStatusMessage(status_code, show_no_grid_as_warning) {
Expand Down
4 changes: 4 additions & 0 deletions constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 24 additions & 16 deletions html-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export function generateStyles(config) {
/*max-height: 100%;*/
display: flex;
/*text-overflow: ellipsis;
flex-wrap: wrap;
word-wrap: break-word;*/ /* Allow the text to wrap within the cell */
flex-wrap: wrap;
word-wrap: break-word;*/ /* Allow the text to wrap within the cell */
}
/* .text-cell left {
justify-content: left;
text-align: left;
}
.text-cell right {
justify-content: right;
text-align: right;
} */
justify-content: left;
text-align: left;
}
.text-cell right {
justify-content: right;
text-align: right;
} */
.header-text {
font-size: min(4vw, 1.17em);
font-weight: bold;
Expand Down Expand Up @@ -180,16 +180,18 @@ export function generateStyles(config) {
margin: 0;
line-height: 1;
}
`;
`;
}

export const card_base = `
<ha-card>
<div id="inv-info"></div>
<div id="card-grid" class="diagram-grid"></div>
<div id="datetime-info" class="update-time"></div>
</ha-card>
<ha-card>
<div id="inv-info">
</div>
<div id="card-grid" class="diagram-grid">
</div>
<div id="datetime-info" class="update-time">
</div>
</ha-card>
`;

export function generateStatus(config) {
Expand All @@ -199,9 +201,15 @@ export function generateStatus(config) {
if (config.inverter_alias.is_used && config.inverter_count > 1) {
// let text_box_options = `<option value="parallel">Parallel</option>`;
let text_box_options = ``;
if (config.parallel.parallel_first) {
text_box_options += `<option value="${config.inverter_count}">Parallel</option>`;
}
for (let i = 0; i < config.inverter_count; i++) {
text_box_options += `<option value="${i}">${config.inverter_alias.values[i]}</option>`;
}
if (!config.parallel.parallel_first) {
text_box_options += `<option value="${config.inverter_count}">Parallel</option>`;
}
text_box_full = `
<select class="inv-select" name="Inverters" id="inverter-selector">
${text_box_options}
Expand Down
Loading

0 comments on commit bdefccd

Please sign in to comment.