Skip to content

Commit

Permalink
Merge pull request #1346 from basbruss/update
Browse files Browse the repository at this point in the history
Multiple fixes and optimizations for button-card v4.x.x
  • Loading branch information
basbruss authored Nov 2, 2023
2 parents 846e1ce + 438d60b commit daa2284
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ card_media_player_chromecast:
- "icon_info"
- "blue_not_unavailable"
- "ulm_translation_engine"
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
card_media_player_chromecast_with_controls:
variables:
ulm_card_media_player_with_controls_name: "No name set"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ custom_card_haven_washer_delayed_text:
show_icon: false
show_label: true
show_name: false
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
styles:
state:
- color: "rgba(var(--color-theme),0.9)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ widget_text:
show_icon: false
show_label: true
show_name: false
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
styles:
grid:
- grid-template-areas: "'l'"
Expand Down
30 changes: 15 additions & 15 deletions custom_cards/custom_card_input_number/card_input_number.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ card_input_number:
tap_action:
action: "call-service"
service: |
[[[
if( entity.entity_id.startsWith("input_number.") )
return "input_number.decrement";
if( entity.entity_id.startsWith("counter.") )
return "counter.decrement";
return "";
]]]
[[[
if( entity.entity_id.startsWith("input_number.") )
return "input_number.decrement";
if( entity.entity_id.startsWith("counter.") )
return "counter.decrement";
return "";
]]]
service_data:
entity_id: "[[[ return entity.entity_id ]]]"
icon: "mdi:arrow-down"
Expand All @@ -67,13 +67,13 @@ card_input_number:
tap_action:
action: "call-service"
service: |
[[[
if( entity.entity_id.startsWith("input_number.") )
return "input_number.increment";
if( entity.entity_id.startsWith("counter.") )
return "counter.increment";
return "";
]]]
[[[
if( entity.entity_id.startsWith("input_number.") )
return "input_number.increment";
if( entity.entity_id.startsWith("counter.") )
return "counter.increment";
return "";
]]]
service_data:
entity_id: "[[[ return entity.entity_id ]]]"
icon: "mdi:arrow-up"
Expand All @@ -91,7 +91,7 @@ widget_text:
show_icon: false
show_label: true
show_name: false
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
styles:
grid:
- grid-template-areas: "'l'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ custom_card_irmajavi_entities:
custom_widget_irmajavi:
show_label: true
show_icon: false
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
styles:
name:
- justify-self: "center"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,84 +22,27 @@ ulm_translation_engine:
return (!not_active.includes(entity.state) && !containsNumbers(entity.state))
}
]]]
ulm_translation_hour: >
[[[
var number = hass.resources[hass['language']]["ui.duration.hour"];
var matches = number.match(/[^{\}]+(?=})/g);
var hour = "Hour";
if (matches) {
var hour = matches[1];
}
return(hour);
]]]
ulm_translation_hours: >
[[[
var number = hass.resources[hass['language']]["ui.duration.hour"];
var matches = number.match(/[^{\}]+(?=})/g);
var hour = "Hours";
if (matches) {
var hour = matches[2];
}
return(hour);
]]]
ulm_translation_hvac: >
[[[
if (typeof(entity) !== 'undefined' && entity !== undefined){
let state = entity.state;
let d_class = entity.attributes.device_class;
let def = ["unknown", "unavailable"];
let lang = hass["language"];
let action = entity.attributes.hvac_action;
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
var mode = hass.resources[lang]["state_attributes." + domain + ".hvac_action." + action];
if (def.includes(state)) {
var mode = hass.resources[lang]["state.default." + state ];
}
var label = hass.resources[lang]["component." + domain + ".state._." + state];
var translation = label ? label : state;
return (entity.attributes.current_temperature ) + '°' + ' • ' + translation + ((entity.state !='off' && mode !== undefined) ? ' (' + mode + ')' : '');
}
]]]
ulm_translation_off: "[[[ return hass.resources[hass['language']]['state.default.off']; ]]]"
ulm_translation_on: "[[[ return hass.resources[hass['language']]['state.default.on']; ]]]"
ulm_translation_state: >
[[[
if (typeof(entity) !== 'undefined' && entity !== undefined){
let state = entity.state;
let d_class = entity.attributes.device_class;
let def = ["unknown", "unavailable"];
let device_class = entity.attributes.device_class;
let lang = hass["language"];
let action = entity.attributes.hvac_action;
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state]
let display_precision = hass.entities[entity.entity_id]?.display_precision
const now = new Date();
const timestamp = (new Date(state)).getTime();
const nowTimeStamp = now.getTime();
const microSecondsDiff = Math.round(timestamp - nowTimeStamp);
const daysDiff = Math.round(microSecondsDiff / (1000 * 60 * 60 * 24));
const hoursDiff = Math.round(microSecondsDiff / (1000 * 60 * 60));
const minutesDiff = Math.round(microSecondsDiff / (1000 * 60));
const secondsDiff = Math.round(microSecondsDiff / (1000));
const formatter = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
var scale = 'day'
var diff = daysDiff
if (Math.abs(secondsDiff) < 60){ scale = 'second'; diff = secondsDiff }
else if (Math.abs(minutesDiff) < 60){ scale = 'minute'; diff = minutesDiff }
else if (Math.abs(hoursDiff) < 24){ scale = 'hour'; diff = hoursDiff }
if (def.includes(state)) {
var translation = hass.resources[lang]["state.default." + state ];
}
else if (domain == "binary_sensor" && d_class != ''){
var translation = hass.resources[lang]["component." + domain + ".entity_component." + d_class + ".state." + state]
let mode = hass.resources[lang]["state_attributes." + domain + ".hvac_action." + action];
if(variables.ulm_show_last_changed){
return helpers.relativeTime(entity.last_changed, true)
}
else if (d_class == 'timestamp'){
var translation = formatter.format(diff, scale)
if(device_class == 'timestamp'){
return helpers.relativeTime(entity.state, true)
}
else if (parseFloat(display_precision) >=0){
var translation = parseFloat(entity.state).toFixed(display_precision?.toString())
if(entity.entity_id.startsWith("climate.")){
return helpers.localize(entity, entity.attributes.current_temperature) + ' • ' +
helpers.localize(entity) + ((entity.state !='off' && mode !== undefined) ? ' (' + mode + ')' : '');
}
return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
return helpers.localize(entity)
}
]]]
ulm_translation_state_reverse: >
Expand All @@ -119,59 +62,6 @@ ulm_translation_engine:
return translation ? translation : state;
}
]]]
ulm_translation_state_unit: >
[[[
if (typeof(entity) !== 'undefined' && entity !== undefined){
let state = entity.state;
let d_class = entity.attributes.device_class;
let def = ["unknown", "unavailable"];
let lang = hass["language"];
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
let unit = entity.attributes.unit_of_measurement != null ? " " + entity.attributes.unit_of_measurement : "";
let display_precision = hass.entities[entity.entity_id]?.display_precision
const now = new Date();
const timestamp = (new Date(state)).getTime();
const nowTimeStamp = now.getTime();
const microSecondsDiff = Math.round(timestamp - nowTimeStamp);
const daysDiff = Math.round(microSecondsDiff / (1000 * 60 * 60 * 24));
const hoursDiff = Math.round(microSecondsDiff / (1000 * 60 * 60));
const minutesDiff = Math.round(microSecondsDiff / (1000 * 60));
const secondsDiff = Math.round(microSecondsDiff / (1000));
const formatter = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
var scale = 'day'
var diff = daysDiff
if (Math.abs(secondsDiff) < 60){ scale = 'second'; diff = secondsDiff }
else if (Math.abs(minutesDiff) < 60){ scale = 'minute'; diff = minutesDiff }
else if (Math.abs(hoursDiff) < 24){ scale = 'hour'; diff = hoursDiff }
if(hass.resources[lang]["component." + domain + ".entity_component._.state." + state]){
var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state] + unit
} else {
var translation = state + unit;
}
if (def.includes(state)) {
var translation = hass.resources[lang]["state.default." + state ];
}
else if (domain == "binary_sensor" && d_class != ''){
var translation = hass.resources[lang]["component." + domain + ".entity_component." + d_class + ".state." + state]
}
else if (domain == "media_player" && d_class != ''){
if (state == 'idle' || state == 'paused')
var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state];
else {
var translation = (entity.attributes.source) + ' • ' + ( Math.round(entity.attributes.volume_level / 0.01)) + '%' ;
}
}
else if (d_class == 'timestamp'){
var translation = formatter.format(diff, scale);
}
else if (parseFloat(display_precision) >=0){
var translation = parseFloat(entity.state).toFixed(display_precision?.toString()) + unit
}
return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
}
]]]
ulm_translation_statistics: "[[[ return hass.resources[hass['language']]['ui.components.statistic-picker.statistic']; ]]]"
ulm_translation_unavailable: "[[[ return hass.resources[hass['language']]['state.default.unavailable']; ]]]"
ulm_translation_currency: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ card_graph:
ulm_card_graph_group_by: "interval"
ulm_card_graph_line_width: 5
ulm_card_graph_icon_color: ""
triggers_update: "all"
triggers_update:
- "[[[ return variables.ulm_card_graph_entity2 ]]]"
custom_fields:
item1:
card:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ card_battery:
ulm_card_battery_color_battery_level_warning: "var(--google-yellow)"
ulm_card_battery_color_battery_level_ok: "var(--google-green)"
ulm_outlet_power_enable_popup: false
triggers_update: "all"
triggers_update:
- "[[[ return variables?.ulm_card_battery_battery_state_entity_id ]]]"
- "[[[ return variables?.ulm_card_battery_charger_type_entity_id ]]]"
custom_fields:
item1:
card:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ card_generic:
card:
type: "custom:button-card"
entity: "[[[ return entity.entity_id ]]]"
name: "[[[ return variables.ulm_translation_state_unit ]]]"
name: "[[[ return variables.ulm_translation_state ]]]"
label: "[[[ return variables.ulm_card_generic_name ]]]"
variables: >
[[[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ card_generic_swap:
card:
type: "custom:button-card"
entity: "[[[ return entity.entity_id ]]]"
label: "[[[ return variables.ulm_translation_state_unit ]]]"
label: "[[[ return variables.ulm_translation_state ]]]"
name: "[[[ return variables.ulm_card_generic_swap_name ]]]"
variables: >
[[[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ card_media_player:
ulm_card_media_player_power_button: false
ulm_card_media_player_force_background_color: false
ulm_card_media_player_color: "blue"
triggers_update: "all"
show_icon: false
show_name: false
show_label: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ card_person:
ulm_card_person_use_entity_picture: false
ulm_card_person_icon: "mdi:face-man"
ulm_address: ""
triggers_update: "all"
triggers_update:
- "[[[ return variables.ulm_card_person_entity ]]]"
- "[[[ return variables.ulm_card_person_eta ]]]"
- "[[[ return variables.ulm_address ]]]"
tap_action:
action: "more-info"
entity: "[[[ return variables.ulm_card_person_entity; ]]]"
show_label: true
show_name: true
label: >
[[[
let translation = helpers.localize(entity)
var eta = ""
if (variables.ulm_card_person_eta && states[variables.ulm_card_person_entity].state != 'home'){
eta = " | " + states[variables.ulm_card_person_eta].state + " "+states[variables.ulm_card_person_eta].attributes.unit_of_measurement;
if (variables.ulm_card_person_eta && entity.state != 'home'){
eta = " | " + helpers.localize(states[variables.ulm_card_person_eta]);
}
if (variables.ulm_address){
return states[variables.ulm_address].state + eta
return helpers.localize(states[variables.ulm_address]) + eta;
}
let state = states[variables.ulm_card_person_entity].state;
let option = ["home", "not_home", "unavailable", "unknown"]
return (option.includes(state)) ? variables.ulm_translation_state + eta : state + eta
return translation + eta
]]]
name: "[[[ return states[variables.ulm_card_person_entity].attributes.friendly_name ]]]"
name: "[[[ return entity.attributes.friendly_name ]]]"
entity: "[[[ return variables.ulm_card_person_entity; ]]]"
icon: "[[[ return variables.ulm_card_person_icon; ]]]"
show_entity_picture: "[[[ return variables.ulm_card_person_use_entity_picture ]]]"
entity_picture:
"[[[ return variables.ulm_card_person_use_entity_picture ? states[variables.ulm_card_person_entity].attributes.entity_picture\
"[[[ return variables.ulm_card_person_use_entity_picture ? entity.attributes.entity_picture\
\ : null ]]]"
styles:
icon:
Expand All @@ -58,7 +59,7 @@ card_person:
- line-height: "14px"
- background-color: >
[[[
return (states[variables.ulm_card_person_entity].state !== 'home') ? "rgba(var(--color-green),1)" : "rgba(var(--color-blue),1)";
return (entity.state !== 'home') ? "rgba(var(--color-green),1)" : "rgba(var(--color-blue),1)";
]]]
info:
- position: "absolute"
Expand All @@ -69,12 +70,12 @@ card_person:
custom_fields:
notification: >
[[[
if (states[variables.ulm_card_person_entity].state == 'home') {
if (entity.state == 'home') {
return '<ha-icon icon="mdi:home-variant" style="width: 10px; height: 10px; color: var(--primary-background-color);"></ha-icon>';
} else {
for (let st in states) {
if (st.startsWith("zone.")) {
if (states[st]?.attributes?.persons?.includes(variables.ulm_card_person_entity) && !states[st]?.attributes?.passive) {
if (states[st]?.attributes?.persons?.includes(entity.state) && !states[st]?.attributes?.passive) {
var icon = states[st].attributes.icon !== null ? states[st].attributes.icon : 'mdi:help-circle';
return '<ha-icon icon="' + icon + '" style="width: 10px; height: 10px; color: var(--primary-background-color);"></ha-icon>';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ card_power_outlet:
return 'rgba(var(--color-' + color + '),var(--opacity-bg))';
}
]]]
triggers_update: "all"
triggers_update:
- "[[[ return variables.ulm_card_power_outlet_consumption_sensor ]]]"
custom_fields:
item1:
card:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ card_thermostat:
[[[
var label = variables.ulm_translation_state;
if((entity.attributes.temperature || entity.attributes.target_temp_high != null) && !variables.ulm_card_thermostat_enable_display_temperature){
return variables.ulm_translation_hvac;
return variables.ulm_translation_state;
}
return label;
]]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ card_vacuum:
}
return (colors[state] || colors["default"]);
]]]
triggers_update: "all"
triggers_update:
- "[[[ return variables.ulm_card_vacuum_camera ]]]"
state:
- operator: "template"
value: "[[[ return variables.ulm_active_state ]]]"
Expand Down
Loading

0 comments on commit daa2284

Please sign in to comment.