Skip to content

Commit

Permalink
Complete overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Dec 10, 2019
1 parent a64a9b4 commit 5495c5b
Show file tree
Hide file tree
Showing 10 changed files with 4,245 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
state-switch.js binary
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Thomas Lovén

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 45 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
state-switch
============
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

Allows you to display different cards depending on the state of an entity, the currently logged in user or the current device-browser combination
Dynamically replace lovelace cards depending on occasion.

![state-switch mov](https://user-images.githubusercontent.com/1299821/48923691-05479700-eeb1-11e8-8c8b-91ea14cfecf1.gif)

> Note in the animation above that the two browser windows have two different users logged in, which changes the rightmost card.
## Installation
This card requires [card-tools](https://github.com/thomasloven/lovelace-card-tools) to be installed.

For installation instructions [see this guide](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins).

## Options
Install `state-switch.js` as a `module`.

```yaml
resources:
- url: /local/state-switch.js
type: module
```
## Usage
```yaml
type: custom:state-switch
entity: <entity>
default: <default>
states:
<state 1>:
<card 1>
<state 2>:
<card 2>
...
```

When the state of `<entity>` is `<state 1>`, `<card 1>` will be displayed, when it's `<state 2>`, `<card 2>` will be displayed.

| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| type | string | **Required** | `custom:state-switch`
| entity | string | **Required** | Controlling entity id, `hash`, `user` or `browser`
| states | object | **Required** | Map of states to cards to display
| default | string | none | State to use as default
If the state of `<entity>` doesn't match any `<state>`, the `<card>` for the `<default>` state will be displayed.

## Options
- `<entity>` **Required** An entity id or `hash`, `user`, `deviceID`
- `<default>` State to use as default fallback
- `<state N>` The state to match
- `<card N>` Lovelace card configuration

The `entity` parameter can take four different types of value
## State matching

### Entity\_id
### entity\_id
If the `entity` parameter is set to an entity id, which card is displayed will depend on the state of that entity.

```yaml
Expand Down Expand Up @@ -143,16 +164,14 @@ If the `entity` parameter is set to `user`, which card is displayed will depend
## Unknown user
```

### browser
If the `entity` parameter is set to `browser`, which card is displayed will depend on the device-browser combination which is currently displaying the page.
### deviceID
If the `entity` parameter is set to `deviceID`, which card is displayed will depend on the device-browser combination which is currently displaying the page.

This "browser ID" is in the form of a 16 character string with a dash in the middle and is unique, random and persistent for the browser.

If the `default` parameter is **not** set, the default behavior will be to display a small card containing the browser ID.
See [browser_mod](https://github.com/thomasloven/hass-browser_mod#devices) for a description on how deviceIDs work.

```yaml
- type: custom:state-switch
entity: browser
entity: deviceID
states:
'9c2aaf6f-ed26e3c1':
type: markdown
Expand All @@ -163,3 +182,10 @@ If the `default` parameter is **not** set, the default behavior will be to displ
content: >
Mobile
```

## A few tips

- To replace more than one card at a time, use e.g. [`vertical-stack`](https://www.home-assistant.io/lovelace/vertical-stack/), [`horizontal-stack`](https://www.home-assistant.io/lovelace/horizontal-stack/) or [`layout-card`](https://github.com/thomasloven/lovelace-layout-card).

---
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
4 changes: 4 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "state-switch",
"render_readme": true
}
Loading

0 comments on commit 5495c5b

Please sign in to comment.