6
submitted 2 months ago* (last edited 2 months ago) by Communist@lemmy.ml to c/python@lemmy.ml

I'm just trying to control my smartlights with a script, it seems to be having a lot of problems, I really don't know what I'm doing, i'd appreciate any help I can get

Once I have a script that can individually turn lights on/off i can edit the rest myself, I just can't get the base functionality working.

top 6 comments
sorted by: hot top controversial new old
[-] xantoxis@lemmy.world 7 points 2 months ago* (last edited 2 months ago)

Light, apparently a class in that library, has not been defined, or imported. In Python, whenever you reference any expression, such as Light(...) on the right-hand-side of an assignment, it must already be present in the program (technically, in this case: the global namespace).

Not entirely your fault, I quickly glanced at the library you're using and in several places the examples use Light() the same way you did, but without importing it first. This is.. not unreasonable in documentation, as you're expected to have some familiarity with Python, but they don't really tell you where to import it from.

Another quick glance at the source code suggests that either of these should work, and do the intended thing:

  1. Add: from lifxlan import Light near the top
  2. Replace your import line with, simply, import lifxlan, and then use lifxlan.Light(...) and lifxlan.LifxLAN() where those names appear in the program.[1]

I strongly suggest taking a few hours to go through a Python tutorial, as you're going to quickly get into more advanced stuff as you try to get this working. It will help to have a framework of understanding before you do.

[1] Note: the line lan = LifxLAN() probably isn't doing anything at all in this program, but I assume you'll be adding more code later that uses it.

[-] Communist@lemmy.ml 4 points 2 months ago

I just want you to know I figured it out RIGHT BEFORE you wrote this, but this is still awesome and super helpful and thank you so much!

[-] xantoxis@lemmy.world 4 points 2 months ago

I knew you could do it

Glad you got it figured out.

Tangent: Something like home assistant could also abstract a fait bit of complexity especially when you start dealing with different manufacturers.
Just checked and they already support lifx.
Good luck

[-] Midnitte@beehaw.org 1 points 2 months ago

Looks like this was solved due to the missing import, but any reason to use this over something with a little more user friendliness such as Home Assistant?

[-] Communist@lemmy.ml 2 points 2 months ago

I don't really value user friendliness, I wanted scripts that I could easily launch through a rofi menu system, home assistant seems to be a full GUI in and of itself, but I don't really know much about it.

this post was submitted on 20 Mar 2024
6 points (100.0% liked)

Python

3115 readers
1 users here now

News and discussions about the programming language Python


founded 5 years ago
MODERATORS