Connecting a Geiger Counter to Home Assistant

Some time ago I bought a radiation sensor also known as a Geiger Counter. It can display the counts per minute on the built in display. The radiation sensor is based on an open-source board which is connected to a geiger muller tube. These small radiation sensors are very inexpensive and can be bought on many places online. I added a part list on the end of this post.

Everything is built in a battery powered 3D printed case so you can take it with you everywhere.

Connecting the board to a linux based system.

Now comes the interesting part. The board has a TTL-serial connector. This is a serial connector operates at Transistor to Transistor Voltage levels (3.3 Volt). It can be connected to the computer through a ttl-usb adapter (TTLSerial<>USB converter) which converts the signals to +15 volt serial voltage. When connected to a computer, the counter can be powered from usb and simultaneously output to the standard serial terminal. The output is written in Counts Per Minute or CPM in one minute intervals.

I had a FTDI cable laying around wich I connected to the 6 pins from the board. (see part list below).

For reading the values from the counter you first have to connect the FTDI TTL to Serial cable to a free usb port on your system. Now you have to find the port wich Ubuntu assigns to the adapter. If you use Ubuntu or some other linux based system, you can display the connected usb devices by running the following command:

sudo lsusb -v | grep 'idVendor\|idProduct\|iProduct\|iSerial'

DSMR P1 – Slimme meter via WiFi adapter met display

All the connected usb ports are shown. Find the device wich says something like FT232 UART, FTDI or TTL to Serial adapter.

Now you have to make the new usb device persistent so that the assigned serial port is the same after every restart. Note down the values from the idVendor and idProduct. Use the following file to assign the ftdi cable to a named serial port:

sudo nano /etc/udev/rules.d/99-usb-serial.rules

enter the following line with the values shown in the previous output

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB-geiger"

save the file with CTRL-O and restart the system. After the restart the following serial port is assigned to the ftdi cable: “ttyUSB-geiger” You can check if it’s created using the following command:

ls -l /dev

The new “ttyUSB-geiger” device has to be listed. Now you have to add your user to the dialout usergroup to have rights to the new created port. Use the following command:

sudo adduser user dialout

change the user to the username you use. You are now ready to read the values from the counter and save them to a file.

Reading the values from the counter and save them to a file with a service

You have to use socat to read the values from the serial port and write them to a file. First install socat using the following command:

sudo apt-get update && sudo apt-get install socat

Now create the following file /etc/systemd/system/geiger-counter.service

Description=Geiger Counter Connected to ttyUSB-geiger
ExecStart=/usr/bin/socat /dev/ttyUSB-geiger,raw,echo=0 \SYSTEM:'tee -a /~home/geiger.txt'

Make the service file executable with the following command:

sudo chmod +x  /etc/systemd/system/geiger-counter.service

The file creates the file /~home/geiger.txt. The tee -a command adds a new line for every new reading.

now reload the newly created geiger counter service:

sudo systemctl reload-or-restart geiger-counter.service

The service is loaded every time you restart your machine.

The output from the geiger counter is saved to the file /~home/geiger.txt in your home directory. You can display the values by entering the following command:

tail -f /~home/geiger.txt

Adding the measurements to Home Assistant

Adding the Geiger Counter to Home Assistant is easy. You can add the following lines to your configuration.yaml file:

  - platform: command_line
    name: Radiation
    command: "tail -n 1 ~/home/geiger.txt"
    unit_of_measurement: "CPM"

The tail -n 1 only reads the last value from the file and puts it in the Home Assistant database. To display the latest readings you have to create a new card on your dashboard. Click on the plus symbol and add the following data:

Click ons SAVE and you’re done.

Part List

Geiger Counter

TTL to USB cable

2 thoughts on “Connecting a Geiger Counter to Home Assistant”

Leave a Reply

Your email address will not be published. Required fields are marked *