class SimpleLogCard extends HTMLElement {
set hass(hass) {
this._hass = hass;
if (!this.content) {
const title = this.config.title || 'Sensor Log';
this.innerHTML = `
No history found.
'; } } formatTime(utcDatetime) { // Convert UTC to local time const localDate = new Date(utcDatetime); let hours = localDate.getHours(); const ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' const minutes = localDate.getMinutes(); return `${hours}:${minutes < 10 ? '0' + minutes : minutes} ${ampm}`; } groupByDate(states) { return states.reduce((acc, state) => { const date = state.last_changed.split('T')[0]; if (!acc[date]) { acc[date] = []; } acc[date].push(state); return acc; }, {}); } async fetchHistory(entityId, maxEntries) { const url = `history/period?filter_entity_id=${entityId}`; const response = await this._hass.callApi('GET', url); return response; } setConfig(config) { if (!config.entity) { throw new Error('You need to define an entity'); } this.config = config; } getCardSize() { return 3; } } customElements.define('simple-log-card', SimpleLogCard);