and see if it works like you want. Otherwise specify a little more, or just show a picture of what it looks with this code, and what you want to have in the end.
After looking at it again, my guess would be the aspect_ratio. Remove the aspect ratio and see how hard it hits the design ⊠Iâm quite sure, youâre limiting the resize (because of the aspect_ratio) and therefor it getâs cut in smaller windows.
Try experimenting with it in the browser window, where you can make the window bigger and smaller to see the result.
EDIT: Google Chrome has a good develper tool, there you can view your layout in different sizes (pre-configured)
Thatâs unfortunate, but it is the source of the display problemâŠ
Iâd say youâd have to start again, as with aspect_ratio you wonât get the result you wanted. I can only speak for the Minimalist âthemeâ, and there the alarm card is handled a lot different than other cards. You might want to take a look at the alarm_card clemalex made, maybe this helps you?
Hi,
I have the following issue:
In order to display an adress I readout the subattribute of a places sensor:
var street = states['sensor.joergs_location'].attributes.street
Sometimes, this attribute is null.
Then an error appears:
ButtonCardJSTemplateError: TypeError: Cannot read properties of null (reading 'substring') in 'var street = states['sensor.joergs_location'].attributes.street var number = states['sensor.jo...'
How can I manage this error so that the card is simply displayed with âunknownâ?
I tried to insert an if clouse 'If states[âsensor.joergs_locationâ].attributes.street is not null or != null
That doesnât work. Has anybody an idea?
Maybe for better understanding, the whole code looks like this and basically works:
name: |
[[[
var street = states['sensor.joergs_location'].attributes.street
var number = states['sensor.joergs_location'].attributes.street_number
street = street.substring(0,30)
if (states['sensor.joergs_location'].attributes.devicetracker_zone == 'not_home')
return street + ' ' + number;
else return states['person.jorg'].state;
]]]
label: |
[[[
var town = states['sensor.joergs_location'].attributes.city
var postal = states['sensor.joergs_location'].attributes.postal_town
town = town.substring(0,30)
postal = postal.substring(0,30)
if (town == '-') return postal;
else return town;
]]]
thats probably because the entity doesnt exist or has unknown/unavailable state. you need to test for that:
[[[ if (entity && entity.attributes && entity.attributes.templates) {
const tpl = entity.attributes.templates;
if (tpl.icon_color) {
return new Function('state', `'use strict'; ${tpl.icon_color}`).call(this, entity.state);
}
}
return null; ]]]
sorry if this is a bit of a complex example, but the crux is in the first lineâŠ
also you might be better of by setting the var to states['sensor.joergs_location'] and reference that in the rest of the template, to make it shorter and more readable
I understand, that you check if the entity is valid in the first if clause.
But my problem is, that the entity is valid but the content of the attribute is null.
in other languages, I can simply check with a function like âISNULL(value) = trueâ
I tried this
or if it does exist but still throws the error of null or none, you should check if the entity.state is not in [âunavailableâ,âunknownâ]. In fact you should always do thatâŠ
like this in jinja templates for automation conditions:
condition:
# first check if the state (the entity) itself exists
- >
{{trigger.to_state is not none and
trigger.from_state is not none}}
# next check if the states state is not unknown
- >
{% set x = ['unavailable','unknown'] %}
{{trigger.to_state.state not in x and
trigger.from_state.state not in x}}
# finally check if the old and new states are not identical
- >
{{trigger.to_state.state != trigger.from_state.state}}
[[[
if (!states['sensor.yvonnes_location'].attributes.street) return 'unknown';
else
var street = states['sensor.yvonnes_location'].attributes.street
var number = states['sensor.yvonnes_location'].attributes.street_number
street = street.substring(0,30)
if (states['sensor.yvonnes_location'].attributes.devicetracker_zone == 'not_home')
return street + ' ' + number;
else return states['person.yvonne'].state;
]]]
result is the error described above, because the entity is valid but the attribute âstreetâ returns null and that cannot be computed.
All what I need is a method that handles this return value.
if states['sensor.yvonnes_location'].attributes.street is null return 'unknown';
hmm, ok, so the entity exists, it even has a state, but none of the attributes has a valid value.
simple check for ânullâ on the attributes, where you now check for âunknownâ
or maybe even better the integration. that creates these entities ⊠which is that?
you can check the template editor in dev tools with a jinja template
{{state_attr('sensor.yvonnes_location','street')}} and {{is_state_attr('sensor.yvonnes_location','street','null')}} to see if it actually returns the string ânullâ ? Or whether it is in fact not yet set, and thus still null (so not the string), in which case you can check for none
{% set joerg = states.sensor.joergs_location.attributes %}
{% if states('sensor.joergs_location') != 'not_home' %}
{% if joerg.street is none %}
{% set street = 'unknown' %}
{% else %}
{% set street = joerg.street %}
{% endif %}
{% if joerg.street_number is not none %}
{% set number = joerg.street_number %}
{% endif %}
{{ street }} {{ number }}
{% else %}
{{ states('sensor.joergs_location') }}
{% endif %}