So I’m pretty new with AppDaemon. However, I used to code a lot with Python for some years ago. So I just need a nudge in the right direction.
I got a color bulb from Ikea (LED1624G9). And I manage to use my Xiaomi Mini Switch to turn it on/off and add delays. However, is there a way to send a color payload to it? And how do I do this?
You don’t need to import datetime twice, you can remove “import datetime”. Why do you import sys and time, if you don’t use it in your app?
if event_data == 1001 or event_data == 1002 or ....
can be simplified to
if event_data in [1001, 1002, 1003, 1004, 1005, 1006]
Never use time.sleep if it can not be avoided. In your case it would be better to create an additional function something like turn_lights_off, which just turn off the light and then you call it in your event_received function with self.run_in(self.turn_lights_off, 2).
For the colors, you just need to add color="orange" to the turn_on method.
self.turn_on("light.ikea", color="orange")
I assume you want to loop through the colors when you press the button? I would suggest to create an input_select with the desired colors, then take the color from there and at the end of the event_received you use the service input_select.select_next, to change the input select to the next entry.
Thanks a lot. I used some copy and pasted code. That’s why it lacks some finesse. Did not see that I imported datetime twice, however. sys was from an earlier idea I had where I appended some libs to the path. Just forgot to remove it. How much easier it would be if AppDaemon was Java.
Thanks for the ideas and input. Guest it would be easiest to create a tuple and then random for a color each press. However, it does not turn on when I’ve added color as a parameter. Tried exactly what you wrote, self.turn_on(“light.ikea”, color=“orange”) and the log fires. But the lamp stays off.
Also, is there a way to write hex codes instead of the color name?
Could be that the color attribute is not supported by the ikea bulbs or maybe it is color_name instead of just color, can’t remember. What attributes does your light have?