Page 1 of 1

don't know why this stopped working.

PostPosted: Fri Sep 08, 2023 6:12 pm
by Different Computers
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.

Re: don't know why this stopped working.

PostPosted: Fri Sep 08, 2023 6:15 pm
by FlyingDiver
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.

Re: don't know why this stopped working.

PostPosted: Sat Sep 09, 2023 7:17 am
by Different Computers
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.

Re: don't know why this stopped working.

PostPosted: Sat Sep 09, 2023 7:45 am
by Different Computers
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.

Re: don't know why this stopped working.

PostPosted: Sat Sep 09, 2023 7:47 am
by FlyingDiver
I don't see a call to indigo.variable.updateValue()

Re: don't know why this stopped working.

PostPosted: Sat Sep 09, 2023 7:58 am
by Different Computers
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")