diff --git a/README.md b/README.md index 07e9afa..97d0576 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ A simple card that shows your current energy usage. | power | state entity | **Required** | State entity for power | | | current | state entity | *Optional* | State entity for current | | | voltage | state entity | *Optional* | State entity for voltage | | +| frequency | state entity | *Optional* | State entity for frequency | | | power_factor | state entity | *Optional* | State entity for power_factor | | | label_leading | string | *Optional* | Leading label | | | label_trailing | string | *Optional* | Trailing label | | @@ -82,6 +83,7 @@ entities: - power: sensor.c_p current: sensor.c_c voltage: sensor.c_v + frequency: sensor.c_fq power_factor: sensor.c_pf label_leading: 'P' label_trailing: 'C' diff --git a/src/energy-overview-card.ts b/src/energy-overview-card.ts index 4270393..faa4ad6 100644 --- a/src/energy-overview-card.ts +++ b/src/energy-overview-card.ts @@ -2,9 +2,10 @@ import {css, CSSResultGroup, html, LitElement, TemplateResult} from "lit"; import {customElement, property} from "lit/decorators"; +import {unsafeHTML} from 'lit/directives/unsafe-html.js'; import {HomeAssistant} from "custom-card-helpers"; import {EnergyOverviewConfig, EnergyOverviewEntity} from "./types"; -import clamp from "./util"; +import clamp, {intersperse} from "./util"; @customElement("energy-overview-card") class EnergyOverviewCard extends LitElement { @@ -126,6 +127,7 @@ class EnergyOverviewCard extends LitElement { power: states[entity.power].state, current: entity.current ? states[entity.current].state : undefined, voltage: entity.voltage ? states[entity.voltage].state : undefined, + frequency: entity.frequency ? states[entity.frequency].state : undefined, power_factor: entity.power_factor ? states[entity.power_factor].state : undefined, color: entity.color ? entity.color : 'var(--energy-grid-consumption-color)', label_trailing: entity.label_trailing ? entity.label_trailing : '', @@ -157,26 +159,36 @@ class EnergyOverviewCard extends LitElement {
- ${entity.current || entity.voltage ? html` + ${entity.current || entity.voltage || entity.frequency ? html` ` : ``} ${entity.power_factor ? html` ` : ``} + class="secondary power-factor">${Math.round(parseFloat(entity.power_factor))} %
` : ``}
${entity.label_leading}
diff --git a/src/types.ts b/src/types.ts index ca20681..5dadf9e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,6 +8,7 @@ export interface EnergyOverviewEntity { power: string; current?: string; voltage?: string; + frequency?: string; power_factor?: string; label_trailing?: string; label_leading?: string; diff --git a/src/util.ts b/src/util.ts index f5482c6..a1a2ce4 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,3 +1,5 @@ export default function clamp(number, min, max) { return Math.max(min, Math.min(number, max)); } + +export const intersperse = (arr, sep) => arr.reduce((a, v) => [...a, v, sep], []).slice(0, -1);