Skip to content

Commit

Permalink
add new name_prefix: setting, fix temp scale issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Jul 25, 2020
1 parent a4de8f5 commit 111d3ba
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 64 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![Release](https://github.com/ironsheep/lovelace-rpi-monitor-card/workflows/Release/badge.svg)

If you have a number of Raspberry Pis on your network then this might be the card you need to setup your Dashboard for monitoring all of you RPi's. Setup the sensor software on your RPi: See [RPi Reporter MQTT2HA Daemon](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon). Then install this card to display the state of your RPi.
If you have a number of Raspberry Pis on your network then this might be the card you need to setup your Dashboard for monitoring all of you RPi's. Setup the sensor software on your RPi: See [RPi Reporter MQTT2HA Daemon](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon). Then install this card to display the state of your RPi.

## About this card

Expand All @@ -26,7 +26,6 @@ If you like my work and/or this has helped you in some way then feel free to hel

[![coffee](https://www.buymeacoffee.com/assets/img/custom_images/black_img.png)](https://www.buymeacoffee.com/ironsheep)


## Installation

Use [HACS](https://github.com/custom-components/hacs) (recommended)
Expand All @@ -43,34 +42,33 @@ If you don't use HACS please change the url accordingly.
## Configuration
| Name | Type | Default | Description |
| ------------- | ------ | ------------------ | --------------------------------------------------------------------- |
| type | string | **Required** | `custom:rpi-monitor-card` |
| entity | string | **Required** | Entity State |
| name | string | none | Overrides default title of the card. (Default: RPi Monitor {FQDN} |
| card_style | string | 'glance' or 'full' | Card layout desired for this RPi. (Default is Full) |
| temp_scale | string | 'C' or 'F' | Show Temperature in Celsius (C) or Fahrenheit (F). (Default is C) |
| Name | Type | Default | Description |
| ------------- | ------ | ------------------ | ----------------------------------------------------------------------- |
| type | string | **Required** | `custom:rpi-monitor-card` |
| entity | string | **Required** | Entity State |
| name | string | none | Overrides default title of the card. (Default: RPi Monitor {FQDN}) |
| name_prefix | string | 'RPi monitor' | Overrides default name prefix(Default: 'RPi Monitor') |
| card_style | string | 'glance' or 'full' | Card layout desired for this RPi. (Default is full) |
| temp_scale | string | 'C' or 'F' | Show Temperature in Celsius (C) or Fahrenheit (F). (Default is C) |
| fs_severity | object | none | A list of severity values. See [Severity Coloring](#severity-coloring). |
| temp_severity | object | none | A list of severity values. See [Severity Coloring](#severity-coloring). |


### Threashold Monitoring

Both the 'system temperature' and 'disk space used' values & icons are colored by threshold. The following defaults can be overridden for each card (each RPi.)

The default coloring is

| **Value**/color | from | to
| ------------- | ------ | ------------------
| **Storage Used** % ||
| default| 0 | 60
| yellow| 61| 85
|red | 86 | 100
| **Temperature** C ||
|default| 0 | 59
| yellow| 60 | 79
| red| 80 | 100

| **Value**/color | from | to |
| ------------------ | ---- | --- |
| **Storage Used** % | |
| default | 0 | 60 |
| yellow | 61 | 85 |
| red | 86 | 100 |
| **Temperature** C | |
| default | 0 | 59 |
| yellow | 60 | 79 |
| red | 80 | 100 |

### Severity Coloring

Expand All @@ -91,10 +89,9 @@ type: 'custom:rpi-monitor-card'
entity: sensor.rpi-monitor-hostname
card_style: glance
temp_scale: f
```

A 'full' card example (*with additional coloring override example*)
A 'full' card example (_with additional coloring override example_)

```yaml
type: 'custom:rpi-monitor-card'
Expand Down
45 changes: 21 additions & 24 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

![Release](https://github.com/ironsheep/lovelace-rpi-monitor-card/workflows/Release/badge.svg)

If you have a number of Raspberry Pis on your network then this might be the card you need to setup your Dashboard for monitoring all of you RPi's. Setup the sensor software on your RPi: See [RPi Reporter MQTT2HA Daemon](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon). Then install this card to display the state of your RPi.
If you have a number of Raspberry Pis on your network then this might be the card you need to setup your Dashboard for monitoring all of you RPi's. Setup the sensor software on your RPi: See [RPi Reporter MQTT2HA Daemon](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon). Then install this card to display the state of your RPi.

--

Expand All @@ -18,7 +18,6 @@ This is a Lovelace card showing you the status of one of the Raspberry Pi's on y

Place one of these cards for each of your RPi's on your network (and install the sensor/daemon script on each RPi) and you can monitor your entire constellation of RPi's "at a glance"!


## Installation

Use [HACS](https://github.com/custom-components/hacs) (recommended)
Expand All @@ -35,36 +34,36 @@ If you don't use HACS please change the url accordingly.
## Configuration
| Name | Type | Default | Description |
| ------------- | ------ | ------------------ | --------------------------------------------------------------------- |
| type | string | **Required** | `custom:rpi-monitor-card` |
| entity | string | **Required** | Entity State |
| name | string | none | Overrides default title of the card. (Default: RPi Monitor {FQDN} |
| card_style | string | 'glance' or 'full' | Card layout desired for this RPi. (Default is Full) |
| temp_scale | string | 'C' or 'F' | Show Temperature in Celsius (C) or Fahrenheit (F). (Default is C) |
| Name | Type | Default | Description |
| ------------- | ------ | ------------------ | ----------------------------------------------------------------------- |
| type | string | **Required** | `custom:rpi-monitor-card` |
| entity | string | **Required** | Entity State |
| name | string | none | Overrides default title of the card. (Default: RPi Monitor {FQDN}) |
| name_prefix | string | 'RPi monitor' | Overrides default name prefix(Default: 'RPi Monitor') |
| card_style | string | 'glance' or 'full' | Card layout desired for this RPi. (Default is full) |
| temp_scale | string | 'C' or 'F' | Show Temperature in Celsius (C) or Fahrenheit (F). (Default is C) |
| fs_severity | object | none | A list of severity values. See [Severity Coloring](#severity-coloring). |
| temp_severity | object | none | A list of severity values. See [Severity Coloring](#severity-coloring). |


### Threashold Monitoring

Both the 'system temperature' and 'disk space used' values & icons are colored by threshold. The following defaults can be overridden for each card (each RPi.)

The default coloring is

| **Value**/color | from | to
| ------------- | ------ | ------------------
| **Storage Used** % ||
| default| 0 | 60
| yellow| 61| 85
|red | 86 | 100
| **Temperature** C ||
|default| 0 | 59
| yellow| 60 | 79
| red| 80 | 100

| **Value**/color | from | to |
| ------------------ | ---- | --- |
| **Storage Used** % | |
| default | 0 | 60 |
| yellow | 61 | 85 |
| red | 86 | 100 |
| **Temperature** C | |
| default | 0 | 59 |
| yellow | 60 | 79 |
| red | 80 | 100 |

### Severity Coloring

Use the following format to override either/or both of 'space used' and 'system temperature' values.

| Name | Type | Default | Description |
Expand All @@ -84,10 +83,9 @@ type: 'custom:rpi-monitor-card'
entity: sensor.rpi-monitor-hostname
card_style: glance
temp_scale: f
```

A 'full' card example (*with additional coloring override example*)
A 'full' card example (_with additional coloring override example_)

```yaml
type: 'custom:rpi-monitor-card'
Expand All @@ -112,7 +110,6 @@ If you like my work and/or this has helped you in some way then feel free to hel

[![coffee](https://www.buymeacoffee.com/assets/img/custom_images/black_img.png)](https://www.buymeacoffee.com/ironsheep)


[maintenance-shield]: https://img.shields.io/badge/maintainer-S%20M%20Moraco%20%40ironsheepbiz-blue.svg?style=for-the-badge
[hacs-shield]: https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge
[license-shield]: https://camo.githubusercontent.com/bc04f96d911ea5f6e3b00e44fc0731ea74c8e1e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f69616e74726963682f746578742d646976696465722d726f772e7376673f7374796c653d666f722d7468652d6261646765
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const CARD_VERSION = '1.0.1';
export const CARD_VERSION = '1.2.0';

/*
* EXAMPLE attributes
Expand Down
92 changes: 76 additions & 16 deletions src/rpi-monitor-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export class RPiMonitorCard extends LitElement {
];

public setConfig(config: RPiMonitorCardConfig): void {
if (this._showDebug()) {
console.log('- setConfig()');
}
// Optional: Check for required fields and that they are of the proper format
if (!config || config.show_error) {
throw new Error(localize('common.invalid_configuration'));
Expand Down Expand Up @@ -282,7 +285,7 @@ export class RPiMonitorCard extends LitElement {
}

this._config = {
name: 'RPi Monitor',
name: 'RPi Monitor Card',
...config,
};

Expand Down Expand Up @@ -322,6 +325,9 @@ export class RPiMonitorCard extends LitElement {

protected render(): TemplateResult | void {
// Check for stateObj or other necessary things and render a warning if missing
if (this._showDebug()) {
console.log('- render()');
}
if (this._config.show_warning) {
return this.showWarning(localize('common.show_warning'));
}
Expand Down Expand Up @@ -356,7 +362,9 @@ export class RPiMonitorCard extends LitElement {
this._firstTime = false;
}

const cardName = 'RPi monitor ' + this._getAttributeValueForKey(Constants.RPI_FQDN_KEY);
const rpi_fqdn = this._getAttributeValueForKey(Constants.RPI_FQDN_KEY);
const cardName =
this._config.name_prefix != undefined ? this._config.name_prefix + ' ' + rpi_fqdn : 'RPi monitor ' + rpi_fqdn;

const card_timestamp_value = this._getRelativeTimeSinceUpdate();

Expand Down Expand Up @@ -428,6 +436,9 @@ export class RPiMonitorCard extends LitElement {

// Here we need to refresh the rings and titles after it has been initially rendered
protected updated(changedProps): void {
if (this._showDebug()) {
console.log('- updated()');
}
if (!this._config) {
return;
}
Expand Down Expand Up @@ -485,7 +496,7 @@ export class RPiMonitorCard extends LitElement {
const currLabelID = this._cardGlanceCssIDs[currName];
const currAttrKey = this._cardGlanceElements[currName];
const rawValue = this._getAttributeValueForKey(currAttrKey);
let latestValue = this._getAttributeValueForKey(currAttrKey);
let latestValue = this._getGlanceCardValueForAttributeKey(currAttrKey);
if (currAttrKey == Constants.RPI_UP_TIME_KEY) {
latestValue = this._filterUptime(latestValue);
} else if (currAttrKey == Constants.RPI_LAST_UPDATE_KEY) {
Expand Down Expand Up @@ -709,10 +720,26 @@ export class RPiMonitorCard extends LitElement {
sections.forEach(section => {
if (numberValue >= section.from && numberValue <= section.to) {
color = section.color;
const logMessage =
'_computeTemperatureColor() - value=[' +
value +
'] matched(from=' +
section.from +
', to=' +
section.to +
', color=' +
color +
')';
if (this._showDebug()) {
console.log(logMessage);
}
}
});
}

const logMessage = '_computeTemperatureColor() - value=[' + value + '] returns(color=' + color + ')';
if (this._showDebug()) {
console.log(logMessage);
}
if (color == undefined) color = '';
return color;
}
Expand All @@ -738,9 +765,26 @@ export class RPiMonitorCard extends LitElement {
sections.forEach(section => {
if (numberValue >= section.from && numberValue <= section.to) {
color = section.color;
const logMessage =
'_computeFileSystemUsageColor() - value=[' +
value +
'] matched(from=' +
section.from +
', to=' +
section.to +
', color=' +
color +
')';
if (this._showDebug()) {
console.log(logMessage);
}
}
});
}
const logMessage = '_computeFileSystemUsageColor() - value=[' + value + '] returns(color=' + color + ')';
if (this._showDebug()) {
console.log(logMessage);
}

if (color == undefined) color = '';
return color;
Expand Down Expand Up @@ -862,26 +906,18 @@ export class RPiMonitorCard extends LitElement {
for (const currName in this._cardGlanceElements) {
const currAttributeKey = this._cardGlanceElements[currName];
// Use `key` and `value`
const currValue = this._getAttributeValueForKey(currAttributeKey);
let interpValue = currValue;
const interpValue = this._getGlanceCardValueForAttributeKey(currAttributeKey);
let currUnits = currName;
if (currUnits == this.kREPLACE_WITH_TEMP_UNITS) {
currUnits = this._getTemperatureScale();
interpValue = this._getScaledTemperatureValue(interpValue);
}
if (currAttributeKey == Constants.RPI_UP_TIME_KEY) {
interpValue = this._filterUptime(currValue);
}
let currIconName = this._cardGlanceIconNames[currName];
if (currAttributeKey == Constants.RPI_FS_USED_PERCENT_KEY) {
currIconName = this._getIconNameForPercent(currValue);
currIconName = this._getIconNameForPercent(interpValue);
}
const currLabelCssID = this._cardGlanceCssIDs[currName];
const currIconCssID = this._cardGlanceIconCssIDs[currName];
// if we have update date, let's carefully format it
if (currAttributeKey == Constants.RPI_LAST_UPDATE_KEY) {
interpValue = this._getUIDateForTimestamp(currValue);
}

let scaleCssID = 'units';
if (currAttributeKey == Constants.RPI_TEMPERATURE_IN_C_KEY) {
scaleCssID = this.kClassIdTempScale;
Expand All @@ -900,7 +936,12 @@ export class RPiMonitorCard extends LitElement {
}

private _getTemperatureScale(): string {
return this._useTempsInC() == true ? 'ºC' : 'ºF';
const scaleInterp = this._useTempsInC() == true ? 'ºC' : 'ºF';
const logMessage = '_getTemperatureScale() scaleInterp=(' + scaleInterp + ')';
if (this._showDebug()) {
console.log(logMessage);
}
return scaleInterp;
}

private _getScaledTemperatureValue(temperature_raw: string): string {
Expand All @@ -909,6 +950,10 @@ export class RPiMonitorCard extends LitElement {
// if not inC convert to F
interpValue = ((parseFloat(temperature_raw) * 9) / 5 + 32.0).toFixed(1);
}
const logMessage = '_getScaledTemperatureValue(' + temperature_raw + ') scaleInterp=(' + interpValue + ')';
if (this._showDebug()) {
console.log(logMessage);
}
return interpValue;
}

Expand Down Expand Up @@ -953,6 +998,21 @@ export class RPiMonitorCard extends LitElement {
return interpValue;
}

private _getGlanceCardValueForAttributeKey(attrKey: string): string {
const latestValue = this._getAttributeValueForKey(attrKey);
let interpValue = latestValue;
if (attrKey == Constants.RPI_LAST_UPDATE_KEY) {
// regenerate the date value
interpValue = this._getUIDateForTimestamp(latestValue);
} else if (attrKey == Constants.RPI_TEMPERATURE_IN_C_KEY) {
// let's scale our temperature value
interpValue = this._getScaledTemperatureValue(latestValue);
} else if (attrKey == Constants.RPI_UP_TIME_KEY) {
interpValue = this._filterUptime(interpValue);
}
return interpValue;
}

private _getUIDateForTimestamp(dateISO: string): string {
const uiDateOptions = {
year: 'numeric',
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface RPiMonitorCardConfig extends LovelaceCardConfig {
fs_severity?: any;
temp_severity?: any;
temp_scale?: string;
name_prefix?: string;

show_warning?: boolean;
show_error?: boolean;
Expand Down

0 comments on commit 111d3ba

Please sign in to comment.