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

Posted on
Wed Jan 02, 2019 7:37 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

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

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?

Posted on
Wed Jan 02, 2019 7:56 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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

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.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Jan 02, 2019 10:33 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

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

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

Posted on
Thu Jan 03, 2019 6:33 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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

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.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Jan 03, 2019 6:45 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

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

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".

Posted on
Thu Jan 03, 2019 7:04 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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

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.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Jan 04, 2019 1:26 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

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

This worked awesome, thank you again.

Posted on
Fri Jan 04, 2019 2:26 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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

I'm glad. Enjoy!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests