The documentation for Zigbee2MQTT explains how to enable automatic MQTT discovery for Home Assistant. If you want complete control of the configuration of every sensor, I suggest you disable this feature in zigbee2MQTT. You can then define the sensors manually (as you have already started to do) thereby giving complete control over their operation.
If you want to round the temperature values, you can do this:
If it doesn’t work, it means the temperature is not received as a numeric value but as a string so you first have to convert it to a floating-point number before rounding it:
If you switch to defining the sensors manually and still see duplicated sensors, it’s because the auto-discovery process has recorded the sensors in the entity registry. You will need to delete the auto-discovered versions from the entity registry (Configuration > Entity Registry. Click on an entity, a popup appears, click Delete).
Hi @hajo62 . I’m considering doing what you’re doing for maximum flexibility. Are you still managing all your devices manually like this in config files? if so can you weigh in on the pros and cons? one immediate one that I can see is that there’s no longer a “device”, but just a group of entities?
With this my sensors are detected. But I want to correct some measured values and round the results. Therefore I still have defined the sensors in the sensors.yaml file; I haven’t found another way to correct or round. But unfortunately this creates new sensors and I’ve asked, if this is the best way.
@hajo62 thanks for answering. So you are not actually able to see the device of those sensors right? You need to group them manually? My question is more about being able to see the entities grouped by device and less about general config. I’ll take a look at your question.
@hajo62 I understand that, thanks for sharing. These sensors are coming from one physical device I guess, so the question is: does the device appear under “Devices” when you go to your device-list in HA? Because I followed what you did and I can play with the different sensors of the same device, but the device itself isn’t recognized as a device.
I believe you are seeing each device twice because you are defining them twice. The first time is when you manually define a device in sensors.yaml (as an MQTT Sensor). The second time is via MQTT Discovery because you have configured this ZigBee2MQTT option:
homeassistant: true
That instructs ZigBee2MQTT to publish its devices in a way that Home Assistant discovers them automatically.
If you want convenience then MQTT Discovery is a good choice. However, if you want greater control over each device’s definition, then manual configuration is preferable. If you choose both, you will get duplication.
Okay, but…
when I now (after changing homeassistant: false) try to delete the entities, it says I can’t delete without removing the (I assume MQTT) integration first.
When I do that, I will still have my defined sensor from sensors.yaml running?
If you changed it the option to homeassistant: false it means Zigbee2MQTT will no longer creates devices via MQTT Discovery. You can confirm this by using an MQTT client like MQTT Explorer and look for topics similar to this:
homeassistant/sensor/my_sensor_name/config
There should be none.
Any entities that were originally created by MQTT Discovery will be automatically deleted. What will remain are the entities you had defined manually. Those won’t disappear unless you manually delete their configurations.
Thanks for explaining that again.
I had that in the past but forgot that on my new setup. Now it’s like I want it to be: Only one sensor per sensor and value corrected and rounded.