Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to set the level of precision for temp/humidity sensors? #708

Closed
mihalski opened this issue Dec 15, 2018 · 23 comments
Closed
Labels
stale Stale issues

Comments

@mihalski
Copy link

mihalski commented Dec 15, 2018

I normally use one decimal point of precision for my temp/humidity sensors and I searched but could not find any way to do this with zigbee2mqtt.

I know I could manually do it in a Home Assistant template but this would prevent the use of MQTT auto-discovery.

Thanks in advance.

P.S. Oh and I set pressure to zero decimal points of precision (ie whole numbers).

Koenkk added a commit to Koenkk/zigbee-herdsman-converters that referenced this issue Dec 15, 2018
@Koenkk
Copy link
Owner

Koenkk commented Dec 15, 2018

Implemented, see documentation on how to use it.

@mihalski
Copy link
Author

Thank you!

Would it also make sense to have a global config equivalent to the device specific config in the main section of the configuration.yaml for when you always want parameters measured with a particular level of precision (including all future sensors)?

@mihalski
Copy link
Author

I also noticed that even with precision set to 1 if the value returned by the sensor happens to be a whole number it returns an int rather than a float (ie missing the .0)

@justmvg
Copy link

justmvg commented Dec 16, 2018

I've installed 1.0.0 yesterday and made changes to the configuration.yaml to set the precision to 1 decimal instead of the default of 2. Restarted zigbee2mqtt but still receiving data with 2 decimals.
Is there anything else I should change?

I have set temperature and humidity values to have 1 decimal for 2 devices.

@Koenkk
Copy link
Owner

Koenkk commented Dec 16, 2018

@justmvg checkout the dev branch

Koenkk added a commit that referenced this issue Dec 19, 2018
@Koenkk
Copy link
Owner

Koenkk commented Dec 19, 2018

@justmvg
Copy link

justmvg commented Dec 19, 2018

@justmvg checkout the dev branch

Thank you. I managed to make it work with the dev branch.

@mihalski
Copy link
Author

mihalski commented Dec 20, 2018

Thank you so much for implementing device type specific defaults!
Granted, I don't really know what I am talking about and this is based on a quick google search, but couldn't you just use .toFixed(precision) where precision is a variable containing the number of decimal points of precision desired?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

@Koenkk
Copy link
Owner

Koenkk commented Dec 20, 2018

The problem of toFixed is that it returns a string, the values should be kept numerical.

@mihalski
Copy link
Author

Does it matter when the intended output is a JSON string? Internally it can be numerical, but when being reported as part of a MQTT JSON string it could be considered seperate.

@Koenkk
Copy link
Owner

Koenkk commented Dec 20, 2018

I don't know, can home assistant still handle it? Does it automatically do the numeric conversion?

@mihalski
Copy link
Author

My understanding of MQTT was that value types were inferred from the presentation of the JSON string. But I am about as far from an expert in the field as is possible.

@Koenkk
Copy link
Owner

Koenkk commented Dec 20, 2018

Yes that's true, but this JSON string can contain textual and numerical values.

@mihalski
Copy link
Author

mihalski commented Dec 20, 2018

I guess trying it and seeing what happens is the only ay to be sure. But as far as I understand it's all a string until context turns it into whatever type it needs to be.

@mateuszdrab
Copy link

mateuszdrab commented Jan 7, 2019

Hey guys, I'm running the latest version of zigbee2mqtt and after adding the following, I'm still seeing the messages get sent with default precision settings.

device_options:
--temperature_precision: 1
--humidity_precision: 1
--pressure_precision: 1

The - represents space

Can't get it to format right in code format.

This is put right after the serial: section and before the devices: section.

What am I doing wrong?

@Koenkk
Copy link
Owner

Koenkk commented Jan 7, 2019

@mateuszdrab are you using the dev branch?

@mateuszdrab
Copy link

mateuszdrab commented Jan 7, 2019

@mateuszdrab are you using the dev branch?

I'm on master, makes sense. I can try that later, I need to open an issue for another matter as well.

@stale
Copy link

stale bot commented Mar 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale issues label Mar 8, 2019
@Koenkk Koenkk closed this as completed Mar 8, 2019
@zerofruchtshake
Copy link

zerofruchtshake commented Mar 15, 2019

The link is not working any more :(

EDIT: Never mind, i'm stupid, found it..
EDIT2: Is there any way to change the default of all sensors at once?

@cigas4
Copy link

cigas4 commented Sep 2, 2019

@zerofruchtshake http://www.zigbee2mqtt.io/configuration/device_specific_configuration.html#changing-device-type-specific-defaults

Where should I put this:

device_options:
occupancy_timeout: 130
temperature_precision: 1

If I put this to HA configuration.yaml, I get error "Component error: device_options - Integration device_options not found."

Also tried HA Configuration - > Customization -> Entitty: Humidity sensor -> add other attribute -> name: humidity_precision value: 1 -> Reboot
But this also does not work.

wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this issue Sep 26, 2019
wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this issue Sep 26, 2019
qosmio pushed a commit to qosmio/zigbee-herdsman-converters that referenced this issue Dec 25, 2019
@kuchar91
Copy link

@zerofruchtshake http://www.zigbee2mqtt.io/configuration/device_specific_configuration.html#changing-device-type-specific-defaults

Where should I put this:

device_options:
occupancy_timeout: 130
temperature_precision: 1

If I put this to HA configuration.yaml, I get error "Component error: device_options - Integration device_options not found."

Also tried HA Configuration - > Customization -> Entitty: Humidity sensor -> add other attribute -> name: humidity_precision value: 1 -> Reboot
But this also does not work.

Put it in devices.yaml or configuration.yaml (add-on) not HA.

@settler-als
Copy link

Hello,
i try use this options in configuration zigbee2mqtt (stable and edge):

device_options:
retain: true
temperature_precision: 1
humidity_precision: 1

temperature_precision: 1 - the option works and it can be seen in the interface lovelace or z2m web ui
humidity_precision: 1 - this option does not work globally for all sensors.

When i check config in web ui -> Settings -> Raw :
when I checked the config file in web ui -> Settings -> Raw , i see only:

"device_options": {
"temperature_precision": 1
},

no "retain: true" and "humidity_precision: 1".

Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues
Projects
None yet
Development

No branches or pull requests

8 participants