Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import appdaemon.plugins.hass.hassapi as hass
- class DishWasher(hass.Hass):
- def initialize(self):
- self.handle = None
- self.power_plug = 'switch.plug_158d0001fa2873'
- self.hall_lamp_desk = 'light.desk_hall'
- self.listen_state(self.callback, self.power_plug, attribute='load_power')
- def callback(self, entity, attribute, new, old, kwargs):
- self.log('callback')
- if old > 14.0: # условие: потребление больше 14
- self.log('cancel timer')
- self.cancel_timer(self.handle) # отменяем таймер
- elif old <= 14.0: # условие: потребление меньше 14
- self.log('set timer')
- self.set_timer() # устанавливаем таймер
- def set_timer(self):
- self.log('running set timer')
- self.handle = self.run_in(self.lamp_off, 120)
- def lamp_off(self, kwargs):
- self.log('running turn off')
- self.turn_off(self.hall_lamp_desk)
- # ЛОГ:
- # 2019-10-15 16:13:28.297529 INFO dishwasher: callback
- # 2019-10-15 16:13:28.299090 INFO dishwasher: set timer
- # 2019-10-15 16:13:28.300646 INFO dishwasher: running set timer
- # 2019-10-15 16:13:40.322555 INFO dishwasher: callback
- # 2019-10-15 16:13:40.323649 INFO dishwasher: set timer
- # 2019-10-15 16:13:40.324430 INFO dishwasher: running set timer
- # 2019-10-15 16:13:50.027945 INFO dishwasher: callback
- # 2019-10-15 16:13:50.028918 INFO dishwasher: cancel timer
- # 2019-10-15 16:15:28.004445 INFO dishwasher: running turn off
Advertisement
Add Comment
Please, Sign In to add comment