[{"data":1,"prerenderedAt":716},["ShallowReactive",2],{"Categories":3,"NavIndexCategoriesCountFooter":203,"content-\u002F2023\u002F01\u002F02\u002Fmonitor-cpu-temp-over-mqtt-in-home-assistant\u002F":204},[4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,68,70,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202],{"category":5},"System Administration",{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},"Software Development",{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":27},{"category":27},{"category":67},"Drones & RC",{"category":69},"DIY Projects",{"category":67},{"category":72},"Photography",{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":67},{"category":67},{"category":72},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":5},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":67},{"category":67},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":72},{"category":67},{"category":138},"3D Printing - Laser Cutting - CNC",{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":5},{"category":138},{"category":27},{"category":27},{"category":138},{"category":138},{"category":72},{"category":158},"Photography,3D Printing - Laser Cutting - CNC",{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":67},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":181},"Home Assistant",{"category":181},{"category":72},{"category":27},{"category":27},{"category":72},{"category":138},{"category":5},{"category":72},{"category":72},{"category":138},{"category":27},{"category":181},{"category":181},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},191,{"id":205,"title":206,"body":207,"category":181,"date":701,"description":213,"embedImage":702,"extension":703,"image":684,"intro":704,"meta":705,"navigation":297,"path":706,"seo":707,"series":702,"sitemap":708,"stem":709,"tags":710,"__hash__":715},"content\u002F2023\u002F01\u002F02\u002Fmonitor-cpu-temp-over-mqtt-in-home-assistant.md","Monitor CPU temp over MQTT in Home Assistant",{"type":208,"value":209,"toc":692},"minimark",[210,214,217,222,235,239,246,252,256,259,396,399,403,408,411,539,543,556,675,678,685,688],[211,212,213],"p",{},"One of two Intel NUC units had a failing fan. To make sure that the replacement was working as expected - some kind of graph was needed. The other NUC is fanless - so runs at a higher temperature.",[211,215,216],{},"Various systems exist for this - grafana etc. - but this was a quick fix and home assistant with MQTT was already available.",[218,219,221],"h2",{"id":220},"prerequisites","Prerequisites",[223,224,225,229,232],"ul",{},[226,227,228],"li",{},"Home assistant running",[226,230,231],{},"MQTT addon to home assistant running and configured (with at least one \"local user\")",[226,233,234],{},"mosquitto-clients package installed on both NUCs",[218,236,238],{"id":237},"getting-the-temperature","Getting the temperature",[211,240,241,242],{},"Both NUCs are running debian linux. In both cases - there is some information under ",[243,244,245],"code",{},"\u002Fsys\u002Fclass\u002Fthermal\u002Fthermal_zone*",[211,247,248,249],{},"After some digging around and using lm-sensors to find out what the current temperature on the CPU was - it turned out that on both boxes it was ",[243,250,251],{},"\u002Fsys\u002Fclass\u002Fthermal\u002Fthermal_zone2\u002Ftemp",[218,253,255],{"id":254},"sending-the-temperature","Sending the temperature",[211,257,258],{},"A simple script to post the data (values of MQTT_* variables need to be set in the script for running):",[260,261,266],"pre",{"className":262,"code":263,"language":264,"meta":265,"style":265},"language-shell shiki shiki-themes github-dark","HOSTNAME=`hostname`\n\nCPU=$(\u003C\u002Fsys\u002Fclass\u002Fthermal\u002Fthermal_zone2\u002Ftemp)\nCPU=$((CPU\u002F1000))\nmosquitto_pub -h $MQTT_HOST -p $MQTT_PORT -u \"$MQTT_USER\" -P \"$MQTT_PASS\" -t \"$HOSTNAME\u002FCPU\u002Ftemp\" -m $CPU -q 1\n","shell","",[243,267,268,292,299,316,332],{"__ignoreMap":265},[269,270,273,277,281,285,289],"span",{"class":271,"line":272},"line",1,[269,274,276],{"class":275},"s95oV","HOSTNAME",[269,278,280],{"class":279},"snl16","=",[269,282,284],{"class":283},"sU2Wk","`",[269,286,288],{"class":287},"svObZ","hostname",[269,290,291],{"class":283},"`\n",[269,293,295],{"class":271,"line":294},2,[269,296,298],{"emptyLinePlaceholder":297},true,"\n",[269,300,302,305,307,310,313],{"class":271,"line":301},3,[269,303,304],{"class":275},"CPU",[269,306,280],{"class":279},[269,308,309],{"class":275},"$(",[269,311,312],{"class":279},"\u003C",[269,314,315],{"class":275},"\u002Fsys\u002Fclass\u002Fthermal\u002Fthermal_zone2\u002Ftemp)\n",[269,317,319,321,323,326,329],{"class":271,"line":318},4,[269,320,304],{"class":275},[269,322,280],{"class":279},[269,324,325],{"class":275},"$((",[269,327,328],{"class":287},"CPU\u002F1000",[269,330,331],{"class":275},"))\n",[269,333,335,338,342,345,348,351,354,357,360,363,366,368,371,373,376,378,381,384,387,390,393],{"class":271,"line":334},5,[269,336,337],{"class":287},"mosquitto_pub",[269,339,341],{"class":340},"sDLfK"," -h",[269,343,344],{"class":275}," $MQTT_HOST ",[269,346,347],{"class":340},"-p",[269,349,350],{"class":275}," $MQTT_PORT ",[269,352,353],{"class":340},"-u",[269,355,356],{"class":283}," \"",[269,358,359],{"class":275},"$MQTT_USER",[269,361,362],{"class":283},"\"",[269,364,365],{"class":340}," -P",[269,367,356],{"class":283},[269,369,370],{"class":275},"$MQTT_PASS",[269,372,362],{"class":283},[269,374,375],{"class":340}," -t",[269,377,356],{"class":283},[269,379,380],{"class":275},"$HOSTNAME",[269,382,383],{"class":283},"\u002FCPU\u002Ftemp\"",[269,385,386],{"class":340}," -m",[269,388,389],{"class":275}," $CPU ",[269,391,392],{"class":340},"-q",[269,394,395],{"class":340}," 1\n",[211,397,398],{},"This is then trigged via cron every 5 minutes.",[218,400,402],{"id":401},"displaying-the-data","Displaying the data",[404,405,407],"h3",{"id":406},"creating-the-sensors","Creating the sensors",[211,409,410],{},"Add the following to home assistant configuration.yaml",[260,412,416],{"className":413,"code":414,"language":415,"meta":265,"style":265},"language-yaml shiki shiki-themes github-dark","mqtt:\n  sensor:\n    - state_topic: \"hostname1\u002FCPU\u002Ftemp\"\n      device_class: \"temperature\"\n      name: \"Hostname 1 CPU Temperature\"\n      state_class: \"measurement\"\n      unit_of_measurement: \"°C\"\n    - state_topic: \"hostname2\u002FCPU\u002Ftemp\"\n      device_class: \"temperature\"\n      name: \"Hostname 2 CPU Temperature\"\n      state_class: \"measurement\"\n      unit_of_measurement: \"°C\"\n","yaml",[243,417,418,427,434,448,458,468,479,490,502,511,521,530],{"__ignoreMap":265},[269,419,420,424],{"class":271,"line":272},[269,421,423],{"class":422},"s4JwU","mqtt",[269,425,426],{"class":275},":\n",[269,428,429,432],{"class":271,"line":294},[269,430,431],{"class":422},"  sensor",[269,433,426],{"class":275},[269,435,436,439,442,445],{"class":271,"line":301},[269,437,438],{"class":275},"    - ",[269,440,441],{"class":422},"state_topic",[269,443,444],{"class":275},": ",[269,446,447],{"class":283},"\"hostname1\u002FCPU\u002Ftemp\"\n",[269,449,450,453,455],{"class":271,"line":318},[269,451,452],{"class":422},"      device_class",[269,454,444],{"class":275},[269,456,457],{"class":283},"\"temperature\"\n",[269,459,460,463,465],{"class":271,"line":334},[269,461,462],{"class":422},"      name",[269,464,444],{"class":275},[269,466,467],{"class":283},"\"Hostname 1 CPU Temperature\"\n",[269,469,471,474,476],{"class":271,"line":470},6,[269,472,473],{"class":422},"      state_class",[269,475,444],{"class":275},[269,477,478],{"class":283},"\"measurement\"\n",[269,480,482,485,487],{"class":271,"line":481},7,[269,483,484],{"class":422},"      unit_of_measurement",[269,486,444],{"class":275},[269,488,489],{"class":283},"\"°C\"\n",[269,491,493,495,497,499],{"class":271,"line":492},8,[269,494,438],{"class":275},[269,496,441],{"class":422},[269,498,444],{"class":275},[269,500,501],{"class":283},"\"hostname2\u002FCPU\u002Ftemp\"\n",[269,503,505,507,509],{"class":271,"line":504},9,[269,506,452],{"class":422},[269,508,444],{"class":275},[269,510,457],{"class":283},[269,512,514,516,518],{"class":271,"line":513},10,[269,515,462],{"class":422},[269,517,444],{"class":275},[269,519,520],{"class":283},"\"Hostname 2 CPU Temperature\"\n",[269,522,524,526,528],{"class":271,"line":523},11,[269,525,473],{"class":422},[269,527,444],{"class":275},[269,529,478],{"class":283},[269,531,533,535,537],{"class":271,"line":532},12,[269,534,484],{"class":422},[269,536,444],{"class":275},[269,538,489],{"class":283},[404,540,542],{"id":541},"lovelace-card","Lovelace card",[211,544,545,546],{},"This uses ",[547,548,555],"a",{"href":549,"rel":550,"target":554},"https:\u002F\u002Fgithub.com\u002Fkalkih\u002Fmini-graph-card",[551,552,553],"nofollow","noopener","noreferer","_blank","mini graph card",[260,557,559],{"className":413,"code":558,"language":415,"meta":265,"style":265},"type: custom:mini-graph-card\nname: CPU Temperatures\nheight: 200\nentities:\n  - entity: sensor.hostname_1_cpu_temperature\n    show_state: true\n    name: Hostname 1\n  - entity: sensor.hostname_2_cpu_temperature\n    show_state: true\n    name: Hostname 2\nshow:\n  points: true\n",[243,560,561,571,581,591,598,611,621,631,642,650,659,666],{"__ignoreMap":265},[269,562,563,566,568],{"class":271,"line":272},[269,564,565],{"class":422},"type",[269,567,444],{"class":275},[269,569,570],{"class":283},"custom:mini-graph-card\n",[269,572,573,576,578],{"class":271,"line":294},[269,574,575],{"class":422},"name",[269,577,444],{"class":275},[269,579,580],{"class":283},"CPU Temperatures\n",[269,582,583,586,588],{"class":271,"line":301},[269,584,585],{"class":422},"height",[269,587,444],{"class":275},[269,589,590],{"class":340},"200\n",[269,592,593,596],{"class":271,"line":318},[269,594,595],{"class":422},"entities",[269,597,426],{"class":275},[269,599,600,603,606,608],{"class":271,"line":334},[269,601,602],{"class":275},"  - ",[269,604,605],{"class":422},"entity",[269,607,444],{"class":275},[269,609,610],{"class":283},"sensor.hostname_1_cpu_temperature\n",[269,612,613,616,618],{"class":271,"line":470},[269,614,615],{"class":422},"    show_state",[269,617,444],{"class":275},[269,619,620],{"class":340},"true\n",[269,622,623,626,628],{"class":271,"line":481},[269,624,625],{"class":422},"    name",[269,627,444],{"class":275},[269,629,630],{"class":283},"Hostname 1\n",[269,632,633,635,637,639],{"class":271,"line":492},[269,634,602],{"class":275},[269,636,605],{"class":422},[269,638,444],{"class":275},[269,640,641],{"class":283},"sensor.hostname_2_cpu_temperature\n",[269,643,644,646,648],{"class":271,"line":504},[269,645,615],{"class":422},[269,647,444],{"class":275},[269,649,620],{"class":340},[269,651,652,654,656],{"class":271,"line":513},[269,653,625],{"class":422},[269,655,444],{"class":275},[269,657,658],{"class":283},"Hostname 2\n",[269,660,661,664],{"class":271,"line":523},[269,662,663],{"class":422},"show",[269,665,426],{"class":275},[269,667,668,671,673],{"class":271,"line":532},[269,669,670],{"class":422},"  points",[269,672,444],{"class":275},[269,674,620],{"class":340},[211,676,677],{},"Given my actual hostnames - this generates the following graph:",[211,679,680],{},[681,682],"img",{"alt":683,"src":684},"Home assistant dashboard card showing CPU temperatures","\u002Fimages\u002Fposts\u002F2023\u002F01\u002Ftemperatures.png",[211,686,687],{},"The NUC with the new fan is holding at approx 40C which is fine.",[689,690,691],"style",{},"html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .s4JwU, html code.shiki .s4JwU{--shiki-default:#85E89D}",{"title":265,"searchDepth":294,"depth":294,"links":693},[694,695,696,697],{"id":220,"depth":294,"text":221},{"id":237,"depth":294,"text":238},{"id":254,"depth":294,"text":255},{"id":401,"depth":294,"text":402,"children":698},[699,700],{"id":406,"depth":301,"text":407},{"id":541,"depth":301,"text":542},"2023-01-02 09:27 +0100",null,"md","A quick fix to get CPU temperature over time from a couple of Intel NUC units",{},"\u002F2023\u002F01\u002F02\u002Fmonitor-cpu-temp-over-mqtt-in-home-assistant",{"title":206,"description":213},{"loc":706},"2023\u002F01\u002F02\u002Fmonitor-cpu-temp-over-mqtt-in-home-assistant",[423,711,712,713,714],"home assistant","debian","linux","NUC","29d6qyfMFs3UGL1X2L4okVZpaXe3CbXsvG-XM-ZfcBI",1775293005714]