@andrey, Hoping you could provide a simple example for what I’m trying to do.
To date, I have been using custom html files to change how switches display in HA. Instead of the slider-looking switch, I prefer to use a paper button element. So my setup that has been working is this:
homeassistant:
customize_glob:
switch.kitchen_light_switch:
custom_ui_state_card: state-card-switch
frontend:
extra_html_url:
- /local/custom_ui/state-card-switch.html
With a file state-card-switch.html
:
<dom-module id="state-card-switch">
<template>
<style is="custom-style" include="iron-flex iron-flex-alignment"></style>
<style>
:host {
line-height: 1.5;
}
paper-button {
width: 85px;
min-width: 30px;
height: 30px;
margin: 5px 0px;
padding: 5px 0px;
font-size: 12px;
background-color: var(--paper-card-background-color);
}
.info {
font-family: var(--paper-font-body1_-_font-family); -webkit-font-smoothing: var(--paper-font-body1_-_-webkit-font-smoothing); font-size: var(--paper-font-body1_-_font-size); font-weight: var(--paper-font-body1_-_font-weight); line-height: var(--paper-font-body1_-_line-height);min-width:10px;white-space:nowrap;float:left
}
.info {
margin-left:16px
}
.name {
white-space: var(--paper-font-common-nowrap_-_white-space); overflow: var(--paper-font-common-nowrap_-_overflow); text-overflow: var(--paper-font-common-nowrap_-_text-overflow);color:var(--primary-text-color);line-height:40px
}
.on {
color: var(--paper-item-icon-active-color);
border: 1px solid var(--paper-item-icon-active-color);
}
.off {
color: var(--secondary-text-color);
border: 1px solid var(--secondary-text-color);
}
.badge {
position:relative;display:inline-block;width:40px;border-radius:50%;height:40px;text-align:center;background-size:cover;line-height:40px
}
</style>
<div class='horizontal justified layout'>
<div class='horizontal start-justified layout'>
<div class="badge">
<state-badge class="badge" state-obj="[[stateObj]]"></state-badge>
</div>
<div class="info">
<div class="name" in-dialog>[[friendlyName]]</div>
</div>
</div>
<paper-button-group on-click="stopPropagation">
<paper-button
class="on"
on-tap='handleOnTap'
hidden$='[[!onButtonVisible]]'>On</paper-button>
<paper-button
class="off"
on-tap='handleOffTap'
hidden$='[[!offButtonVisible]]'>Off</paper-button>
</paper-button-group>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'state-card-switch',
properties: {
hass: {
type: Object,
},
stateObj: {
type: Object,
observer: 'stateObjChanged',
},
onButtonVisible: {
type: Boolean,
value: false,
},
offButtonVisible: {
type: Boolean,
value: false,
},
friendlyName: {
type: String,
value: 'unknown',
},
},
stateObjChanged: function (newVal) {
if (newVal) {
if (newVal.state == 'on') {
this.onButtonVisible = true;
this.offButtonVisible = false;
this.friendlyName = this.stateObj.attributes.friendly_name;
} else if (newVal.state == 'off') {
this.onButtonVisible = false;
this.offButtonVisible = true;
this.friendlyName = this.stateObj.attributes.friendly_name;
this.timeAgo = this.stateObj.last_changed;
}
}
},
handleOnTap: function (e) {
var serviceData = {entity_id: this.stateObj.entity_id}
this.hass.callService('switch', 'turn_off', serviceData);
},
handleOffTap: function (e) {
var serviceData = {entity_id: this.stateObj.entity_id}
this.hass.callService('switch', 'turn_on', serviceData);
},
stopPropagation: function (e) {
e.stopPropagation();
},
});
</script>
However, if I try to switch to this configuration:
homeassistant:
customize_glob:
"*.*":
custom_ui_state_card: state-card-custom-ui
switch.kitchen_light_switch:
show_last_changed: true
state_card_custom_ui_secondary: state-card-switch
frontend:
extra_html_url:
- /local/custom_ui/state-card-custom-ui.html
- /local/custom_ui/state-card-switch.html
The entire element then disappears from the UI, possibly similar to what @maurizio53 was experiencing? . If I comment out the secondary html option, the switch shows up in the UI with the time since last change, as expected. I’m assuming this behavior is due to the custom html file I’m using for the switch. Which elements of the custom html file need to exist in order to have the state_card_custom_ui_secondary
option work properly? My goal is to combine some of the CustomUI features (ie time since last change) with some custom cosmetic changes. Any thoughts would be much appreciated. Perhaps even a template secondary html file could be added to the Github docs.