don't know why this stopped working.

Posted on
Fri Sep 08, 2023 6:12 pm
Different Computers offline
User avatar
Posts: 2556
Joined: Jan 02, 2016
Location: East Coast

don't know why this stopped working.

I mean, I know it worked at one point.

I definitely have a variable named "darkness" and this script doesn't generate an error, but the value of variable 'darkness' does not change

Code: Select all
# Get the value of AverageLuminance
average_luminance_name = "AverageLuminance"
average_luminance = indigo.variables[average_luminance_name]
if average_luminance is not None:
    average_luminance_value = int(average_luminance.value)
    # Invert the value of AverageLuminance
    average_luminance_inverse = 100 - average_luminance_value
    # Set the value of the "darkness" variable to the inverse of AverageLuminance
    darkness_name = "darkness"
    darkness = indigo.variables[darkness_name]
    if darkness is not None:
        darkness.value = str(average_luminance_inverse)
        indigo.server.log(f"Set value of variable '{darkness_name}' to {average_luminance_inverse}")
    else:
        indigo.server.log(f"Variable '{darkness_name}' not found")
else:
    indigo.server.log(f"Variable '{average_luminance_name}' not found")


How did I goof? This is a central script in my evening outdoor lights process.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Fri Sep 08, 2023 6:15 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: don't know why this stopped working.

Are you sure you have a variable named "AverageLuminance"? Better to use the Variable ID, which will be the same even if the name changes.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Sep 09, 2023 7:17 am
Different Computers offline
User avatar
Posts: 2556
Joined: Jan 02, 2016
Location: East Coast

Re: don't know why this stopped working.

I take your point, but AverageLuminance definitely exists. I'm continuing to look. Something seems wrong with my average luminance script too, since it has a value right now way above 100.

OK, found some bad math in the averaging that was really due to my having replaced a broken zoos sensor that reported in % luminance with another that reports Lux.

That's fixed now, but the darkness calculation is still not working. Onward.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sat Sep 09, 2023 7:45 am
Different Computers offline
User avatar
Posts: 2556
Joined: Jan 02, 2016
Location: East Coast

Re: don't know why this stopped working.

I've fixed the AverageLuminance calculation and that's now correctly changing the variable to a number between 0-100.

This script however, still doesn't change the darkness variable. I've triple-checked the IDs, and it DOES write the correct value and variable ID to the log.
Code: Select all
# Get the ID of the AverageLuminance variable
average_luminance_id = 944796063 

# Get the value of AverageLuminance
average_luminance = indigo.variables[average_luminance_id]
if average_luminance is not None:
    average_luminance_value = int(average_luminance.value)
    # Invert the value of AverageLuminance
    average_luminance_inverse = 100 - average_luminance_value

    # Get the ID of the darkness variable
    darkness_id = 1021324478 

    # Set the value of the "darkness" variable to the inverse of AverageLuminance
    darkness = indigo.variables[darkness_id]
    if darkness is not None:
        darkness.value = str(average_luminance_inverse)
        indigo.server.log(f"Set value of variable ID {darkness_id} to {average_luminance_inverse}")
    else:
        indigo.server.log(f"Variable ID {darkness_id} not found")
else:
    indigo.server.log(f"Variable ID {average_luminance_id} not found")


Maybe I need more caffeine, but I'm not seeing the problem.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sat Sep 09, 2023 7:47 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: don't know why this stopped working.

I don't see a call to indigo.variable.updateValue()

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Sep 09, 2023 7:58 am
Different Computers offline
User avatar
Posts: 2556
Joined: Jan 02, 2016
Location: East Coast

Re: don't know why this stopped working.

Thank you.

Duh to me. The corrected script, which now works:
Code: Select all
# Get the ID of the AverageLuminance variable
average_luminance_id = 944796063

# Get the value of AverageLuminance
average_luminance = indigo.variables[average_luminance_id]
if average_luminance is not None:
    average_luminance_value = int(average_luminance.value)
    # Invert the value of AverageLuminance
    average_luminance_inverse = 100 - average_luminance_value

    # Get the ID of the darkness variable
    darkness_id = 1021324478 

    # Set the value of the "darkness" variable to the inverse of AverageLuminance
    darkness = indigo.variables[darkness_id]
    if darkness is not None:
        darkness.value = str(average_luminance_inverse)
        indigo.variable.updateValue(darkness.id, value=str(average_luminance_inverse))
        indigo.server.log(f"Set value of variable ID {darkness_id} to {average_luminance_inverse}")
    else:
        indigo.server.log(f"Variable ID {darkness_id} not found")
else:
    indigo.server.log(f"Variable ID {average_luminance_id} not found")

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests