@jhows conforme o Jorge disse.
Podes fazer o inverso se calhar fica mais interessante, usando um countdown.
Para isso no hassio precisas de criar dentro da pasta Config uma outra pasta chamada custom_components e dentro dessa uma outra pasta chamada sensor.
Depois dentro dessa pasta criar um ficheiro com um nome a tua escolha.py
exemplo: countdown.py
dentro desse ficheiro colocas o que está aqui:
"""
Date Countdown
"""
import datetime
from datetime import timedelta
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__)
ATTR_DAYS = 'days'
ATTR_HOURS = 'hours'
ATTR_MINUTES = 'minutes'
DEFAULT_NAME = "Countdown"
CONF_DATE = 'date'
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_DATE): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up date countdown sensor."""
end_date = config.get(CONF_DATE)
sensor_name = config.get(CONF_NAME)
add_devices([Countdown(sensor_name, end_date)])
class Countdown(Entity):
"""Implementation of the date countdown sensor."""
def __init__(self, sensor_name, end_date):
"""Initialize the sensor."""
self.end_date = end_date
self._name = sensor_name
self._state = None
self._data = {}
self.update()
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def device_state_attributes(self):
return {
ATTR_DAYS: self._data.get("days"),
ATTR_HOURS: self._data.get("hours"),
ATTR_MINUTES: self._data.get("minutes")
}
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return 'mdi:calendar'
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Calculate time until end"""
end_date = datetime.datetime.strptime(self.end_date, '%d-%m-%Y %H:%M')
days = (end_date - datetime.datetime.now())
days, seconds = days.days, days.seconds
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
self._data["days"] = days
self._data["hours"] = hours
self._data["minutes"] = minutes
self._state = str(days) + " days " + str(hours) \
+ " hours " + str(minutes) + " minutes"
De seguida criar um sensor no home assistant desta forma:
- platform: countdown
name: lembrete
date: "20-07-2018 18:00"
- platform: template
sensors:
contador_plantacao:
value_template: ´{{ states.lembrete.attributes.days }}´
friendly_name: 'Alface'
unit_of_measurement: "Faltando"