Hi! First of all, thank you for your response! Here you go:
This is the code of the chore.yaml that I created
{% set entity = 'sensor.'+sensor_name %}
type: 'custom:button-card'
name: {{name}}
entity: {{entity}}
label: >
[[[ return variables.var.label ]]]
show_label: true
icon: >
[[[ return variables.var.icon ]]]
custom_fields:
status: >
[[[ return '<span style="display: inline-block; color: white; background: '+variables.var.color+'; padding: 0 5px; border-radius: 5px;">'+variables.var.days_left+'</span>' ]]]
styles:
grid:
- grid-template-areas: '"i n status" "i l status"'
- grid-template-columns: 15% 1fr 1fr
- grid-template-rows: 1fr 1fr
icon:
- color: >
[[[ return variables.var.color ]]]
label:
- color: var(--disabled-text-color)
- justify-self: start
name:
- justify-self: start
variables:
var: >
[[[
let colors = {};
colors["success"] = "#8BC24A";
colors["warning"] = "#FFC107";
colors["error"] = "#FF5252";
colors["disabled"] = "var(--disabled-text-color)";
let result = {};
result.label = "Aufgabe erstellen";
result.color = colors["disabled"];
result.icon = "mdi:alert-plus";
result.days_left = "";
let timestamp;
let time;
let minutes;
let hours;
let days;
if (states['{{entity}}']) {
if (entity.state != 'unknown') {
timestamp = parseInt(entity.state);
time = (Date.now() / 1000) - timestamp;
minutes = Math.floor(((time % 3600) / 60));
hours = Math.floor(((time % 86400) / 3600));
days = Math.floor((time / 86400));
result.color = colors["success"];
result.icon = "mdi:checkbox-marked-circle-outline";
// LAST TRIGGER
if (time < 60)
result.label = 'weniger als 1 Minute';
else if (days == 1)
result.label = '1 Tag her';
else if (days > 1)
result.label = days+' Tage her';
else if (hours >= 1)
result.label = hours+' Stunden her';
else if (hours < 1)
result.label = minutes+(minutes > 1 ? ' Minuten' : ' Minute');
// DAYS LEFT
result.days_left = Math.round(((timestamp + ({{cycle_days|int}}*86400)) - (Date.now()/1000)) / 86400);
if (result.days_left <= {{warning_before|int}}) {
result.color = colors["warning"];
result.icon = "mdi:clock-alert";
}
if (result.days_left <= 0) {
result.color = colors["error"];
result.icon = "mdi:alert-circle"
}
result.days_left = result.days_left + (result.days_left == 1 ? " Tag verbleibt" : " Tage verbleiben");
} else {
result.label = "Klicken zum Erledigen";
}
}
return result;
]]]
tap_action:
confirmation:
text: >
[[[
if (!states['{{entity}}'])
return 'Entität {{entity}} wird erstellt.'
else
return 'Möchten sie diese Aufgabe wirklich als erledigt markieren?'
]]]
action: call-service
service: mqtt.publish
service_data:
topic: >
[[[
if (!states['{{entity}}'])
return 'homeassistant/sensor/{{sensor_name}}/config'
else
return 'homeassistant/sensor/{{sensor_name}}/state'
]]]
payload: >
[[[
if (!states['{{entity}}'])
return '{ "name": "{{sensor_name}}", "state_topic": "homeassistant/sensor/{{sensor_name}}/state", "value_template": "\{\{ value_json.state \}\}", "device_class": "timestamp", "json_attributes_topic": "homeassistant/sensor/{{sensor_name}}/state", "json_attributes_template": "\{\{ value_json.attributes | tojson \}\}" }'
else
return '{ "state":' + (Date.now() / 1000) + ', "attributes": { "cycle_days": {{cycle_days}}, "warning_before": {{warning_before}} } }'
]]]
retain: true
And here is the code for the Button Card:
- !include
- ../../templates/household_task.yaml
- name: Change Bed Sheets
sensor_name: chore_change_bed_sheets
warning_before: 1
cycle_days: 14
(I used your code just to see if it works, but I always get the above errors.