I have been using the time sensor for a while now but after the update to 0.91.1 it seems to be behaving incorrectly and it causes my automations to not fire. The time “jumps” forward and its out of sync with the system clock
As a “fix” I am now sending the time via appdaemon but its overkill
import appdaemon.plugins.hass.hassapi as hass
import datetime
import pytz
class Time(hass.Hass):
def initialize(self):
self.entity = self.args['entity']
self.update_seconds = self.args['update_seconds']
# Schedule from now to the end of time :)
now = datetime.datetime.now()
now += datetime.timedelta(0,10) # Add 10 seconds just in case it does not start in time
self.handle = self.run_every(self.run, now, self.update_seconds)
def run(self, kwargs=None):
TIME_STR_FORMAT = '%H:%M'
tz = pytz.timezone('America/Los_Angeles')
now = datetime.datetime.now(tz)
time = now.strftime(TIME_STR_FORMAT)
#self.log("Updating state of {} to {}".format(self.entity, time))
self.set_state(entity_id=self.entity, state=time, attributes={"friendly_name": "Current time from appdaemon",
"unit_of_measurement": "time"})
The one difference I noticed is that, in my case, date returns the local system time (i.e. adjusted for time zone) whereas in your example it returns UTC time. Whether that’s meaningful or not is unclear.