8000 climate support, actions for resources, editor refactor, HACS support by Wetzel402 · Pull Request #29 · postlund/home-card · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

climate support, actions for resources, editor refactor, HACS support #29

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

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6363613
Added new ranch home theme
Wetzel402 Jul 29, 2019
db6c0ca
Delete ranch_home.png
Wetzel402 Jul 29, 2019
347b2c3
Added ranch home theme
Wetzel402 Jul 29, 2019
26a6cce
Update README.md
Wetzel402 Aug 1, 2019
3a7132d
Update README.md
Wetzel402 Aug 1, 2019
884041c
Update README.md
Wetzel402 Aug 1, 2019
2a7a910
Update README.md
Wetzel402 Aug 1, 2019
2d03cd1
Update README.md
Wetzel402 Aug 1, 2019
fd6e25d
Update README.md
Wetzel402 Aug 1, 2019
9776e58
Update README.md
Wetzel402 Aug 1, 2019
b44bbaf
Added climate object, updated resource objects
Wetzel402 Mar 2, 2022
2c74407
Update README.md
Wetzel402 Mar 2, 2022
c6adbd1
Merge branch 'postlund:master' into master
Wetzel402 Mar 2, 2022
428d426
Create hacs.json
Wetzel402 Mar 2, 2022
f10fc30
Update README.md
Wetzel402 Mar 2, 2022
78e280b
Update hacs.json
Wetzel402 Mar 2, 2022
0564d51
Update hacs.json
Wetzel402 Mar 2, 2022
f0c111d
Create placeholder.txt
Wetzel402 Mar 2, 2022
80bd635
Rename home-card-editor.js to dist/home-card-editor.js
Wetzel402 Mar 2, 2022
85b7e88
Rename home-card.js to dist/home-card.js
Wetzel402 Mar 2, 2022
3bb15ad
Rename themes.js to dist/themes.js
Wetzel402 Mar 2, 2022
4c95440
Create placeholder.txt
Wetzel402 Mar 2, 2022
55a34cf
Create placeholder.txt
Wetzel402 Mar 2, 2022
0be91d0
Add files via upload
Wetzel402 Mar 2, 2022
146021b
Add files via upload
Wetzel402 Mar 2, 2022
8565a55
Delete themes directory
Wetzel402 Mar 2, 2022
a6a60da
Delete placeholder.txt
Wetzel402 Mar 2, 2022
51846e9
Delete placeholder.txt
Wetzel402 Mar 2, 2022
3b21ac6
Delete placeholder.txt
Wetzel402 Mar 2, 2022
1cdf44d
Update README.md
Wetzel402 Mar 2, 2022
a377591
Delete dist/ranch_with_three_stall_garage directory
Wetzel402 Mar 2, 2022
f58699e
Delete dist/two_story_with_garage directory
Wetzel402 Mar 2, 2022
1e57ebe
Create placeholder.txt
Wetzel402 Mar 2, 2022
87c51b8
Create placeholder.txt
Wetzel402 Mar 2, 2022
5f97990
Delete placeholder.txt
Wetzel402 Mar 2, 2022
27c3a2d
Add files via upload
Wetzel402 Mar 2, 2022
d08717b
Delete placeholder.txt
Wetzel402 Mar 2, 2022
6e23bf0
Create placeholder.txt
Wetzel402 Mar 2, 2022
5de6399
Add files via upload
Wetzel402 Mar 2, 2022
4fc77f9
Delete placeholder.txt
Wetzel402 Mar 2, 2022
ecbaadf
Update home-card.js
Wetzel402 Mar 2, 2022
18f5ad4
Update home-card.js
Wetzel402 Mar 2, 2022
ce1b451
Update README.md
Wetzel402 Mar 3, 2022
58efdf9
Update home-card-editor.js
Wetzel402 Mar 9, 2022
d18f27f
Update home-card.js
Wetzel402 Mar 9, 2022
b64a03e
Update home-card.js
Wetzel402 Apr 4, 2023
2676460
Update home-card.js
Wetzel402 Apr 4, 2023
cab77a4
Update home-card.js
Wetzel402 Apr 4, 2023
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
68 changes: 25 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Home Card

[![hacs_badge](https://img.shields.io/badge/HACS-Custom-41BDF5.svg?style=for-the-badge)](https://github.com/hacs/integration)

A quick glance of the state of your home in [Home Assistant](https://github.com/home-assistant/home-assistant) Lovelace UI.

![Demo of card](images/demo.gif)
Expand Down Expand Up @@ -33,42 +35,8 @@ Some things I want to add in upcoming releases:

## Install

### Simple Install

1. Download `home-card.js`, `themes.js` and `themes` and copy them into `config/www/home-card` (create the `home-card` directory)

2. Add a reference to `home-card/home-card.js` inside your `ui-lovelace.yaml`

```yaml
resources:
- url: /local/home-card/home-card.js?v=0
type: module
```

### Git Install

1. Clone this repository into your `www`-directory: `git clone https://github.com/postlund/home-card.git`

2. Add a reference to `home-card/home-card.js` inside your `ui-lovelace.yaml`

```yaml
resources:
- url: /local/home-card/home-card.js?v=0
type: module
```

### Custom updater

Not using this yet...

## Updating

If you...

* manually copied the files, just download the latest files and overwrite what you already have
* cloned the repository from Github, just do `git pull` to update

... and increase `?v=X` to `?vX+1`.
### HACS
Add this repository in HACS, download, and install.

## Using the card

Expand All @@ -94,6 +62,7 @@ Both the weather and resources areas are optional and will not displayed if omit
| theme | string | **required** | Name of a theme, see [supported themes](#supported-themes)
| background | string | transparent | Supported values: empty, `transparent`, `paper-card`
| weather | string | optional | `weather` entity used for displaying location and temperature
| climate | object | optional | `climate` entity used for displaying interior temperature
| entities | object | optional | List of [entity objects](#entity-object)
| resources | object | optional | List of [resource objects](#resource-object)
| custom_themes | object | optional | List of [theme objects](#theme-object)
Expand All @@ -102,9 +71,10 @@ Both the weather and resources areas are optional and will not displayed if omit

The following themes and overlays are currently supported:

| Theme | Overlays |
|------|----------|
| two_story_with_garage | door, garage, outside_light, upstairs_light, downstairs_light, car, sprinkler
| Image | Theme | Overlays |
:------:|:-----:|:---------:
![thumb](images/structure.png?s=100) | two_story_with_garage | door, garage, outside_light, upstairs_light, downstairs_light, car, sprinkler
![thumb](images/ranch_home.png?s=100) | ranch_with_three_stall_garage | door, garage, garage2, outside_light, upstairs_light, downstairs_light(not implemented), car, car2, car3, sprinkler

These states are supported by the overlays:

Expand Down Expand Up @@ -151,13 +121,20 @@ A `resource` is a simple sensor that is displayed beneath the house, e.g. a temp
| entity | string | **required** | An entity from Home Assistant, e.g, `sensor.water_usage`
| icon | string | optional | Override icon to use, e.g. `mdi:car`
| unit_of_measurement | string | optional | Override unit of measurement, e.g. `lux`
| state_map | map | optional | Key-value map of state (in Home Assistant) to overlay state

A simple example of a resource object in yaml looks like this:

```yaml
- entity: sensor.water_usage
icon: mdi:water
unit_of_measurement: liter
resources:
- entity: alarm_control_panel.alarm
state_map:
armed_away: Armed
disarmed: Standby
armed_home: Home mode
tap_action:
action: navigate
navigation_path: /lovelace/security
```

This object supports custom [tap and hold actions](#tap-and-hold-actions).
Expand Down Expand Up @@ -216,6 +193,11 @@ Simple example using basic features:
icon: 'mdi:alarm-light'
- entity: sensor.outside_temperature
icon: 'mdi:thermometer'
climate:
- entity: climate.hallway
tap_action:
action: navigate
navigation_path: /lovelace/climate
```

#### Using custom tap and hold actions
Expand Down Expand Up @@ -331,4 +313,4 @@ The excellent `clear` theme is used in demo graphics, you can find it here:

https://community.home-assistant.io/t/clear-theme/100464

Background image is linked from the same page as well.
Background image is linked from the same page as well.
143 changes: 143 additions & 0 deletions dist/home-card-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { THEMES } from './themes.js';

const LitElement = Object.getPrototypeOf(
customElements.get("ha-panel-lovelace")
);
const html = LitElement.prototype.html;

export const fireEvent = (node, type, detail = {}, options = {}) => {
const event = new Event(type, {
bubbles: options.bubbles === undefined ? true : options.bubbles,
cancelable: Boolean(options.cancelable),
composed: options.composed === undefined ? true : options.composed,
});

event.detail = detail;
node.dispatchEvent(event);
return event;
};

export class HomeCardEditor extends LitElement {

static get properties() {
return { hass: {}, _config: {} };
}

setConfig(config) {
this._config = config;
}

get getWeathers() {
const weathers = Object.keys(this.hass.states).filter(eid => {
return ['weather'].includes(eid.substr(0, eid.indexOf('.')));
});

weathers.sort();
return weathers;
}
/*
get getClimates() {
const climates = Object.keys(this.hass.states).filter(eid => {
return ['climate'].includes(eid.substr(0, eid.indexOf('.')));
});

climates.sort();
return climates;
}
*/
firstUpdated() {
this._firstRendered = true;
}

render() {
if (!this.hass) {
return html``;
}

const weathers = this.getWeathers.map(entity => {
return html`<paper-item>${entity}</paper-item>`;
});
/*
const climates = this.getClimates.map(entity => {
return html`<paper-item>${entity}</paper-item>`;
});
*/
return html`
<div class="card-config">
${this.make_dropdown("Theme", "theme", Object.keys(Object.assign({}, THEMES, this._config.custom_themes)))}

${this.make_dropdown("Background", "background", ["transparent", "paper-card"])}

<paper-dropdown-menu
label="Weather (optional)"
@value-changed="${this.configChanged}"
.configValue="${'weather'}"
>
<paper-listbox
slot="dropdown-content"
.selected="${this.getWeathers.indexOf(this._config.entity)}"
>
${weathers}
</paper-listbox>
</paper-dropdown-menu>

</div>
`;
}

/*
<paper-dropdown-menu
label="Climate (optional)"
@value-changed="${this.configChanged}"
.configValue="${'climate'}"
>
<paper-listbox
slot="dropdown-content"
.selected="${this.getClimates.indexOf(this._config.entity)}"
>
${climates}
</paper-listbox>
</paper-dropdown-menu>

</div>
`;
}
*/
make_dropdown(label, configValue, items) {
var selected = Math.max(0, items.indexOf(this._config[configValue]));
return html`
<div>
<paper-dropdown-menu
label="${label}"
.configValue="${configValue}"
@value-changed="${this.configChanged}">
<paper-listbox slot="dropdown-content" selected="${selected}">
${items.map(
(name) => html`
<paper-item>${name}</paper-item>
`
)}
</paper-listbox>
</paper-dropdown-menu>
</div>
`;
}

configChanged(ev) {
if (!this._config || !this.hass || !this._firstRendered) return;
const {
target: { configValue, value },
detail: { value: checkedValue },
} = ev;

if (checkedValue !== undefined || checkedValue !== null) {
this._config = { ...this._config, [configValue]: checkedValue };
} else {
this._config = { ...this._config, [configValue]: value };
}

fireEvent(this, 'config-changed', { config: this._config });
}
}

customElements.define("home-card-editor", HomeCardEditor);
52 changes: 46 additions & 6 deletions home-card.js → dist/home-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import {
css,
} from 'https://unpkg.com/lit-element@2.0.1/lit-element.js?module';

const VERSION = 4;
const VERSION = 4.1;

console.info(
`%c HOME-CARD \n%c Version ${VERSION} `,
'color: orange; font-weight: bold; background: black',
'color: white; font-weight: bold; background: dimgray'
);

// From weather-card
const fireEvent = (node, type, detail, options) => {
Expand Down Expand Up @@ -85,8 +91,9 @@ class HomeCard extends LitElement {

make_content() {
var weather = "";
var climate = "";
var resources = "";

if (this.config.weather) {
var weatherObj = this.stateObject('weather', this.config.weather);
weather = html `
Expand All @@ -98,6 +105,13 @@ class HomeCard extends LitElement {
</span>
</div>`;
}

if (this.config.climate) {
climate = html `
<div id="weather">
${this.config.climate.map(climate => this.make_climate(climate))}
</div>`;
}

if (this.config.resources) {
resources = html `
Expand All @@ -109,6 +123,7 @@ class HomeCard extends LitElement {
return html `
<div id="root">
${weather}
${climate}
<div id="house">
<img id="house-image" src="${this.imgPath(this.theme.house)}" />
${this.make_entities()}
Expand All @@ -117,18 +132,37 @@ class HomeCard extends LitElement {
</div>
`;
}

make_climate(climate) {
var climateObj = this.stateObject('climate', climate.entity);

return html `
<span id="weather-info">
<span @mousedown="${ev => this._down(climate)}"
@touchstart="${ev => this._down(climate)}"
@mouseup="${ev => this._up(climate, true)}">
${"Interior "}
${climateObj.attributes.current_temperature}${this.hass.config.unit_system.temperature}
</span>
`;
}

make_resource(resource) {
var stateObj = this.stateObject('resources', resource.entity);
var state = stateObj.state;
if (resource.state_map && stateObj.state in resource.state_map) {
state = resource.state_map[stateObj.state];
}

return html `
<span @mousedown="${ev => this._down(resource)}"
@touchstart="${ev => this._down(resource)}"
@mouseup="${ev => this._up(resource, false)}">
@mouseup="${ev => this._up(resource, true)}">
<span class="icon">
<ha-icon icon="${resource.icon || this.get_attribute(stateObj, 'icon', 'mdi:help-rhombus')}" />
</span>
<span>${Math.round(stateObj.state) || stateObj.state}</span>
<span>${resource.unit_of_measurement || this.get_attribute(stateObj, 'unit_of_measurement', '')}</span>
<span>${Math.round(state) || state}</span>
<span>${resource.unit_of_measurement || this.get_attribute(stateObj, 'unit_of_measurement', '')}</span>
</span>
</span>
`;
Expand Down Expand Up @@ -188,7 +222,7 @@ class HomeCard extends LitElement {
}

imgPath(filename) {
return `/local/home-card/themes/${this.config.theme}/${filename}?v=${VERSION}`;
return `/local/community/home-card/themes/${this.config.theme}/${filename}?v=${VERSION}`;
}

stateObject(source, entity_id) {
Expand Down Expand Up @@ -368,3 +402,9 @@ class HomeCard extends LitElement {
}

customElements.define('home-card', HomeCard);
window.customCards = window.customCards || [];
window.customCards.push({
type: 'home-card',
name: 'Home Card',
description: 'A graphical representation of your home with different themes',
});
2 changes: 1 addition & 1 deletion themes.js → dist/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,4 @@ export const THEMES = {
},
},
},
};
};
5 changes: 5 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "home-card",
"render_readme": true,
"filename": "home-card.js"
}
Loading
0