CPU/GPU Temp controlled color (Flex)

Hi there,

I hope software is the correct category for this:

I was wondering if it is possible with the BlinkStick client 1 or 2 to control the color of BlinkStick Flex in relation to the temperature of the cpu/gpu?

And if not, if there is a not too complicated workaround with something like Python?
I can write a few lines of simple code but I am no programmer by any means.

Background:
I am building a system with the gorgeous DAN A4-SFX and I want to light both of its chambers with simple static color that shifts when the components get hot. I already ordered the Flex and will probably cut it halfway, put one half in each chamber and connect them with soldered on wires.

Thanks!

Hello WhoNocks and welcome to the forums.

The BlinkStick Client does not have a notification for CPU temperature.
How to realize this is basicly not a BlinkStick question but a question of how to get the values you need which I think is the harder part.
First of all you´ll need the method to get the temperature itself. There are a lot of different ways documented in the internet:
google get cpu temperature python

For the BlinkStick itself you´ll find a lot of information in the python wiki:

For example different colors for CPU usage:

You´re idea is of course a good one. If you plan to run on windows only I would recommend to take a look at the .NET API for BlinkStick and try to realize it with C#.

I hope it helps. Let us know if you need some more help.

Thank you! I was pleasantly surprised what an active community this product has and the uses people come up with.

That the Client can not do it is a bummer but I see that this might be hard to implement, since you already pointed out that actually reading the temperature will probably be the hardest part.

I have done a quick search and it seems that it might in fact be so difficult (because of different standards used by hardware manufacturers) that I cant do the data collection myself but need to use something like this.

I will most likely only ever use this machine with windows, so C# will probably be fine. I actually wrote some small useless programs with C# before, like the kind of programs you write in an IT class in school. But I never had the motivation to do more since I didnt see the practical use for me. Maybe this is finally the time for me to learn some programming :smiley:

Once I have the Flex I will get to it!

Hello,
We managed to get working with windows using python :slight_smile:

If CLR library doesn’t work:
You must be using the wrong ‘clr’ module. remove it

pip uninstall clr

And then install pythonnet

pip install pythonnet

Just need to download additional library from [Downloads - Open Hardware Monitor](THIS LINK)
Extract it and edit path to OpenHardwareMonitorLib.dll in the code:
clr.AddReference(r’C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll’)

import clr 
import time
from blinkstick import blinkstick


# Path to OpenHardwareMonitor.dll library
clr.AddReference(r'C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')

from OpenHardwareMonitor.Hardware import Computer

def get_cpu_temp():
    c = Computer()
    c.CPUEnabled = True
    c.Open()
    for sensor in c.Hardware[0].Sensors:
        if "/temperature" in str(sensor.Identifier):
            return sensor.Value
    return None

def set_blinkstick_color(temp):
    stk = blinkstick.find_first()
    if temp >= 75:
        color = "red"
    elif temp >= 60:
        color = "orange"
    elif temp >= 45:
        color = "yellow"
    else:
        color = "green"

    if stk is not None:
        stk.set_color(name=color)

if __name__ == "__main__":
    try:
        while True:
            temp = get_cpu_temp()
            if temp is not None:
                print(f"Current CPU Temperature: {temp}C")
                set_blinkstick_color(temp)
            else:
                print("Could not fetch CPU temperature.")
            time.sleep(1)
    except KeyboardInterrupt:
        print("Terminating program...")
    finally:
        stk = blinkstick.find_first()
        if stk is not None:
            stk.set_color(name="black")

ALSO NEW SET OF CODE Below FOR FLEX YOU CAN TRY it changes number of LED’s light depends on CPU temperature and also in addition of this it lights in different hue from Green to Red color:

import clr
import time
from blinkstick import blinkstick

# Define the number of LEDs
num_leds = 32

clr.AddReference(r'C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')

from OpenHardwareMonitor.Hardware import Computer

def get_cpu_temp():
    c = Computer()
    c.CPUEnabled = True
    c.Open()
    for sensor in c.Hardware[0].Sensors:
        if "/temperature" in str(sensor.Identifier):
            temp = sensor.Value
            return temp
    return None
    
def map_value(value, from_low, from_high, to_low, to_high):
    # Map a value from one range to another
    return (value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low

def set_led_color(num_leds, temp, blinkstick):
    if blinkstick:

        # Define the color gradient from green to red
        green = (0, 255, 0)
        red = (255, 0, 0)

        # Calculate the starting and ending LED indices based on the percentage
        start_led = 0
        end_led = int(map_value(temp, 0, 100, 0, num_leds))

        # Calculate the step for each color channel (R, G, B)
        step_r = (red[0] - green[0]) / num_leds
        step_g = (red[1] - green[1]) / num_leds
        step_b = (red[2] - green[2]) / num_leds

        # Initialize the color
        current_color = green

        # Set the colors for each LED
        for i in range(num_leds):
            if start_led <= i < end_led:
                for stick in blinkstick:
                    stick.set_color(index=i, red=int(current_color[0]), green=int(current_color[1]), blue=int(current_color[2]))
            else:
                # Turn off LEDs beyond the specified percentage
                for stick in blinkstick:
                    stick.set_color(index=i, red=0, green=0, blue=0)
            current_color = (current_color[0] + step_r, current_color[1] + step_g, current_color[2] + step_b)
    else:
        print("No BlinkStick found.")

if __name__ == "__main__":
    blinkstick = blinkstick.find_all()
    try:
        while True:
            temp = get_cpu_temp()
            if temp is not None:
                print(f"Current CPU Temperature: {temp}C")
                set_led_color(num_leds, temp, blinkstick)
            else:
                print("Could not fetch CPU temperature.")
            time.sleep(1)
    except KeyboardInterrupt:
        print("Terminating program...")
    finally:
        if blinkstick:
            for stick in blinkstick:
                for i in range(num_leds):
                    stick.set_color(index=i, red=0, green=0, blue=0)  # Turn off all LEDs