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
hlw8012: fix constants for BL0937 #1973
Conversation
c77f306
to
8832d71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cant help but think there is a reason for the / 1000000.0f
in the final calculations. Perhaps precision is lost if the multiplier is a smaller number/more decimals before multiplying the cf_hz
/cf1_hz
?
(If I am spitting out garbage, just let me know.)
The only other comment I have is probably, use the existing CONF_MODEL
. You don't need to make a new one and call everything ...SensorModel
when Model
will do fine.
@jesserockz That depends a bit on the scale of those values, but iirc those constants were just there for easier code (because iirc the datasheet uses those units). If anything, I think it should be more accurate now, because IEEE754 floats have higher precision closer to 0. |
The BL0937 sensor has different constants factors for converting pulses. Add a configuration to handle constants on per sensor model basis. While at it, avoid computing the same factor on every update and move to setup logic to do it only once.
Fixed name of config option to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 2 suggestions below to use the cv.enum
helper
With the current implementation it is impossible to calibrate all measurements at the same time for the BL0937 sensor as it has different constants factors for converting pulses.
If you set
voltage_divider
andcurrent_resistor
to correctly calibrate voltage and current, you get a reading for power that is completely off.Add a configuration option
sensor_model
to handle constants on per sensor model basis.While at it, avoid computing the same factor on every update and move to setup logic to do it only once.
Types of changes
Related issue or feature (if applicable): fixes BL0937 sensor readings
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#1282
Test Environment
Example entry for
config.yaml
:Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: