I have been struggling with this for a while and am hoping that someone can point me in the right direction.
I got a button card with conditional custom fields which I evaluate based on location variables (based on Minimalist cards. I want to add my sensor.time as a condition in the template but I struggle to understand what the syntax would be after this:
if (states[variables.ulm_card_person_commute_entity]?.state && states[variables.ulm_card_person_entity].state != 'home') ADD TIME SENSOR HERE
With the complete code being:
commute: >
[[[
if (states[variables.ulm_card_person_commute_entity]?.state && states[variables.ulm_card_person_entity].state != 'home') {
var commute = states[variables.ulm_card_person_commute_entity]?.state;
var timeleft = states[variables.ulm_card_person_commute_left]?.state;
var distance = states[variables.ulm_card_person_commute_distance]?.state;
var icon = "ios:car"
var color = "rgba(var(--ios-green))";
if (commute > 30)
{ color = "rgba(var(--ios-orange))";}
else if (commute > 60)
{ color = "rgba(var(--ios-red))";}
return `
<ha-icon icon="${icon}" style="width: 16px; height: 16px; font-size: 14px; color: ${color}; margin: 0 2px 0 0"></ha-icon>
<span style="padding-top: 6px;">Zeit für ${distance}km beträgt ${commute} min</span>
`;
}
else if (states[variables.ulm_card_person_commute_entity]?.state && states[variables.ulm_card_person_entity].state == 'home') {
var towork = states[variables.ulm_card_person_commute_work].state;
var icon = "ios:building";
var color = "rgba(var(--ios-green))";
if (towork > 30)
{ color = "rgba(var(--ios-orange))";}
else if (towork > 60)
{ color = "rgba(var(--ios-red))";}
return `
<ha-icon icon="${icon}" style="width: 16px; height: 16px; font-size: 14px; color: ${color}; margin: 0 2px 0 0"></ha-icon>
<span style="padding-top: 6px;">Arbeitsweg: ${towork} min</span>
`;
}
]]]