time:
- platform: homeassistant
id: ha_time
text_sensor:
- platform: homeassistant
id: timer_status
entity_id: timer.timertest123
- platform: homeassistant
id: timer_finish
entity_id: timer.timertest123
attribute: finishes_at
display:
- platform: lcd_pcf8574
dimensions: 20x4
address: 0x27
lambda: |-
it.printf(0, 0, "Timer: %s", id(timer_status).state.c_str());
if (id(timer_status).state == "active") {
struct tm tm_finish{}, tm_ha_time{};
time_t t_helper;
double remain;
int remain_h, remain_m, remain_s;
strptime(id(timer_finish).state.c_str(), "%Y-%m-%dT%T", &tm_finish); // Convert string to time struct
t_helper = mktime(&tm_finish) + 3600; // Convert to time_t and add 1 hour (correct for your timezone)
tm_ha_time = id(ha_time).now().to_c_tm(); // Get current time in a tm struct
remain = difftime(t_helper, mktime(&tm_ha_time)); // Calculate difference in seconds
remain_h = (int) remain/3600;
remain_m = (int) (remain - 3600*remain_h)/60;
remain_s = (int) remain - 3600*remain_h - 60*remain_m;
it.printf(0, 2, "%02d:%02d:%02d", remain_h, remain_m, remain_s);
it.printf(0, 3, "End: %02d:%02d", tm_finish.tm_hour, tm_finish.tm_min);
} else {
it.printf(0, 3, " "); // clear second line
}