How can I read the battery temperature sensor readings of my Mac using python?
I have an M1 Macbook Air, Late 2020 version w/8 core CPU and 8 core GPU and I recently put a thermal pad mod onto it. However, one of the issues I saw with this was the battery temperature increases and I wanted to see if I could make a python script that can read the battery temperature sensor and if it goes above 44ºC, then I immediately shut off using the power adapter as the power source and switch to using the battery to cool it down. In addition, I reduce the brightness of the main display by 50% in order to reduce power consumption and possibly(slow down my computer) although I don't know if thats possible. Any help would be appreciated(especially about the battery temperature sensors, the screen brightness, shutting off the plugged in power source(It's a lot like Al Dante, the battery management for Mac Pro feature: https://apphousekitchen.com/feature-explanation-heat-protection/
I have already tried searching for other solutions on the internet and I've seen python modules that can get my cpu, and gpu temps but I can't find any for battery temps. I also use the Stats app for mac where I can see battery 1 and battery 2 temps and so there's definitely sensors there, but I just need python to access them.
https://github.com/freedomtan/sensors_cmdline gives you a stream of temperature dictionaries suitable for a Python implementation. The first frame contains the descriptions, followed by the value stream.
git clone https://github.com/freedomtan/sensors_cmdline && cd sensors_cmdline && make && ./sensors
Cloning into 'sensors_cmdline'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 19 (delta 6), reused 12 (delta 4), pack-reused 0
Receiving objects: 100% (19/19), 11.02 KiB | 537.00 KiB/s, done.
Resolving deltas: 100% (6/6), done.
clang -Wall -O2 -g -c -o sensors.o sensors.m
clang -o sensors sensors.o -framework Foundation -framework IOKit
./sensors
ANE MTR Temp Sensor1 (°C), GPU MTR Temp Sensor1 (°C), GPU MTR Temp Sensor4 (°C), ISP MTR Temp Sensor5 (°C), NAND CH0 temp (°C), PMGR SOC Die Temp Sensor0 (°C), PMGR SOC Die Temp Sensor1 (°C), PMGR SOC Die Temp Sensor2 (°C), PMU TP3w (°C), PMU tcal (°C), PMU tdev1 (°C), PMU tdev2 (°C), PMU tdev3 (°C), PMU tdev4 (°C), PMU tdev5 (°C), PMU tdev6 (°C), PMU tdev7 (°C), PMU tdev8 (°C), PMU tdie1 (°C), PMU tdie2 (°C), PMU tdie4 (°C), PMU tdie5 (°C), PMU tdie6 (°C), PMU tdie7 (°C), PMU tdie8 (°C), PMU2 tcal (°C), PMU2 tdev1 (°C), PMU2 tdev2 (°C), PMU2 tdev3 (°C), PMU2 tdev4 (°C), PMU2 tdev5 (°C), PMU2 tdie1 (°C), PMU2 tdie2 (°C), PMU2 tdie3 (°C), PMU2 tdie4 (°C), PMU2 tdie5 (°C), PMU2 tdie6 (°C), PMU2 tdie7 (°C), PMU2 tdie8 (°C), SOC MTR Temp Sensor0 (°C), SOC MTR Temp Sensor1 (°C), SOC MTR Temp Sensor2 (°C), eACC MTR Temp Sensor0 (°C), eACC MTR Temp Sensor3 (°C), pACC MTR Temp Sensor2 (°C), pACC MTR Temp Sensor3 (°C), pACC MTR Temp Sensor4 (°C), pACC MTR Temp Sensor5 (°C), pACC MTR Temp Sensor7 (°C), pACC MTR Temp Sensor8 (°C), pACC MTR Temp Sensor9 (°C)
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.625000, 30.500000, 30.156250, 37.292130, 51.850006, 32.489059, 32.660599, 32.401474, -21.219223, -21.294342, 31.715332, 33.602203, 33.003662, 37.077560, 33.859024, 36.433853, 37.828552, 36.862991, 36.433853, 35.146439, 51.850006, 32.664246, 31.459854, 31.974457, 31.715332, 32.751831, 39.437820, 39.974243, 38.686829, 39.330536, 39.652390, 39.437820, 39.759674, 39.115967, 27.328125, 27.968750, 28.640625, 29.984375, 26.546875, 27.046875, 29.062500, 29.750000, 29.093750, 29.546875, 30.218750, 29.234375
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.625000, 30.500000, 30.156250, 37.077560, 51.850006, 32.401474, 32.572998, 32.317520, -21.219223, -21.300476, 31.715332, 33.602203, 32.916061, 36.970276, 35.575577, 36.862991, 36.004715, 36.112000, 36.755707, 35.039154, 51.850006, 32.664246, 31.459854, 31.802933, 31.715332, 32.751831, 39.437820, 39.008682, 38.150406, 39.330536, 39.437820, 39.008682, 39.866959, 39.437820, 27.328125, 27.968750, 28.640625, 29.687500, 26.546875, 27.046875, 30.468750, 30.296875, 29.953125, 29.328125, 29.093750, 28.765625
30.000000, 30.000000, 30.000000, 30.000000, 30.000000, 30.703125, 30.578125, 30.343750, 38.043121, 51.850006, 32.401474, 32.572998, 32.401474, -21.219223, -21.300476, 31.715332, 33.602203, 32.916061, 37.721268, 35.146439, 36.326569, 36.433853, 36.219284, 37.399414, 34.288162, 51.850006, 32.580307, 31.459854, 32.229935, 31.715332, 32.835770, 39.008682, 39.652390, 38.257690, 38.794113, 39.545105, 39.437820, 38.686829, 39.437820, 28.640625, 27.968750, 27.421875, 29.687500, 26.687500, 25.281250, 30.468750, 30.296875, 29.953125, 29.328125, 29.093750, 28.765625
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.703125, 30.578125, 30.343750, 37.613983, 51.850006, 32.401474, 32.321182, 32.401474, -21.219223, -21.294342, 31.715332, 33.602203, 33.003662, 38.794113, 34.288162, 36.219284, 36.755707, 36.219284, 36.755707, 35.575577, 51.850006, 32.664246, 31.459854, 31.974457, 31.886871, 32.664246, 39.437820, 39.437820, 36.862991, 39.008682, 38.901398, 39.330536, 39.545105, 39.437820, 28.640625, 27.968750, 27.421875, 29.687500, 26.687500, 25.281250, 30.468750, 30.296875, 29.953125, 29.328125, 29.093750, 28.765625
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.703125, 30.578125, 30.343750, 37.184845, 51.850006, 32.489059, 32.401474, 32.317520, -21.219223, -21.300476, 31.715332, 33.602203, 33.003662, 37.292130, 35.146439, 36.433853, 36.433853, 36.112000, 36.004715, 34.288162, 51.850006, 32.580307, 31.459854, 31.974457, 31.715332, 32.751831, 39.330536, 39.866959, 36.755707, 39.008682, 39.652390, 39.008682, 39.437820, 39.437820, 28.640625, 27.968750, 27.421875, 29.687500, 26.687500, 25.281250, 30.468750, 30.296875, 29.953125, 29.328125, 29.093750, 28.765625
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.703125, 30.578125, 30.343750, 37.399414, 51.850006, 32.401474, 32.401474, 32.317520, -21.219223, -21.294342, 31.715332, 33.602203, 33.003662, 38.901398, 35.361008, 36.755707, 37.721268, 35.682861, 36.541138, 34.395447, 51.850006, 32.580307, 31.459854, 31.974457, 31.715332, 32.751831, 39.437820, 39.974243, 37.828552, 38.901398, 39.008682, 39.008682, 34.824585, 39.437820, 28.640625, 27.968750, 27.421875, 28.828125, 26.687500, 25.281250, 28.343750, 29.546875, 30.500000, 29.125000, 29.859375, 27.984375
30.000000, 30.000000, 30.000000, 30.000000, 31.000000, 30.750000, 30.609375, 30.281250, 37.935837, 51.850006, 32.572998, 32.401474, 32.401474, -21.219223, -21.300476, 31.802933, 33.602203, 33.003662, 37.935837, 35.575577, 37.292130, 37.399414, 36.970276, 36.219284, 34.395447, 51.850006, 32.580307, 31.459854, 31.974457, 31.715332, 32.751831, 39.223251, 39.974243, 38.150406, 39.223251, 39.437820, 35.146439, 39.545105, 39.223251, 28.203125, 28.406250, 27.421875, 28.828125, 28.203125, 26.578125, 28.343750, 29.546875, 30.500000, 29.125000, 29.859375, 27.984375