This is my first attempt at a custom control in Home Assistant, and my first post.
So I’ve got this far:
The bottom left of the pair of buttons is supposed to reflect the state of the entity preset (grey = none, white = any other preset and clicking will then go back to none, and dark grey = preset doesn’t exist - one of my radiators (Porch) is different to the others).
This works in javascript
ccol: |-
[[[ if (states[entity.entity_id].attributes.preset_mode == 'none') {
return 'rgba(128,128,128,0.7)';
} else if (!states[entity.entity_id].attributes.preset_mode) {
return 'rgba(0,0,0,0.7)';
} else {
return 'white';
} ]]]
but I then want to disable the button (otherwise you get an error when clicking) - but that requires Jinja - and that’s what I can’t get to work:
Edit - I should clarify - the code ‘works’ as in there are no errors and card-mod is installed - I just can’t get the if statement right - either all buttons are disabled or none are - whereas only the Porch button should be.
style: |
:host {
{% if state_attr('entity.entity_id','preset_mode') is none %}
pointer-events: none;
{% endif %}
}
tap_action:
action: call-service
service: climate.set_preset_mode
service_data:
entity_id: '[[[ return entity.entity_id ]]]'
preset_mode: none
Any help appreciated. Full code below.
Thanks
Andy
button_card_templates:
container:
color_type: label-card
color: dimgray
styles:
card:
- padding: 0
name:
- border-radius: 0.4em 0.4em 0 0
- padding: 0.1em
- width: 100%
- font-weight: bold
grid:
- grid-template-areas: '"i" "n" "buttons"'
- grid-template-columns: 1fr
- grid-template-rows: 1fr min-content min-content
custom_fields:
buttons:
- background-color: rgba(0,0,0,0.3)
- margin: 0
- padding: 0.3em
thermostat:
show_icon: false
hold_action:
action: none
variables:
bcol: |-
[[[
if (states[entity.entity_id].state == 'off') {
return 'rgba(128,128,128,0.7)';
} else {
const t = states[entity.entity_id].attributes.temperature;
switch (true) {
case (t <= 15):
return 'rgba(30,144,255,0.7)';
break;
case (t <= 18):
return 'rgba(0,192,0,0.7)';
break;
case (t >=22):
return 'rgba(255,0,0,0.7)';
break;
default:
return 'rgba(255,165,0,0.9)';
}
}
]]]
tcol: |-
[[[ const t = states[entity.entity_id].attributes.current_temperature;
switch (true) {
case (t <= 15):
return 'rgba(30,144,255,0.9)';
break;
case (t <= 18):
return 'rgba(0,192,0,0.7)';
break;
case (t >=22):
return 'rgba(255,0,0,0.7)';
break;
default:
return 'rgba(255,165,0,0.9)';
}
]]]
icol: |-
[[[ if (states[entity.entity_id].state == 'off') {
return 'rgba(192,192,192,0.7)';
} else {
return 'white';
} ]]]
ccol: |-
[[[ if (states[entity.entity_id].attributes.preset_mode == 'none') {
return 'rgba(128,128,128,0.7)';
} else if (!states[entity.entity_id].attributes.preset_mode) {
return 'rgba(0,0,0,0.7)';
} else {
return 'white';
} ]]]
pcol: '[[[ return ''white''; ]]]'
styles:
card:
- max-width: 48px
- padding: 0
- background-color: inherit
- border-radius: 0
grid:
- grid-template-areas: '"n" "." "current" "." "temp" "." "buttons"'
- grid-template-columns: 1fr
- grid-template-rows: 25px 3px min-content 3px min-content 3px min-content
name:
- font-size: 0.65em
- white-space: normal
- color: white
custom_fields:
temp:
- padding: 0
- margin: 0
current:
- font-size: 0.8em
- white-space: normal
- color: '[[[ return variables.tcol ]]]'
style: |
ha-card { border-width: 0px; }
custom_fields:
temp:
card:
type: custom:button-card
show_icon: false
show_name: false
styles:
card:
- height: 80px
- background-color: '[[[ return variables.bcol ]]]'
grid:
- grid-template-areas: '". up ." ". target ." ". down ."'
- grid-template-columns: 5% 1fr 5%
- grid-template-rows: 1fr 1fr 1fr
custom_fields:
target:
- font-size: 0.8em
- color: '[[[ return variables.icol ]]]'
custom_fields:
up:
card:
type: custom:button-card
icon: fas:play
show_name: false
size: 40%
style: |
ha-card { border-width: 0px; }
styles:
card:
- background-color: inherit
icon:
- color: '[[[ return variables.icol ]]]'
- transform: rotate(270deg)
entity: '[[[ return entity.entity_id ]]]'
tap_action:
action: call-service
service: climate.set_temperature
service_data:
entity_id: '[[[ return entity.entity_id ]]]'
temperature: >-
[[[ return states[entity.entity_id].attributes.temperature
+ 0.5 ]]]
target: >-
[[[ return (states[entity.entity_id].attributes.temperature) +
"°C"; ]]]
down:
card:
type: custom:button-card
icon: fas:play
show_name: false
size: 40%
style: |
ha-card { border-width: 0px; }
styles:
card:
- background-color: inherit
icon:
- color: '[[[ return variables.icol ]]]'
- transform: rotate(270deg) rotateY(180deg)
entity: '[[[ return entity.entity_id ]]]'
tap_action:
action: call-service
service: climate.set_temperature
service_data:
entity_id: '[[[ return entity.entity_id ]]]'
temperature: >-
[[[ return states[entity.entity_id].attributes.temperature
- 0.5 ]]]
buttons:
card:
type: custom:button-card
entity: '[[[ return entity.entity_id ]]]'
show_icon: false
show_name: false
styles:
grid:
- grid-template-areas: '"b1 . b2"'
- grid-template-columns: 1fr 3px 1fr
card:
- background-color: inherit
- padding: 0
- margin: 0
style: |
ha-card { border-width: 0px; }
custom_fields:
b1:
card:
type: custom:button-card
entity: '[[[ return entity.entity_id ]]]'
icon: mdi:cancel
size: 90%
show_name: false
styles:
card:
- background-color: '[[[ return variables.bcol ]]]'
- padding: 0
- margin: 0
icon:
- color: '[[[ return variables.ccol ]]]'
- padding: 0
- margin-top: 0
- margin-left: 0
- margin-right: 0
- margin-bottom: 1px
style: |
:host {
{% if state_attr('entity.entity_id','preset_mode') is none %}
pointer-events: none;
{% endif %}
}
tap_action:
action: call-service
service: climate.set_preset_mode
service_data:
entity_id: '[[[ return entity.entity_id ]]]'
preset_mode: none
b2:
card:
type: custom:button-card
entity: '[[[ return entity.entity_id ]]]'
icon: mdi:power
size: 90%
show_name: false
styles:
card:
- background-color: '[[[ return variables.bcol ]]]'
- padding: 0
- margin: 0
icon:
- color: '[[[ return variables.pcol ]]]'
- padding: 0
- margin-top: 0
- margin-left: 0
- margin-right: 0
- margin-bottom: 1px
tap_action:
action: call-service
service: climate.set_hvac_mode
service_data:
entity_id: '[[[ return entity.entity_id ]]]'
hvac_mode: |-
[[[
if (states[entity.entity_id].state == 'off') {
return 'heat';
} else {
return 'off';
}
]]]
current: >-
[[[ return (states[entity.entity_id].attributes.current_temperature) +
"°C"; ]]]