For my lighting in the morning, I have the following:
def initialize(self):
# Wait for movement to turn lights on in the morning
self.listen_state(self.morning, entity='binary_sensor.xiaomi_motion_kitchen', old='off', new='on', constrain_input_select='input_select.house,Morning')
# Turn lights off one hour after sunrise in the morning
self.run_at_sunrise(self.morning_off_sunrise, offset=3600, constrain_input_select='input_select.house,Morning')
def morning(self, entity, attribute, old, new, kwargs):
sunrise = self.sunrise() + datetime.timedelta(minutes=60)
if self.date() == sunrise.date() and self.time() < sunrise.time() and self.get_state('light.living_room') == 'off':
self.log("Running first morning function")
self.call_service('light/turn_on', entity_id='light.living_room', profile='standard')
self.handle = self.listen_state(self.morning_off, entity='sensor.aeotec_zw100_multisensor_6_burglar', new='0', constrain_input_select='input_select.house,Morning')
def morning_off(self, entity, attribute, old, new, kwargs):
self.call_service('light/turn_off', entity_id='light.living_room')
self.cancel_listen_state(self.handle)
def morning_off_sunrise(self, kwargs):
self.call_service('light/turn_off', entity_id='light.living_room')
My question is, is it possible to combine the two āmorning_offā functions? The problem Iām getting at the moment (it seems no matter what Iāve tried) is I always end up with a variation of TypeError: morning_off() takes 2 positional arguments but 6 were given
I understand why thatās occurring, but canāt seem to work out for sure if there is a way to combine the functions and have the positional arguments as āoptionalā for lack of a better word.
Itās not a huge deal in this one app, but I find Iām often running into this āperform action if X happens OR at Y timeā quite frequently so it seems like it would be neater to not be duplicating the functions.
Thanks for any advice one way or the other!