Page 1 of 1

Can I display 3 or more images based on Variable values?

PostPosted: Wed Jan 02, 2019 7:37 pm
by sumocomputers
I know that I can use 2 different images for Variables that are True/False on a custom control page.

But I am trying to build a simple "meter" that shows when electricity rates in effect are low, normal, or high.

I currently have a single variable that can have a fixed value of 0.09, 0.23, and 0.52 (these are cents per kWh).

My idea is to have 3 images (green, orange, red), only one of which displays based on the Variable value.

Is this possible, or is there another method or plugin I should look at?

Re: Can I display 3 or more images based on Variable values?

PostPosted: Wed Jan 02, 2019 7:56 pm
by DaveL17
Getting the image display heuristics to display images based on such specific variable values is probably possible, but not worth the trouble in my opinion. I'd suggest creating another variable and using Triggers or Python to set the value of the new variable to green/orange/red (or low/medium/high or whatever) and then trigger the images based off those values.

Re: Can I display 3 or more images based on Variable values?

PostPosted: Wed Jan 02, 2019 10:33 pm
by sumocomputers
Thanks for the direction. I was able to get everything working the way I want.

It's all hard-coded values, so if electricity rates change I will need to make some manual updates, but it does the job!

It would be nice if on Triggers, Indigo allowed for a Variable to "become between these 2 values" aka "greater than X, AND less than Y", but minor annoyance.

Image

Re: Can I display 3 or more images based on Variable values?

PostPosted: Thu Jan 03, 2019 6:33 am
by DaveL17
sumocomputers wrote:
Thanks for the direction. I was able to get everything working the way I want.

It's all hard-coded values, so if electricity rates change I will need to make some manual updates, but it does the job!

It would be nice if on Triggers, Indigo allowed for a Variable to "become between these 2 values" aka "greater than X, AND less than Y", but minor annoyance.

Image

Glad that you found something that works for you. If you'd like some help with a short Python script that can handle your logic (and hopefully eliminate the manual update bit), please let me know.

Re: Can I display 3 or more images based on Variable values?

PostPosted: Thu Jan 03, 2019 6:45 pm
by sumocomputers
Now that I have the electricity rates working, I do need some help trying to figure out the current electricity cost display.

Ideally I would do something similar to the rate with 3 graphics for Low, Medium, and High, but would need to define ranges to change another variable, let's call it meterCost. The range might be something like this:

Low (0.0 through 0.50) meterCost = low
Normal (0.51 through 1.50) meterCost = medium
High (1.51 or higher) meterCost = high

I already have a variable called electricityCost which is constantly changing and represents the cost I am paying at the moment, which would be the input.

The problem with built-in Indigo, is the triggers don't allow for a range of values, just equal to, greater, less than, etc.

If I could define ranges for low, medium, and high, I can just append the graphic with a "+low", "+medium", "+high".

Re: Can I display 3 or more images based on Variable values?

PostPosted: Thu Jan 03, 2019 7:04 pm
by DaveL17
This is untested, but should be close. Create a new variable called 'meterCostPNG' or something similar. Replace the 12345678 with the appropriate variable IDs.

Code: Select all
meter_cost = float(indigo.variables[12345678].value)  # the ID of your cost source

if meter_cost <= 0.5:
    indigo.variable.updateValue(12345678, 'low')  # the ID of your PNG variable
elif 0.5 < meter_cost <= 1.5:
    indigo.variable.updateValue(12345678, 'medium')  # the ID of your PNG variable
else:
    indigo.variable.updateValue(12345678, 'high')  # the ID of your PNG variable

Create a Trigger that fires whenever meterCost changes. Save the above script as a Python script Action within the Trigger.

Re: Can I display 3 or more images based on Variable values?

PostPosted: Fri Jan 04, 2019 1:26 pm
by sumocomputers
This worked awesome, thank you again.

Re: Can I display 3 or more images based on Variable values?

PostPosted: Fri Jan 04, 2019 2:26 pm
by DaveL17
I'm glad. Enjoy!