diff --git a/dashboard.png b/dashboard.png new file mode 100644 index 0000000..5dc81a0 Binary files /dev/null and b/dashboard.png differ diff --git a/dimmer-button.js b/dimmer-button.js index e49b1e2..ed5671d 100644 --- a/dimmer-button.js +++ b/dimmer-button.js @@ -2,13 +2,16 @@ //Add automatic area on
when supported
//value template support
//Select mode color
+//iOS fix?
+//Dynamic backgrounds
+//Group color options in config
import {
LitElement,
html,
css
} from "https://unpkg.com/lit-element@2.0.1/lit-element.js?module";
-console.info('%c DIMMER-BUTTON %c 0.3 ','color: antiquewhite; background: #B565C6;','color: salmon; background: gray;');
+console.info('%c DIMMER-BUTTON %c 0.4 ','color: antiquewhite; background: #B565C6;','color: salmon; background: gray;');
class DimmerButton extends LitElement {
@@ -20,7 +23,7 @@ class DimmerButton extends LitElement {
}
static getStubConfig() {
- return { entity: '#Required',name: '#friendly_name',mode: '#supports "brightness" or "color_temp" for light and "volume" for media_player', direction: "horizontal", bottom: "#optional text under name", height: "",background: "",foreground: "",icon: "",on_icon: "",off_icon: "",on_color: "",off_color: "" }
+ return { entity: '#Required',name: '#friendly_name',mode: '#supports "brightness" or "color_temp" for light and "volume" for media_player', direction: "horizontal", bottom: "#optional text under name", height: "",background: "",foreground: "",icon: "",on_icon: "",off_icon: "",on_color: "",off_color: "", text_color: "" }
}
constructor() {
@@ -51,23 +54,21 @@ class DimmerButton extends LitElement {
if(entity.entity_id.includes("light.")||entity.entity_id.includes("switch.")) {
this.iconOn = this.config.icon ? this.config.icon : this.config.on_icon ? this.config.on_icon : entity.attributes.icon ? entity.attributes.icon : entity.entity_id.includes("light.") ? "hass:lightbulb" : "mdi:toggle-switch";
this.iconOff = this.config.icon ? this.config.icon : this.config.off_icon ? this.config.off_icon : entity.attributes.icon ? entity.attributes.icon : entity.entity_id.includes("light.") ? "hass:lightbulb-outline" : "mdi:toggle-switch-off-outline";
- if(entity.attributes.supported_features & 1) {
- if(entity.attributes.supported_features & 2 && this.config.mode == "color_temp"){
- this.mode = "color_temp";
- this.displayState = entity.state === "on" ? ('• '+(this.newValue != 0 ? Math.round(1000000/(((entity.attributes.max_mireds-entity.attributes.min_mireds)*(this.newValue/100))+entity.attributes.min_mireds))+' K' : Math.round((1000000/(entity.attributes.color_temp)))+' K')) : '';
- this.rangeValue = entity.state === "on" ? Math.round(((entity.attributes.color_temp-entity.attributes.min_mireds)*100)/(entity.attributes.max_mireds-entity.attributes.min_mireds)) : 0;
- }else{
- this.mode = "brightness";
- this.displayState = '• '+(this.newValue != 0 ? this.newValue : (entity.state === "on" ? Math.round(entity.attributes.brightness/2.55) : 0))+'%';
- this.rangeValue = entity.state === "on" ? Math.round(entity.attributes.brightness/2.55) : 0;
- }
+ if(this.config.mode == "color_temp"){
+ this.mode = "color_temp";
+ this.displayState = entity.state === "on" && entity.attributes.color_temp ? ('• '+(this.newValue != 0 ? Math.round(1000000/(((entity.attributes.max_mireds-entity.attributes.min_mireds)*(this.newValue/100))+entity.attributes.min_mireds))+' K' : Math.round((1000000/(entity.attributes.color_temp)))+' K')) : '';
+ this.rangeValue = entity.state === "on" ? Math.round(((entity.attributes.color_temp-entity.attributes.min_mireds)*100)/(entity.attributes.max_mireds-entity.attributes.min_mireds)) : 0;
+ }else if(this.config.mode == "brightness"){
+ this.mode = "brightness";
+ this.displayState = '• '+(this.newValue != 0 ? this.newValue : (entity.state === "on" && entity.attributes.brightness ? Math.round(entity.attributes.brightness/2.55) : 0))+'%';
+ this.rangeValue = entity.state === "on" ? Math.round(entity.attributes.brightness/2.55) : 0;
}else{
this.mode = "toggle";
this.displayState = '';
this.rangeMax = 1;
this.rangeValue = entity.state === "on" ? 1 : 0;
}
- }else if(entity.entity_id.includes("sensor.")){
+ }else if(entity.entity_id.includes("sensor.")||entity.entity_id.includes("device_tracker.")){
this.iconOn = this.config.icon ? this.config.icon : this.config.on_icon ? this.config.on_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:eye";
this.iconOff = this.config.icon ? this.config.icon : this.config.off_icon ? this.config.off_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:eye";
this.mode = "static";
@@ -76,9 +77,11 @@ class DimmerButton extends LitElement {
}else if(entity.entity_id.includes("media_player.")){
this.iconOn = this.config.icon ? this.config.icon : this.config.on_icon ? this.config.on_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:cast";
this.iconOff = this.config.icon ? this.config.icon : this.config.off_icon ? this.config.off_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:cast";
- if(entity.attributes.supported_features & 4 && this.config.mode == "volume") {
+ this.rangeMax = 1;
+ this.rangeValue = entity.state === "on" ? 1 : 0;
+ if(this.config.mode == "volume") {
this.mode = "volume";
- this.displayState = (entity.state === "playing" ? '• '+(this.newValue != 0 ? this.newValue : Math.round((entity.attributes.volume_level*100)))+'%' : '');
+ this.displayState = (entity.state === "playing" && entity.attributes.volume_level ? '• '+(this.newValue != 0 ? this.newValue : Math.round((entity.attributes.volume_level*100)))+'%' : '');
this.maxVol = this.config.max_volume ? this.config.max_volume : 100;
this.rangeMax = this.maxVol;
this.rangeValue = (entity.attributes.volume_level*100);
@@ -90,6 +93,8 @@ class DimmerButton extends LitElement {
}
}else{
this.mode = "static";
+ this.iconOn = this.config.icon ? this.config.icon : this.config.on_icon ? this.config.on_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:help-circle";
+ this.iconOff = this.config.icon ? this.config.icon : this.config.off_icon ? this.config.off_icon : entity.attributes.icon ? entity.attributes.icon : "mdi:help-circle-outline";
}
}
@@ -97,6 +102,7 @@ class DimmerButton extends LitElement {
const entity = this.config.entity;
const entityStates = this.hass.states[entity]
const name = this.config.name ? this.config.name : entityStates.attributes.friendly_name;
+ const textColor = this.config.text_color ? this.config.text_color : "var(--primary-text-color)";
const onColor = this.config.on_color ? this.config.on_color : "#fdd835";
const offColor = this.config.off_color ? this.config.off_color : "gray";
const cardHeight = this.config.height ? this.config.height : "150px";
@@ -111,8 +117,9 @@ class DimmerButton extends LitElement {
return html`