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

Adds calibration offsets for tilt on DJT11LM sensor #6622

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

ghoz
Copy link
Contributor

@ghoz ghoz commented Dec 4, 2023

the DJT11LM seems to be very poorly calibrated,

  • provide raw accelerometer values : raw_x, raw_y and raw_z used for calibration after calibration can be removed from the payload by adding "raw_[xyz]" to "filtered_attributes" of the devices
  • allows a simple offset based calibration. not perfect , but much better than without.

one sensor went from ~15° to a few degrees off

will update the documentation on how to calibrate,
but in a nutshell:
put the sensor on a flat surface, set the offset for x and y to the opposite of raw_x and raw_y
put the sensor on its side, do the same thing for z

@ghoz ghoz force-pushed the DJT11LM_calibration branch from c2c8690 to 9a7e67c Compare December 4, 2023 21:05
the DJT11LM seems to be very poorly calibrated,
* provide raw accelerometer values : raw_x, raw_y and raw_z used for calibration
  after calibration can be removed from the payload by adding "raw_[xyz]" to "filtered_attributes" of the devices
* allows a simple offset based calibration

went from 15° to a few degrees off
// raw accelrometer values
result.raw_x=x;
result.raw_y=y;
result.raw_z=z;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you still want to have the raw values if you have the calibrated ones?

Copy link
Contributor Author

@ghoz ghoz Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the only way I found to get the raw values for doing the actual calibration

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you already have the raw values before doing any calibration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have the raw values, but right now, they are not available to users, we use them as is to compute and expose angles.
In order to know what offset to set, we need a way for the user to get the values when the sensor is on a level surface to compensate the values
(eg sensor flat I get "raw_x":60,"raw_y":-13,"raw_z":-704, => I set in the options the offset for x to -60, y to 13
with the sensor on one side : I get "raw_x":-942,"raw_y":-11,"raw_z":225, => offset for z ~ -225 )
so to reiterate as a user in order to find the offsets I need the raw values one way or another

To do an automated calibration witout the raw values, we would have to ask the user to put the device on 2 perpendicular faces, and wait for the values to update between each change, then compute the offsets for each axis and push them in the config or somewhere else, but not sure how to approach this tbh

Copy link
Contributor Author

@ghoz ghoz Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the latest iteration, renamed the raw_x to x_axis to follow the other accelerometer sensors .
and expose the calibrated values

// simple offset calibration
x=calibrateAndPrecisionRoundOptions(x, options, 'raw_x');
y=calibrateAndPrecisionRoundOptions(y, options, 'raw_y');
z=calibrateAndPrecisionRoundOptions(z, options, 'raw_z');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to call the options x (no raw_)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at other accelerometer based sensors I see we have a set of x,y,z_axis that are exposed
using https://github.com/Koenkk/zigbee-herdsman-converters/blob/v16.0.2/src/lib/exposes.ts#L760
such as https://github.com/Koenkk/zigbee-herdsman-converters/blob/v16.0.2/src/devices/third_reality.ts#L228
Do you prefer me do rename and expose them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry you were talking about the option name
yes I can rename (the question for the raw values is still valid though)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename

Copy link
Contributor Author

@ghoz ghoz Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the option
I think It might be confusing as they are offsets for the accelerometer underlying /raw values, not the exposed angle_x y z that are computed...

@Koenkk
Copy link
Owner

Koenkk commented Dec 5, 2023

Note to self; after this merge Koenkk/zigbee2mqtt.io#2375

ghoz added 3 commits December 5, 2023 21:34
rename raw_x,y,z options to x,y,z
moved options definition to the converter
rename raw_x, raw_y, raw_z to x_axis, y_axis, z_axis
expose the *calibrated* accelerometer values
@Koenkk Koenkk merged commit 36c8c4a into Koenkk:master Dec 6, 2023
2 checks passed
@Koenkk
Copy link
Owner

Koenkk commented Dec 6, 2023

Thanks!

@ghoz ghoz deleted the DJT11LM_calibration branch December 7, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants