Hey there everyone,
So I wrote this to compensate for lack of ambient light outside
import appdaemon.appapi as appapi
import datetime
class living_room_daytime_light(appapi.AppDaemon):
def initialize(self):
self.living_room_lights = 'light.living_room_lights'
self.luxsensor = 'sensor.average_outside_lux'
self.run_every(self.adjust_light_function, self.luxsensor)
def brightness_to_percent(self, brightness):
return 255/100 * int(brightness)
def adjust_light_function(self, entity, attribute, old, new, kwargs):
lux=float(new)
self.log(lux)
if lux < 500:
brightness = self.brightness_to_percent(80)
self.turn_on(self.living_room_lights, brightness=brightness)
elif 501 <= lux <= 800:
brightness = self.brightness_to_percent(70)
self.turn_on(self.living_room_lights, brightness=brightness)
elif 801 <= lux <= 1000:
brightness = self.brightness_to_percent(60)
self.turn_on(self.living_room_lights, brightness=brightness)
elif 1001 <= lux <= 1200:
brightness = self.brightness_to_percent(50)
self.turn_on(self.living_room_lights, brightness=brightness)
elif 1201 <= lux <= 1500:
brightness = self.brightness_to_percent(40)
self.turn_on(self.living_room_lights, brightness=brightness)
elif lux > 1500 :
self.turn_off(self.living_room_lights)
Right now I have it set to run with a state change so naturally everytime my lux sensors report in and HA figures out the AVG through a sensor template the script is called. So needless to say it gets called a lot.
I’d like to change it instead to run like every 2 mins or every 5 just to give the system a small break.
I’ve been looking at the examples of the self.run_every and I’m confused on the time aspect.
So I see this in the docs
self.run_every(self.run_every_c, time, 17 * 60)
Which says that it should run every 17 mins in 2 hours which I don’t quite understand how that works.
So I want to double check the syntax of this, should I set it up like
self.run_every(self.adjust_light_function, time 5 * 300, self.luxsensor)
Thank you all for your help with wrapping my head around this.
EDIT: Realized my math was screwy