Hi guys,
I want to automate my bathroom ventilation. I want t keep it simple and just have a after-run time and static humidity values.
For the after-run part, I tried to utilize the duration parameter, but I do not get it working. The callback is not executed after the duration is expired.
apps.yaml snipped:
lueftersteuerung_duschbad:
module: lueftersteuerung_dusche
class: lueftersteuerung
luefter_nachlauf: 60
luefter_nachlauf_max: 2400
luftfeuchte: 60
lueftersteuerung_dusche.py:
import appdaemon.plugins.hass.hassapi as hass
import datetime
class lueftersteuerung(hass.Hass):
def initialize(self):
self.listen_state(self.fan_timeout,"switch.luefter_dusche_90", old="off", new="on", duration=int(self.args["luefter_nachlauf"]))
def minute_task(self, kwargs):
fan = self.get_state("switch.luefter_dusche_90")
light = self.get_state("switch.licht_dusche_89")
humidity = float(self.get_state("sensor.feuchte_dusche_93"))
act = datetime.datetime.replace(datetime.datetime.now(datetime.timezone.utc)).timestamp()
fan_last_change = int(act - datetime.datetime.replace(self.convert_utc(self.entities.switch.luefter_dusche_90.last_changed)).timestamp())
light_last_change = int(act - datetime.datetime.replace(self.convert_utc(self.entities.switch.copy_licht_dusche.last_changed)).timestamp())
self.log("LĂĽfter letzte Ă„nderung vor {}s".format(fan_last_change))
self.log("Licht letzte Ă„nderung vor {}s".format(light_last_change))
self.log("rH%: {}".format(humidity))
if (fan=="on" and light=="off" and (((humidity<int(self.args["luftfeuchte"])) and (light_last_change>int(self.args["luefter_nachlauf"]))) or (light_last_change>int(self.args["luefter_nachlauf_max"])))):
self.turn_off("switch.luefter_dusche_90")
self.cancel_timer(self.minutely)
self.log('Luefter abgeschaltet')
def fan_timeout(self, entity, attribute, old, new, kwargs):
self.log('Nachlauf abgelaufen')
time = datetime.time(0, 0, 0)
self.minutely = self.run_minutely(self.minute_task, time)
Without the duration parameter, the callback is immediately firing and working as expected.
What am I doing wrong?
Thanks Dirk