Hi guys, I have a variable filled with a HEX color (e.g. #FF0000). Is it possible to convert this to a RGB color? It doesnt matter how many variables will be used, like 255,0,0 to one variable or to 3 invidual variables (one for red, green and blue).
-
HEX color to RGB
-
@gratizzz I think the easiest way for this is a litte helper script like this:
#!/bin/bash hex=$1 printf "%d,%d,%d" 0x${hex:0:2},0x${hex:2:2},0x${hex:4:2}
you can use this script like
./HexToRgba.sh 48f442
which returns72,244,66
.pimatic-google-calendar | pimatic-wmi | pimatic-snmp | pimatic-wakeonlan |
Like my work? Then consider a donation
Follow me: www.thorstenreichelt.de -
@thost96 working great! Maybe a newbe question but what is the best way to get the result in a pimatic variable?
-
@gratizzz try this code. Update info where needed;
#!/bin/sh hex=`echo $1 | tr '[:lower:]' '[:upper:]'` a=`echo $hex | cut -c-2` b=`echo $hex | cut -c3-4` c=`echo $hex | cut -c5-6` r=`echo "ibase=16; $a" | bc` g=`echo "ibase=16; $b" | bc` b=`echo "ibase=16; $c" | bc` #post to pimatic #generate value to variable, seperated by a comma value=$r','$g','$b #pimatic username user=yourusername #pimatic password password=yourpassword #variable you want to change variable=test #pimatic ip address pimaticip=192.168.0.0 #do the actual variable change through patching curl -s -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$value'"}' --user "$user:$password" http://$pimaticip/api/variables/$variable > /dev/null exit 0
Since the forum alters posted code, here is a pastebin link if copying this code doesnt work;
Use sameway as mentioned before.
-
This post is deleted!