Change decimal value

Hi!
I’m a complete novice here. I don’t understand programming at all.

So I have a presence sensor that has a distance entity, but it only displays something like this:
Cuplikan layar 2024-09-12 180118

That is about 1.2 meters.
Can I change it to 1.2? It doesn’t really matter for the unit display.

I’ve tried browsing around, but I don’t know where to start, where to put it. It’s getting frustating.
I found this template works when written in the Developers Tools > Template tab:

value_template: "{{ (states('sensor.zb_zy_m100_distance') | float * 10) | round(1) }}"

But now where do I put it? Or is there another way?
Step by step guide more appreciated.
Thanks a lot!

it looks to me like that sensor is provided by some integration or device rather than being a template.

existing sensor values cannot be modified using jinja. however, what you CAN do is rename the entity ID and name, then create a new entity (with the original name and ID of the hidden entity) using the template sensor helper.

do not forget to set its measurement unit, state class and entity class to what the original sensor. you can even assign it to the device of the original sensor.

Then you can hide the original sensor.

Which integration did you use to add this device?

Thats ZY-M100 24GV2 sensor connected via Z2M

How to do that?
Please enlighten me what to do

I have created a Helper to average temperature and humidity from several sensors, it is not difficult because it is already listed and just insert the sensor.
But for this one I dont understand how.

Thats ZY-M100 24GV2 sensor connected via Z2M

Based on your distance sensor, you are really, really close to nailing it :rofl:

1 Like

First thing I would do is check the Z2M GitHub for existing issues for this device. If there aren’t any, then raise one yourself.

This should be a pretty easy fix on Z2M, so you wouldn’t need to wait too long until it’s merged in. That way, everyone who has this sensor won’t have to mess around with templates in the future thanks to you.

1 Like

@bjk8kds ok, had a look in github and while no one directly reported this issue with your model, there were a couple of similar issues with presence and move sensitivity.

This issue created the original converter and the person who submitted it admitted that the distance sensor values aren’t right. Maybe post there and ask if he’s seeing the same thing and if the below change could fix it? (see edit)

I suspect the issue is coming from the tuya.valueConverter.divideBy10 mapping in Z2M code itself for datapoint 9 (distance):

		multiEndpoint: true,
		tuyaDatapoints: [
			[104, 'presence', tuya.valueConverter.trueFalse1],
			[2, 'radar_sensitivity', tuya.valueConverter.raw],
			[102, 'presence_sensitivity', tuya.valueConverter.raw],

			[3, 'detection_distance_min', tuya.valueConverter.divideBy100],
			[4, 'detection_distance_max', tuya.valueConverter.divideBy100],

			[9, 'distance', tuya.valueConverter.divideBy10],


			[105, 'keep_time', tuya.valueConverter.raw],
			[103, 'illuminance_lux', tuya.valueConverter.raw],
			[1, 'state', tuya.valueConverterBasic.lookup({
				'none': 0,
				'presence': 1,
				'move': 2
			})],

		],
    },

If this is changed to tuya.valueConverter.raw, then the distance values should be reported correctly. (see edit)
Before you raise an issue though, can you confirm that inside Z2M itself the distance is also being reported as 0.12 instead of 1.2?

EDIT: had a look at what is actually being used in Z2M currently and I believe I found the issue. It’s using tuya.valueConverter.divideBy100 instead of tuya.valueConverter.divideBy10. That would explain the decimal being off by 1 place and is probably a typo from when the device was first integrated.
Raise a bug against this - should be a pretty easy fix.

1 Like

Thank you for your assistance…
Actually yesterday I raised an issue about this device sensitive slider not working (back to 0 after a few minutes)
I would raise an issue again, thanks.

1 Like