In the previous tutorial we looked at adding a MQTT switch device. In this tutorial we will look at adding MQTT sensors.
Sensor entities are read only and the information sent has a value which can be a integer,string or JSON encoded data.
Sensors also have an optional device class which is very useful and should be configured. Possible device classes are here
They also have a unit of measurement as well as other properties shown on this page.
As an example we will add four temperature sensors
Below is a screen shot showing the start of the sensor section with the single switch entry above.
My sensor section has four temperature sensors and the configuration is shown below:
Notes:
Many of the settings for the fours sensors are the same. They are all temperature sensors and been given the device class of temperature.
The bedroom temperature sensor doesn’t use the availability topic and so it doesn’t need to be sent the available message, but the other sensors do.
The bedroom temperature sensor has a value template and expects to receive JSON data. e.g ‘{“temperature”:20}’. All of the other expect to see an integer,float or string.
The outside temperature sensor has been assigned to a device called outside monitor.
If I add each of these sensors to an area we see the value on the area card because we assigned the device class.
If we look at the available devices we can see our outside monitor.
To activate the sensors that have an available topic I publish the message online to the available topic.
- home/kitchen/temperature/available
- home/livingroom/temperature/available
- home/outside/temperature/available
- Good introduction to yaml here
- Home Assistant Configuration.yaml File Basics
- Adding an MQTT Device to Home Assistant
- Running home assistant in a docker container
- Smart Homes and MQTT
I struggled days to get my DIY sensors ‘available’ in HA. Tried Bard, ChatGPT, searched with Google, no answer – except from here. Simple fix. Thanks a lot!