Bluetooth-Devices / bthome-ble

Parser for BTHome BLE devices
https://bthome.io/
MIT License
79 stars 16 forks source link

Add Generic Datatypes #134

Closed the78mole closed 3 months ago

the78mole commented 4 months ago

Is your feature request related to a problem? Please describe. Currently I'm implementing some device with a magnetic sensor. But since there is no data type for magnetic flux or something similar, I would need at least a workaround, but there is also not a generic data type for non-binary values.

Describe the solution you'd like I would like to have a set of generic data types, someone can use according to their needs. These are:

Additional context I also realized, that some datatypes are defined as uintX, like voltage, but voltage can also go negative...

stsquad commented 3 months ago

The raw sensor should be able to receive any number as a hexadecimal coded string. It doesn't say if there should be a leading "0x" in the string though.

Ernst79 commented 3 months ago

The count sensors are available in uint8, uint16 and uint32, which you can use for any (positive number). The raw sensor is a special case, where you have to specify the length of the bytestring first (in the 2nd byte). However, the raw sensor is intended to send a bytestring as is, there won't be any translation to a number in e.g. Home Assistant. But the count sensor should be ok for the unsigned inters at least.

Feel free to add a specific type if you want, by creating a PR.

the78mole commented 3 months ago

I understand, that there is a raw sensor, but this does still not address the issue, that some of the sensor values, currently defined only positive, can often go negative (voltage, power, current...). Is it intended to be solved in the future or does someone need to always work around it and introduce quite some overhead on the receiving side?

Ernst79 commented 3 months ago

We can add a count sensors that can go negative (signed int), to at least solve it with a generic sensor type. It is also possible to add some singed int sensors for specific types. But I don't think negative voltage is used very often.

the78mole commented 3 months ago

A generic signed int sensor would already serve well. You should also think about integrating a signed power sensor. Thinking about households with solar power and battery storage, a power sensor that measures positive and negative power is needed in every place (main meter, battery sensor,...) and it is totally necessary, if you want to control the power generation in a way, that you get net zero for the main net meter. Thanks for taking it into account!

Ernst79 commented 3 months ago

Added in 3.11.0