adamoutler/HassOSArgonOneAddon

It is ignoring floating values

Opened this issue · 3 comments

value_a=$((100/(tmaxi-tmini)))
value_b=$((-value_a*tmini))
until false; do
read -r cpuRawTemp < /sys/class/thermal/thermal_zone0/temp #read instead of cat fpr process reduction
cpuTemp=$(( cpuRawTemp/1000 )) #built-in bash math
unit="C"
if [ "$CorF" == "F" ]; then # convert to F
cpuTemp=$(( ( cpuTemp * 9/5 ) + 32 ));
unit="F"
fi
value=$cpuTemp
test "${logTemp}" == "true" && echo "Current Temperature = $cpuTemp °$unit"
fanPercent=$((value_a*value+value_b))

In my case, I tried:

tmini = 0
tmaxi = 60
CorF = C

cpuRawTemp = 56900
Line Variable Formula Actual Expected
141 value_a 100/(tmaxi-tmini) 1 1.667
142 value_b -value_a*tmini 0 0
146 cpuTemp cpuRawTemp/1000 56 56.900
154 value cpuTemp 56 56.900
157 fanPercent value_a*value+value_b 56 94.852

We will need to multiply the values by 100, perform the operations then divide by 100. I don't have time to do this now.

@mxr can you handle this? It's related to the way bash handles fp. It's truncated at the point.

mxr commented

I don't use this addon anymore (no longer using this hardware). Not sure if bc is available but you could also try something like

value_a=$(bc <<< "scale=3; 100 / ($tmaxi - $tmini)")
value_b=$(bc <<< "scale=3; -$value_a*$tmini")