Appdaemon fade light

Hi, i’m trying to fade light on movement using run_at service but i’ve got some problems because callback are not executed in the times listed belowe.
do you know if is there a way to do it?

adesso = datetime.now()
self.run_at(self.light_on20, adesso + timedelta(microseconds=200000))
self.run_at(self.light_on30, adesso + timedelta(microseconds=500000))
self.run_at(self.light_on40, adesso + timedelta(microseconds=700000))
self.run_at(self.light_on50, adesso + timedelta(microseconds=1100000))
self.run_at(self.light_on60, adesso + timedelta(microseconds=1300000))
self.run_at(self.light_on70, adesso + timedelta(microseconds=1700000))
self.run_at(self.light_on80, adesso + timedelta(microseconds=1900000))
self.run_at(self.light_on90, adesso + timedelta(microseconds=2300000))
self.run_at(self.light_on100, adesso + timedelta(microseconds=2500000))

then each light_on% change the brightness of the light:

def light_on20(self, kwargs):
  self.turn_on("light.ingresso", brightness = "50")
  self.log("live 20 percento")

and this is the log, callback is not executed in the right sequence

2018-04-26 22:02:56.556105 INFO luce_moviento_ingresso: live 40 percento
2018-04-26 22:02:56.558722 INFO luce_moviento_ingresso: live 30 percento
2018-04-26 22:02:56.559821 INFO luce_moviento_ingresso: live 20 percento
2018-04-26 22:02:57.604877 INFO luce_moviento_ingresso: live 80 percento
2018-04-26 22:02:57.609757 INFO luce_moviento_ingresso: live 50 percento
2018-04-26 22:02:57.616977 INFO luce_moviento_ingresso: live 70 percento
2018-04-26 22:02:57.618406 INFO luce_moviento_ingresso: live 60 percento
2018-04-26 22:02:58.416943 INFO luce_moviento_ingresso: live 100 percento
2018-04-26 22:02:58.419436 INFO luce_moviento_ingresso: live 90 percento

appdaemon doesnt work with microseconds, but in seconds.
you could try it wit time.sleep in between the commands but i dont think you get the effect you like.

is there no transition for the light you have?

i’m using IKEA tradfri, i don’t like the standard transition so i tried to do it myself.
i’ve tried the solution you posted but to have a good effect i would need to call the “turn_on” sevice very often with little tme.sleep (about 0.025) and it’s not supported because if i do 40 loops with 0.025 appdaemon take about 8 seconds (i’m having 4 calls per second).

Have you thought about creating a custom component? I don’t believe it has any timing restrictions, but it will be a bit more complicated to implement.

why do you say not supported?

creating a transition like that is possible as you see, but if it is a desired way thats the question.
sending 40 turn_on commands in such a short time will put quite a load on your system.
it could be that you run into other sideeffects in the future, while transitioning the light.
it could disturb network, other sensors, etc.

maybe you could try to use transition in a few steps. from 0 to 25, from 25 to 50 etc.

@petro a custom component would run into the same problems. the fact stays that you need to send 40 commands to the light to get the desired effect.

1 Like

now that you mention it yes. @dvd78 have you looked at the configuration of the device itself? Maybe it has a configuration that allows you to adjust rampup.

@petro, unfortunately there is not configuration to adjust on device to fade it…
@ReneTode i undetstand there could be some problems on network, i thought that there wouldn’t be problems for only 2 seconds. and the problems to use transition with big difference of brightess from one step and nex one is that you see light going on like a “stair”…

at least you know the advantages and the disadvantages.
its for you to decide if it is worth it for you.

my lights have a “decent” transition, but i only find it annoying.

1 Like