Skip to content

Commit

Permalink
Merge pull request #6 from moejetz/master
Browse files Browse the repository at this point in the history
Add 'attributes' config option
  • Loading branch information
leinich committed Feb 24, 2020
2 parents e1425cf + 3f37263 commit 1a0edf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
20 changes: 17 additions & 3 deletions MMM-homeassistant-sensors.js
Expand Up @@ -52,7 +52,8 @@ Module.register("MMM-homeassistant-sensors", {
for (var i = 0; i < values.length; i++) {
var icons = values[i].icons[0];
var sensor = values[i].sensor;
var val = this.getValue(data, sensor);
var attributes = values[i].attributes;
var val = this.getValue(data, sensor, attributes);
var name = this.getName(data, sensor);
var unit = this.getUnit(data, sensor);
var alertThreshold = values[i].alertThreshold;
Expand All @@ -79,10 +80,23 @@ Module.register("MMM-homeassistant-sensors", {
}
return wrapper;
},
getValue: function(data, value) {
getValue: function(data, value, attributes=[]) {
for (var i = 0; i < data.length; i++) {
if (data[i].entity_id == value) {
return data[i].state;
if(attributes.length==0) {
return data[i].state;
}
var returnString = ' | ';
for(var j=0; j<attributes.length; j++) {
if(attributes[j] == 'state') {
returnString += data[i].state + ' | ';
} else {
if(data[i]['attributes'][attributes[j]] !== undefined) {
returnString += data[i]['attributes'][attributes[j]] + ' | ';
}
}
}
return returnString.slice(0, -3);
}
}
return null;
Expand Down
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -5,10 +5,10 @@ It can display information from [Home Assistant](https://home-assistant.io/) usi

## Installation

Navigate into your MagicMirror's `modules` folder and clone this repository:
Navigate into your MagicMirror's `modules` folder and clone this repository:
`cd ~/MagicMirror/modules && git clone https://github.com/leinich/MMM-homeassistant-sensors.git`

If you want to use icons for the sensors download the `MaterialDesignIcons` webfont from https://github.com/Templarian/MaterialDesign-Webfont/archive/master.zip and unzip the folder:
If you want to use icons for the sensors download the `MaterialDesignIcons` webfont from https://github.com/Templarian/MaterialDesign-Webfont/archive/master.zip and unzip the folder:
`cd ~/MagicMirror/modules/MMM-homeassistant-sensors && wget https://github.com/Templarian/MaterialDesign-Webfont/archive/master.zip && unzip master.zip`

## Configuration
Expand All @@ -34,11 +34,12 @@ It is very simple to set up this module, a sample configuration looks like this:

## values option

| Option | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `sensor` | `entity_id` from Home Assistant. Please have a look at the states pages for the unique `entity_id` of your sensor |
| `alertThreshold` | As soon as the measured value of the sensor exceeds the configured threshold, the entry will begin to 'blink'. <br><br> **Default:** `off` |
| `icons` | Icons object for the on/off status of sensor. see: [MaterialDesignIcons](https://materialdesignicons.com/) |
| Option | Description |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sensor` | `entity_id` from Home Assistant. Please have a look at the states pages for the unique `entity_id` of your sensor |
| `alertThreshold` | As soon as the measured value of the sensor exceeds the configured threshold, the entry will begin to 'blink'. <br><br> **Default:** `off` |
| `attributes` | Array of sensor attributes to show. If not set, only show sensor state. If set, you can add as many attributes as you want, if you want to show the state as well add `'state'`. <br><br> **Default:** `[]` |
| `icons` | Icons object for the on/off status of sensor. see: [MaterialDesignIcons](https://materialdesignicons.com/) |

## icons option

Expand Down

0 comments on commit 1a0edf0

Please sign in to comment.