Recommended Free Tools
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Home Assistant can create a custom sensor on a Raspberry Pi 5, but the right method depends on where the reading comes from: use a template for data already in Home Assistant, REST for an HTTP endpoint, MQTT for published messages, and usually ESPHome or another networked device for a new physical sensor. The Pi 5 is typically the Home Assistant server; it does not automatically turn every sensor wired to its GPIO pins into a Home Assistant entity.
Choose the method that matches your data
| Where the value comes from | Use | Why |
|---|---|---|
| One or more existing Home Assistant entities | Template sensor | Calculates, converts, or combines values already available to Home Assistant. |
| A device or service with an HTTP endpoint | REST sensor | Home Assistant requests a value or JSON response at an interval. |
| A device or script that publishes readings | MQTT sensor | Home Assistant listens for messages on a broker rather than polling the source. |
| A sensor wired to GPIO, I²C, or SPI | Usually ESPHome or another supported device/integration | Separates hardware access from the Home Assistant host and avoids assuming Home Assistant OS is a general-purpose Linux system. |
Before configuring anything, identify the source, payload type (number, text, or JSON), update frequency, and what the sensor should do when the source goes offline. If the reading is safety-critical, do not silently turn missing data into a plausible value such as zero.
What you need for Home Assistant on a Raspberry Pi 5
- Raspberry Pi 5 with at least 2 GB of RAM, Home Assistant’s stated minimum for this installation.
- A microSD card of at least 32 GB; Home Assistant recommends an A2-rated card.
- Ethernet for the initial setup and a suitable USB-C power supply. Raspberry Pi recommends a high-quality 5 V/5 A supply; an ordinary phone charger or computer USB port may not provide adequate power.
- A display and HDMI cable can help diagnose a failed first boot, but are not normally needed for installation.
- Active cooling is recommended by Raspberry Pi for best performance. NVMe storage is optional, not a requirement for a few sensors.
Home Assistant officially supports the Pi 5 as a Home Assistant OS host. Its installation guide listed OS image 18.2 on August 18, 2026; that version will change, so choose the current Pi 5 image in Raspberry Pi Imager rather than relying on a fixed image number. See the Home Assistant Raspberry Pi installation guide and Raspberry Pi 5 specifications.
Install Home Assistant OS
- Install Raspberry Pi Imager on a computer and insert the microSD card. Writing the image erases the card.
- In Imager, choose OS → Other specific-purpose OS → Home automation → Home Assistant.
- Select the Home Assistant OS image for Raspberry Pi 5, then select the microSD card and write the image.
- Insert the card in the Pi, connect Ethernet, and connect the power supply.
- Allow the Pi to start, then open
http://homeassistant.local:8123in a browser. If local-name discovery does not work, usehttp://PI_IP_ADDRESS:8123, replacing the placeholder with the Pi’s address on your network.
Home Assistant says a Pi 4 or Pi 5 normally displays onboarding within about a minute. If it is still unavailable after five minutes, check power and Ethernet, reflash the card, and if needed connect a display to inspect startup output. The Pi 5 support announcement has additional storage guidance; for a small sensor setup, microSD remains the simpler supported starting point.
#1 Best Overall
Method 1: Create a template sensor from existing entities
Use a template when the underlying readings already appear in Home Assistant. This example averages bedroom and kitchen temperatures:
template:
- sensor:
- name: "Average Indoor Temperature"
unique_id: average_indoor_temperature
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
state: >
{% set bedroom = states('sensor.bedroom_temperature') | float(0) %}
{% set kitchen = states('sensor.kitchen_temperature') | float(0) %}
{{ ((bedroom + kitchen) / 2) | round(1) }}
Replace the example entity IDs with real ones. The states() function reads an entity state, while float(0) converts it to a number and supplies zero if conversion fails. That fallback keeps the expression from erroring, but it can conceal a missing reading. If unavailable input must remain visible, test and handle that condition explicitly instead of treating it as a genuine zero.
The name, unique ID, unit, device class, and state class each have a job: they identify the entity, describe the reading, and help Home Assistant display or record it appropriately. A measurement sensor should provide a consistent numeric state and unit. Do not mix text such as offline into a numeric measurement. Use Home Assistant’s Template Editor to test the expression, and consult the Template integration documentation. State-based template sensors update when referenced entities change; trigger-based templates are available when updates should follow an explicit schedule or other trigger.
Free tools Windows power users keep installed
One-click scans. No signup required.
Method 2: Read an HTTP endpoint with a REST sensor
If an endpoint returns JSON such as {"temperature":21.902,"humidity":44.1}, a REST sensor can extract one field:
Rank #2
sensor:
- platform: rest
name: "Custom API Temperature"
unique_id: custom_api_temperature
resource: "http://192.168.1.50/api/status"
method: GET
scan_interval: 30
timeout: 10
value_template: "{{ value_json.temperature | float }}"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
Change the address and JSON key to match your endpoint. value_json refers to a parsed JSON response. For a response that is just plain text or a number, use value, for example value_template: "{{ value | float }}". REST sensors support options such as headers, parameters, authentication, payloads, availability, and SSL verification; see the REST sensor documentation.
The documented defaults are a 30-second polling interval and a 10-second timeout; the example makes them explicit. They are not a recommendation to poll every API at that rate. Set an interval that respects the endpoint’s limits and update needs, and choose a timeout that will not leave the request waiting unnecessarily. Prefer HTTPS and keep certificate verification enabled unless there is a specific, understood reason not to. Avoid placing secrets in screenshots or publicly shared YAML.
Method 3: Receive readings over MQTT
MQTT suits devices or scripts that publish readings, especially when several distributed sources need to send updates. Home Assistant needs an MQTT broker; for Home Assistant OS, its documentation recommends the Mosquitto broker app as the easiest setup. Home Assistant’s MQTT integration requires a broker that supports MQTT 5. Add and configure the broker, then configure the MQTT integration before creating the sensor. See MQTT setup and testing.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFor a JSON message published to home/custom_sensor:
{"temperature":23.2,"humidity":43.7}
Configure a sensor that extracts the temperature and uses a separate topic to report source availability:
mqtt:
sensor:
- name: "Custom MQTT Temperature"
unique_id: custom_mqtt_temperature
state_topic: "home/custom_sensor"
value_template: "{{ value_json.temperature | float }}"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
availability_topic: "home/custom_sensor/status"
payload_available: "online"
payload_not_available: "offline"
The source must publish online or offline on the availability topic for that status configuration to reflect reality. If it publishes a raw number rather than JSON, use a matching topic and a template such as {{ value | float }}.
A retained MQTT message lets a newly connected subscriber receive the last published reading immediately. Without one, the entity may have no state until the next message arrives. To test a JSON publication from a computer with the Mosquitto client installed, replace the address with your Home Assistant host’s IP:
mosquitto_pub
-h HOME_ASSISTANT_IP
-t home/custom_sensor
-m '{"temperature":23.2,"humidity":43.7}'
For an immediate state after reconnect, add the client’s retain option (commonly -r) to the publish command. You can also use the MQTT integration’s frontend tools to listen to a topic and publish a test message. After changing MQTT configuration in YAML, restart Home Assistant to apply it; see the MQTT sensor documentation.
Rank #4
What if the sensor is wired directly to the Pi?
The Pi 5 has a 40-pin GPIO header and supports expansion interfaces, but the header alone does not make a connected sensor appear in Home Assistant. GPIO pins use 3.3 V logic: applying an incompatible voltage can damage the Pi. A sensor may also need drivers, libraries, permissions, bus configuration, or a daemon that Home Assistant OS does not provide as a general-purpose Linux environment.
For a new physical sensor, a common maintainable arrangement is to connect it to an ESP32 or ESP8266 running ESPHome and bring its entities into Home Assistant over the network. MQTT from a separate microcontroller or Linux host is another option. A supported USB or serial integration can work when the hardware is designed for it. Direct Pi wiring is possible for some projects, but do not assume a Python script that works on Raspberry Pi OS will work unchanged on Home Assistant OS.
Add the sensor to a dashboard
- Open Settings → Devices & services → Entities and search for the sensor’s name or entity ID. Confirm it has a state and the intended unit.
- Open the dashboard, choose to edit it, and add a card such as Entities or Gauge. Select the new entity and save.
- For a numeric sensor, verify the displayed unit and precision. If you expect a history graph or long-term statistics, make sure the state is numeric and its unit and state class stay consistent.
If the entity was defined in YAML but is missing, first validate the configuration using Home Assistant’s configuration-check function. Fix indentation and errors, then restart if the integration requires it. Look under Devices & services and in the entity registry; duplicate names can lead to an automatically adjusted entity ID. Check logs for template, connection, or payload errors.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsTroubleshooting by symptom
The state is unknown or unavailable
- Check that the entity ID and source topic or URL are exact, and that the underlying entity or publisher exists.
- For REST, confirm the endpoint is reachable from the Home Assistant host, including local DNS, authentication, and response format.
- For MQTT, confirm the broker connection and exact topic spelling. Check that the availability topic is not reporting
offline. - Check whether a JSON key exists and whether the template handles an empty or malformed payload. For REST or MQTT, a defensive expression might be
{{ value_json.temperature | default(0) | float }}, but a zero fallback can hide outages; for important monitoring, preserve an unavailable state instead. - If the MQTT source sends only on change, consider retained messages so the last value is delivered after reconnection.
The value is wrong or history is missing
Verify the source field and conversion, then check unit, device class, state class, and precision. Keep a measurement numeric and consistent; alternating between numbers and text can undermine display and statistics. Ensure the unit does not change over time. A total, a measurement, and an instantaneous reading may need different state-class treatment, so use the current integration documentation for the kind of value being recorded.
Best Value
- SMART HOME LEARNING KIT--This kit combines the most common electronic components of smart home projects,developed specially for those beginners who are interested in Arduino and raspberry pi DIY.
- THE PROFESSIONAL SMART HOME KIT--This has 16 sensors modules and delicately selected sensors to detect temperature, humidity, sound, light, infrared, motion, flame,vibration,digital touch, air pressure and many other commonly-used sensors modules.
- THE MOST COMPLETE SMART HOME KIT--This universal kit are compatible for Arduino UNO R3 / Mega2560 / Mega328 /Nano / Raspberry Pi, it could DIY 16 projects according to your need.
- HIGH QUALITY GUARANTEE--We eliminate many old-fashioned sensors which have low reliability and duplicate function as other sensor in the kit, the kookye modules sensor kits are choosed carefully for our user.
- DETAILED TUTORIAL ON OUR WEBSITE--Our website provide step-by-step instruction, detailed circuit connection graph/video, verified sample code and library package which can save lot of user's research time and speed up the learning progress.
REST requests time out or the endpoint is rate-limited
Increase scan_interval, set a sensible timeout, and avoid polling more often than the source permits. If one endpoint response contains several values, consider extracting multiple sensors from the same response rather than making unnecessary repeated requests. Keep credentials private.
YAML changes do not show up
Save and check the configuration, correct any reported syntax or indentation problem, and restart when the integration requires it. Then inspect Devices & services, the entity registry, and logs. Some YAML-defined integrations do not apply changes just because the file was saved.
The Pi reboots, slows down, or overheats
Check the USB-C supply first, then cooling and storage quality. Raspberry Pi recommends a high-quality 5 V/5 A supply and says active cooling supports best performance. Poor microSD media, heavy database writes, a faulty add-on, a runaway script, or malformed traffic can also cause trouble. NVMe can be useful for heavier history or camera workloads, but it adds hardware and setup complexity and is not necessary merely to add a custom sensor.
Which setup makes sense?
- DIY hardware and maximum flexibility: Raspberry Pi 5 running Home Assistant OS. The official minimum is 2 GB RAM; more memory is for broader workloads, not a prerequisite for a custom sensor.
- New GPIO-based sensor: Pi 5 as the host plus a separate ESPHome device is often simpler to maintain than installing hardware dependencies on the Home Assistant host.
- API value: REST is direct and does not require a broker, but it polls.
- Distributed devices or pushed updates: MQTT handles publishing well, at the cost of configuring and maintaining a broker.
- Derived value: Template is the simplest option when the raw entities already exist.
- Appliance-style installation: Home Assistant Green is the plug-and-play alternative; it is not a like-for-like substitute for a Pi 5 GPIO development board. See Home Assistant Green and the installation overview.
Do not buy a 16 GB Pi solely for a small set of template, REST, or MQTT sensors. Choose hardware around the whole workload, particularly camera use, add-ons, storage, power, and cooling.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.


Leave a Reply