Displaying CPU temperature in Home Assistant

CPU temperature screenshot in Home Assistant

Earlier in the week, I mentioned that I’d bought a new case to keep my Raspberry Pi cool. So that I can keep an eye on the CPU temperature, and hope that it doesn’t overheat again, I’ve added this as a sensor in Home Assistant.

Adding a CPU temperature sensor to Home Assistant isn’t as straightforward as most other integrations. It’s not included in the System monitor integration, for example. When I was searching for solutions, I found all sorts, including one which required installing several packages from Aptitude, a script, and an MQTT broker. To be fair, that was designed to monitor multiple Raspberry Pis remotely; all I needed was just to poll the CPU temperature of the device that Home Assistant was running on.

Command line integration

Whilst not as straightforward as adding an integration, there is a relatively simple way of adding a CPU temperature sensor using the Command line integration. Indeed, it’s one of the given usage examples, which I’ve copied below:

# Example configuration.yaml entry
command_line:
  - sensor:
      name: CPU Temperature
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      # If errors occur, make sure configuration file is encoded as UTF-8
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(1) }}"

You’ll need to add this to your configuration.yaml file, and then restart Home Assistant. You should now have a ‘CPU Temperature’ entity, which you can add to a card to display on your home dashboard.

As well as running the command, the example code also adds the relevant units, and also reformats the numbers. If you open a terminal window and run the cat /sys/class/thermal/thermal_zone0/temp command on its own, you’ll get a value like ‘36511’. So, the value_template line divides the number by 1000 (or specifically multiplies it by 0.001, but the result is the same), and rounds it to one decimal place.

Once you’ve got the entity into Home Assistant, you can log your CPU temperature over time, and even display it as a graph if you want. You can also build automations, so that you can receive notifications when your CPU temperature is too high. For a Raspberry Pi, ‘too high’ is 85°C.

Raspberry Pi cooling fan and case

A photo of my Raspberry Pi in its new case with a cooling fan

We finally had some nice, warm weather a couple of weeks ago. Which was nice for being outside, but not so nice for my poor little Raspberry Pi, which couldn’t keep cool. So, I’ve upgraded it with this cooling fan and case from The Pi Hut.

Until now, I’ve been using the standard, official Raspberry Pi case. Which does the job of keeping dust out off the main board and protecting it, but not much else. As it’s plastic, it doesn’t do a good job of heat dissipation.

This was a problem last week, as my Raspberry Pi was getting so hot that it was shutting itself down to prevent damage. The impact of this was that my phone couldn’t access the internet, as I use AdGuard Home as the DNS server.

Cooling options

When it comes to cooling down a computer, there are three ways of doing it. Most use all three:

  • Ventilation – letting air flow through the computer
  • Active cooling – using a fan (or water cooling system) to move hot air away
  • Heat dissipation – using heat sinks to help get heat away from components like the processor

The Raspberry Pi has an ARM processor which is a RISC (Reduced Instruction Set Computer) type, and these tend to run cooler than CISC (Complete Instruction Set Computer) processors like those from AMD and Intel. This is why just about every smartphone uses ARM processors, as otherwise they would probably need fans too. Let’s just say Intel’s attempts at putting x86 processors into smartphones didn’t go well.

If you’re not doing anything too taxing with your Raspberry Pi, then the lack of cooling in the official case probably isn’t going to cause you issues. Indeed, I’d only had occasional issues until the recent warm weather. In addition to Home Assistant and AdGuard, my Raspberry Pi also runs Plex, MariaDB, Nextcloud, Calibre-Web, a Matter server and Nginx Proxy Manager, and it manages all these okay normally.

Cooling case

I ordered the new case from The Pi Hut on a Friday, and it arrived through my letterbox within 24 hours. It’s only £10 and includes a fan, which plugs into your Raspberry Pi’s GPIO (General Purpose Input and Output) ports for power. It comes in a tiny package, because there’s some assembly involved; essentially, you get four acrylic plates, the fan, and lots of screws. Each acrylic plate has been laser cut, and peeling off the protective film and popping out the tabs is quite satisfying.

You’ll need a screwdriver; I have one from the iFixit Essential Electronics Toolkit which seems to be the same one used in the assembly guide. Preparing the plates actually takes longer than the assembly – there’s not many screws and it all slots together.

Up and running with the cooling fan

Once assembled, I re-connected all the cables and booted my Raspberry Pi up. And then had to unscrew the top and re-connect the cooling fan wires as I’d put them in backwards. But after that, the fan whirred into action and I could feel a slight breeze coming out.

The fan is whisper quiet; whilst my hearing isn’t the best, I couldn’t hear it at all. It’s also worth noting that I run my Raspberry Pi on Debian, and not the official Raspberry Pi OS, and yet the fan still works. In other words, there’s no special drivers or scripts to install to get it to work.

If heat is still a problem, then there’s still plenty of space inside the case to add heat sinks, and again, The Pi Hut has you covered. In the meantime, I’ll see how I get on with this new case.

Water cooling?

I mentioned liquid cooling, which is more effective than a cooling fan, and sometimes used for high performance gaming computers. Of course, someone has done this for their Raspberry Pi, and the video is embedded above. The cooling system is huge compared to the Raspberry Pi board, which suggests that just because you can, doesn’t mean you should.

Modern Image Formats plugin

A screenshot of the Modern Images Format plugin in the WordPress plugin directory

I’ve recently started using the Modern Image Formats plugin for WordPress, which automatically converts any images you upload to the WordPress Media Library to the new WebP and AVIF image formats.

Both formats offer better image compression than GIF, JPEG or PNG, and AVIF is particularly good. Mozilla reckons it’s the ‘next big thing’ for images on web pages. All modern web browsers support it, and have done so for a couple of years; it was added to Firefox in version 93 in October 2021.

I’m old enough to remember when PNG images were the next big thing, and were expected to overtake the GIF format which was limited to 256 colours and encumbered by patents. Suffice to say that GIFs are still alive and well in their animated format.

If you have a WordPress blog, consider giving the Modern Image Formats a try. It works in the background, and should make your images smaller. That way, they’ll take up less disk space, and download quicker – especially for users on slower connections. It won’t convert every image – sometimes, the original JPEG or PNG may be smaller, and so it’ll leave these alone.

I’ve been using it for some time now and no-one seems to have complained that the images aren’t working yet.

Some 2029 election predictions

An AI-generated image of a fortune teller looking into a crystal ball which says 2029

Okay, so I appreciate that we’ve only just got the 2024 general election out of the way. It’s likely that the next general election will be in 2029, and so I’m going to make some predictions. Mainly because it’ll be interesting to look back on them in five years time, to see if I was right. So, here’s what I predict:

The Tories won’t win a majority

I suspect that the Conservative party will be out of power for at least the next two parliamentary terms, and so will lose the next election in 2029. We know that Rishi Sunak will step aside as leader, once a successor is found, and so there will be a leadership election soon. We also know that, to be eligible to stand, you have to be an elected MP – and there aren’t many left now. Penny Mordaunt, for example, was seen as a potential candidate, but she lost her seat. Jeremy Hunt has also ruled himself out, despite having narrowly retained his seat in the House of Commons. He has stood twice before for leader and lost both times.

The names that are being discussed are:

  • Suella Braverman
  • Priti Patel
  • Kemi Badenoch
  • James Cleverly
  • Robert Jenrick
  • Victoria Atkins

As we saw last time, the Conservative party membership, when faced with a choice between Rishi Sunak and Liz Truss, went for Truss and triggered the Truss-Kwarteng Budget Crisis. Rishi was then brought in as leader after the economy crashed and Truss was forced out. I mention this, because Rishi was arguably the better choice (though not much better) and yet the mostly white, mostly older party membership voted for Truss. This wouldn’t be good news for Patel, Braverman and Badenoch.

The 1922 Committee

There’s also the issue of the rules of the 1922 Committee of backbench Tory MPs. I don’t have a better source other than this thread on Bluesky, but to be a candidate in a Conservative Party leadership contest, you need the support of 100 MPs. This is regardless of how many Conservatives MPs there are – which is currently 121. Therefore, any potential candidates are going to have to get the support of more than 80% of sitting MPs, and MPs will be asked to back multiple candidates – assuming that’s even allowed. Oh, and once a leader is elected, if 15% of sitting MPs send a letter to the chair of the 1922 Committee, a vote of no confidence can be instigated. That’s only 19 MPs in the current Parliament, as opposed to over 60 before.

Of course, I wouldn’t be surprised if the 1922 Committee and/or the Conservative Party itself changes its constitution, to adapt to having a historically low number of MPs.

After the 2029 election, there will potentially be a new crop of MPs who have better leadership qualities, and who can’t as easily be blamed for the mess that the Tories have made until now.

Labour will win again in 2029, but with a smaller majority

Labour have a lot of work to do. Even though yesterday was a Saturday, the first cabinet meeting took place, as a sign that the new government wants to hit the ground running. Of course, it could have been mostly performative, but most government roles have already been filled.

Interestingly, there’s a couple of appointments to ministerial roles outside of the House of Commons:

  • James Timpson, boss of the Timpsons business, is Minister for Prisons, Parole and Probation. Timpsons employs many ex-prisoners to help their rehabilitation and reduce re-offending
  • Sir Patrick Vallance is the new Science Minister – you may remember him as Britain’s chief medical officer during the Covid pandemic and his regular appearances alongside Prof Sir Chris Whitty.

I’m guessing both will need to be appointed as members of the House of Lords, but it’s refreshing to see people with relevant knowledge and experience being appointed to suitable roles. It gives me hope that this will be a government that actually gets things done, and I hope that, by 2029, they’ll have done enough to warrant re-election.

Not all of Reform’s MPs will last

I suspect that Nigel Farage is the dog that caught the car. He’s succeeded at being elected as an MP on his eighth attempt, but when faced with the day-to-day reality of being an MP of a small party, I suspect he’ll get bored soon enough and quit, triggering a by-election. Depending on who wins the Tory leadership contest, they may end up joining the Conservative party, although that will prove controversial and may see others quit in protest.

The same may happen with the handful of independents who were elected; either they’ll quit, or join one of the major parties.

There may be another coalition government

If Labour doesn’t do so well next time and we end up with a hung parliament, then I can see Labour potentially going into coalition with the Liberal Democrats. The SNP and/or Green Party may join too, depending on how many MPs they have and how many are needed to get a majority. Turnout was low this time and Labour managed to get elected with a thumping majority despite winning fewer votes overall than in 2019. So, Labour will need to get more people out to vote for them next time, rather than rely on a combination of apathy and split votes among the opposition.

Before the election, Labour talked about automatic voter registration, which would ensure many more people are registered to vote. Whilst they haven’t committed themselves to completely abolishing voter ID (which stopped 14,000 people from voting in 2023’s local council elections), there are likely to be changes to what ID will be accepted. I’m against voter ID personally – it tries to fix a practically non-existent problem – but accepting a wider variety of ID would be an improvement. The Electoral Reform Society shows an example of two almost identical Oyster cards, one issued to a young person and one to someone over 60, but only the latter is accepted under the current rules.

I think that’ll do for predictions. They say that a week is a long time in politics, so five years is almost an epoch.

A General Election debrief

An AI-generated illustration of an elephant dressed as a politician standing in front of a podium, surrounded by supporters.

So, it’s been around 13 hours since the polls closed last night, and we have a new Prime Minister in Sir Keir Starmer. Obviously, as a Labour Party member, I’m delighted that Labour have won the election, and with a sizeable majority too.

This is a quick, stream-of-consciousness blog post reacting to the results, and what I think it means for each party. I’ll be referring to these statistics from the BBC throughout.

Labour

Obviously this is, for the most part, a fantastic result for Labour. Having had a dire outcome in the last General Election in 2019, to come back and win a sizeable majority of seats is an impressive turnaround.

It’s not a perfect result; some polls in the run-up to the election suggested an even bigger win, and Labour has only gained 1.6% of the total votes compared to last time. And some seats have been lost, notably two in Leicester and one in the new Batley and Dewsbury constituency (which covers part of the old constituency of Batley and Spen where Jo Cox was assassinated in 2016). These both have large Muslim populations who have not approved of Labour’s stance in relation to the war in Gaza.

The limited swing in the popular vote suggests that people have not voted enthusiastically for Labour, but are voting against the Conservatives. Whilst it could be 2029 before we have another election, Labour may need to do more to convince people to stick with them next time. I believe Labour’s strategy has deliberately been vague and uncontroversial to get elected, and marks a break from the Jeremy Corbyn era (who incidentally retained his seat as an independent candidate). Now that they’re in power, with a healthy majority, I hope that they will pursue a more progressive agenda. Labour could definitely do more to reward those on the left who have backed them, especially around LGBTQ+ issues. Kier Starmer wrote an op-ed piece for Attitude magazine, to which its editor has had to add clarification based on Starmer’s comments about Trans* people in recent weeks.

Conservatives

The Tories have taken a deserved battering. After winning a majority last time, we’ve had two changes of Prime Minister, and a government that has looked increasingly out of ideas. Big issues like the state of the NHS, failing school buildings, universities approaching bankruptcy, and thousands of refugees fleeing conflict risking their lives on small boats in the English Channel, have not been tackled. Instead, we’ve had ‘culture wars’ and inaction.

No wonder this became the worst defeat in the party’s history for what it calls itself ‘the natural party of government‘. It wasn’t as bad as some polls suggested – one had the Tories in third place behind the Liberal Democrats. But they have less than 1/5th of the seats in the Commons now, with a net loss of 250 – more than two-thirds of the seats they were defending. And whilst Rishi Sunak retained his seat, many of his government colleagues did not – nor did previous Prime Minister Liz Truss. It’s also notable that Wales now has no Tory MPs anymore.

Liberal Democrats

As mentioned, some pre-election polls predicted that the LibDems would win more seats than the Tories, making them the official opposition. It would be very funny if that had happened, with both the government and main opposition formed of centre-left parties. This didn’t come to pass – the Tories didn’t quite as terribly – but with 71 seats, the LibDems have more than they did in 2010 when they entered a coalition with the Tories.

Whilst Ed Davey has some skeletons in his closet from his time as a minister with responsibility for the Post Office during the Horizon scandal, he ran an entertaining and well-targeted campaign. His various stunts brightened up the pre-election period, and by focussing their campaign on a number of core target seats, they’ve pulled off a great result.

Reform UK

Urgh. If I have to say the phrase ‘The Right Honourable Nigel Farage MP’, it’ll be through gritted teeth. On his eighth attempt, he has finally become an MP, representing Clacton-on-sea in Essex. Reform’s popularity surged throughout the pre-election period, and even last night’s exit poll predicted that they would win 17 seats. Despite more than 4 million people voting for them (urgh again), they only picked up 4 seats – three of which are seaside constituencies: the aforementioned Clacton, along with Great Yarmouth and Boston & Skegness.

If we had some form of proportional representation, then Reform would have won more seats than the LibDems and become the third-largest party. As it is, by fielding a candidate in just about every constituency, arguably they spread themselves too thinly. At best, they split the right-wing vote and helped Labour into power.

Green Party/ies

The Green Party of England and Wales have held a single seat in Brighton for a few years, but never managed to capitalise on this elsewhere. Until now, having won 4 MPs this time, and almost 2 million votes. That puts them on a par with Reform, so, theoretically they should receive the same amount of airtime. This is a really good result for them.

Workers Party GB

George Galloway’s latest vehicle has run into a siding, again. Having won a by-election in Rochdale just four months ago, Galloway managed to lose his seat, and none of their other candidates did any better. Nationally, they picked up over 200,000 votes, which is more than Plaid Cymru achieved in Wales. No doubt Galloway will pop up again in another constituency by-election in time.

A new Prime Minister

So, we have our sixth Prime Minister since our eight-year-old was born in 2015. I’m hoping for a period of relative stability – for context, I was 32 when my sixth Prime Minister, Theresa May, took up the post in 2016. Keir Starmer has promised ‘change’ – let’s hope it’ll be effective change for the better.

As for the rest of the world? I hope that Britain’s ability to move on from having a right-wing populist government will give some hope to those in the USA and France, who have imminent elections.

It’s polling day!

A photo of a sign saying 'Polling Station' on the side of a building

Today’s the day when you can vote in the UK’s General Election (assuming you haven’t already voted by post). The polling stations opened at 7am, and you have until 10pm to get out there and vote.

If you’re not sure where your polling station is, use WhereDoIVote.co.uk – just pop your postcode in. Similarly, WhoCanIVoteFor.co.uk will tell you who will be on your ballot paper, and (most likely) some more information about the candidates and what they stand for.

You don’t need to take your polling card with you, but you must bring some photo ID with you. The Electoral Commission has an extensive list of what forms of ID are accepted, but the main ones include your passport and driving licence.

I’ll be off to vote in person this morning. Tomorrow, I’ll try to find the time to write about the result, once we have a picture of which party (or coalition of parties) is likely to be in government. I may or may not stay up for the exit polls tonight.

Phomemo D30 Bluetooth Label Printer review

A photo of a Phomemo D30 Bluetooth Label Printer

We’ve had this little Phomemo D30 Bluetooth label printer (sponsored link) for about 3 1/2 years now, and it’s a fab little gizmo.

It lets you quickly print labels from your phone, with text or emojis, using the Print Master app. It’s quick, as it uses thermal printing in the same way that receipts are printed in shops. The label printer itself is also quite compact – about the same height and width as a smartphone, but about twice the thickness. It comes with a built-in rechargeable battery, and a micro-USB port for charging. There’s a variety of colours to choose from – we have a ‘green’ one that’s more turquoise, but they come in pink, purple, grey and a cheaper all-white model.

The Print Master app is relatively easy to use. You select the size of label to match, type what you want and add any emojis. There are also templates that you can use, and a variety of fonts. When you’re ready to print, you can select the number of copies, and it’ll pop out of your printer in a couple of seconds.

We’ve used our label printer extensively since we bought it. It was especially useful in our new kitchen as it meant that we could label boxes of things in the cupboards. We also use it on a regular basis to label leftovers before they go in the freezer. It’s easier and neater than writing labels by hand.

Madam Misfit

A photo of Madam Misfit wearing a peacock outfit performing at Sci-Fi Weekender in Great Yarmouth in March 2023.

I’m going to talk about one of my favourite artists of the moment: Madam Misfit. She’s been at the past three Sci-Fi Weekenders and is always popular with the crowd (although we missed her this time as she was on really late). Her first appearance saw the smaller venue (‘The Spaceport’) filled to bursting, and so she’s rightly been on the main stage for her two most recent events.

I first found out about Madam Misfit through her collaborations with Professor Elemental (who we have also seen numerous times). Her music sits between Electro Swing and Chap Hop, combining singing and rap elements in songs that are very easy to dance to. As well as Sci-Fi Weekender, you can often find her at Steampunk gatherings, and co-hosting her Carnival of Chaos, a variety show.

Most of her music is on Spotify, but there’s also a few singles that are exclusive to Bandcamp, including her latest, Power Up. Also, if you want her song ‘Crap Romance’ (a parody of the Lady Gaga song), then you’ll need to buy her first album, The Elixir of Swing, on audio CD. Some of my favourite songs of hers are her cover of the Inspector Gadget theme tune, and the theme tune to The Wombles where Misfit plays the oboe.

Like many independent artists, you can also support her on Patreon – her third album should be coming out soon.