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

Initial support for GVH5074 #21

Merged
merged 6 commits into from
Jan 18, 2022
Merged

Conversation

cornking03
Copy link
Contributor

Values reported over MQTT all match expected values. Several features were added following examples from existing drivers, but not tested such as HA discovery, via_pubs, and publish attributes.

@tony-fav
Copy link
Owner

Looks good.

Have you tested with a negative temp on your device? By my research on this device, the negative is stored via 2s complement, not the same way it is stored in the GVH5075 (as you've done here just with 2 bytes rather than 3).

This code snippet demos the difference between the 2 methods

import string

def twos_complement(n, w)
  if n & (1 << (w - 1))
    n = n - (1 << w)
  end
  return n
end

def gvh5075_way(n, w)
  if n & (1 << (w - 1))
    n = (1 << (w - 1)) - n
  end
  return n
end

for x:0x7FF0..0x800F
  print(string.format('0x%X', x), gvh5075_way(x, 16), twos_complement(x, 16))
end

with output

0x7FF0 32752 32752
0x7FF1 32753 32753
0x7FF2 32754 32754
0x7FF3 32755 32755
0x7FF4 32756 32756
0x7FF5 32757 32757
0x7FF6 32758 32758
0x7FF7 32759 32759
0x7FF8 32760 32760
0x7FF9 32761 32761
0x7FFA 32762 32762
0x7FFB 32763 32763
0x7FFC 32764 32764
0x7FFD 32765 32765
0x7FFE 32766 32766
0x7FFF 32767 32767
0x8000 0 -32768
0x8001 -1 -32767
0x8002 -2 -32766
0x8003 -3 -32765
0x8004 -4 -32764
0x8005 -5 -32763
0x8006 -6 -32762
0x8007 -7 -32761
0x8008 -8 -32760
0x8009 -9 -32759
0x800A -10 -32758
0x800B -11 -32757
0x800C -12 -32756
0x800D -13 -32755
0x800E -14 -32754
0x800F -15 -32753

@cornking03
Copy link
Contributor Author

cornking03 commented Jan 17, 2022

I did throw my GVH5074 in the freezer and was receiving correct negative readings from it (I was also pleasantly surprised with the signal strength for it being inside a metal box). I am not very familiar with bitwise operations and just learned about two's complement today (thanks)! I added my method to yours above...

...

def GVH5074_initial_way(n)  
  if n <= 0x7FFF
    return n 
  end
  return (-(0xFFFF - n))
end

for x:0x7FF0..0x800F
  print(string.format('0x%X', x), gvh5075_way(x, 16), twos_complement(x, 16), GVH5074_initial_way(x))
end

Output:

0x7FF1 32753 32753 32753
0x7FF2 32754 32754 32754
0x7FF3 32755 32755 32755
0x7FF4 32756 32756 32756
0x7FF5 32757 32757 32757
0x7FF6 32758 32758 32758
0x7FF7 32759 32759 32759
0x7FF8 32760 32760 32760
0x7FF9 32761 32761 32761
0x7FFA 32762 32762 32762
0x7FFB 32763 32763 32763
0x7FFC 32764 32764 32764
0x7FFD 32765 32765 32765
0x7FFE 32766 32766 32766
0x7FFF 32767 32767 32767
0x8000 0 -32768 -32767
0x8001 -1 -32767 -32766
0x8002 -2 -32766 -32765
0x8003 -3 -32765 -32764
0x8004 -4 -32764 -32763
0x8005 -5 -32763 -32762
0x8006 -6 -32762 -32761
0x8007 -7 -32761 -32760
0x8008 -8 -32760 -32759
0x8009 -9 -32759 -32758
0x800A -10 -32758 -32757
0x800B -11 -32757 -32756
0x800C -12 -32756 -32755
0x800D -13 -32755 -32754
0x800E -14 -32754 -32753
0x800F -15 -32753 -32752

I'm not sure if I just got lucky with my method or if the math actually checks out, but I can update mine to use the two's complement.

@tony-fav
Copy link
Owner

Looks like you're super close to a twos_complement but missing the shift by 1 (see here). The function I used is basically this. However, I'm thinking berry uses Two's Complement when it extracts data with the geti method. So, we may be able to get rid of the if statement with just
changing
var temp = adv_data.get(3,2)
to
var temp = adv_data.geti(3,2)
Give it a try and let me know!

@tony-fav
Copy link
Owner

I see the commit, but I just want to confirm before I merge that the change gets you good temperature values (positive and negative).


`02` - unknown

## Temperature
Copy link
Owner

Choose a reason for hiding this comment

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

Can edit this section now if the .geti is working appropriately.

Copy link
Owner

Choose a reason for hiding this comment

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

The Two's complement is so close to what you figured out. It's subtracting the temp value from 0x10000 instead of from 0xFFFF!

@cornking03
Copy link
Contributor Author

Forgot to actually submit my comment after that commit yesterday. I did confirm that the change returns correct positive and negative values.

image

@tony-fav tony-fav merged commit 3066bc8 into tony-fav:main Jan 18, 2022
tony-fav added a commit that referenced this pull request Jan 18, 2022
* Initial 5074 testing

* Fixed decimal rounding issue

* Adding refrence material

* Now using geti for  two's complement

* Updated notes for new temperature method

* Fixed internal anchor link

Co-authored-by: cornking03 <cornking03+git@gmail.com>

Co-authored-by: cornking03 <84036755+cornking03@users.noreply.github.com>
Co-authored-by: cornking03 <cornking03+git@gmail.com>
@cornking03 cornking03 deleted the GVH5074_Support branch January 19, 2022 14:05
tony-fav added a commit that referenced this pull request Mar 1, 2022
* Start of Blerry 2
Config loading from json files

* revert default config as json
basic device setup framework

* basic handle and active scan loading from driver

* basic callback functionality
basic classes for advert interp

* working callback and advert reading

* create attribute and sensor classes

* pull in all tasmota settings v1 did
webui display trial
basic ATCpvvx support

* attributes in webui bc why not

* enable binary sensors
prep for working on discovery
"finish" ATCpvvx driver

* basic publishing

* rename config file, add initial dev driver

* fix webui, string_upper func, upper the macs

* initial sensor discovery

* protect helper functions as static methods

* add binary sensor discovery
add todo list

* add via_pubs support

* add general calibration

* add dewpoint calcs back into drivers
limit driver list to those supported

* add general precision support

* add driver for GVH5074
add spoofer, notes, config for GVH5074
add some notes to dev driver
add twos_complement helper function
do not require 'advanced' in user config
do not require 'override' in user config

* rename to drivers for V2

* rename device_notes to driver_notes

* port GVH5075 driver

* port IBSTH2 driver (need testers!)

* add version numbering

* Add support for Xiaomi_LYWSDCGQ
This could morph to a more generic Xiaomi driver

* Add ThermoPro TP59 Driver
todo: verify negative temp

* driver loading logs

* workaround for some tasmota versions

* Fix: Driver: ThermoPro_TP59: fix humidity

* first thwack at a v0.2.x README

* Support ATC/pvvx on Mi-Like with Xiaomi driver

* add "ignored" flag
tiny Inkbird change

* update readme for ignore flag

* beginning of setup script

* setup 2

* setup 3

* start some Tasmota Commands

* BlerySet/Get/DelDevice and BlerrySet/Get/DelConfig

* test auto download driver

* some log statements for dl driver

* try fix blerry setup delete itself

* try again

* try again again

* move drivers into drivers folder
update driver download location
change GVH5074 to use geti instead of an extra twos_complement function

* update gitignore

* Initial support for GVH5074 (#21) (#24)

* Initial 5074 testing

* Fixed decimal rounding issue

* Adding refrence material

* Now using geti for  two's complement

* Updated notes for new temperature method

* Fixed internal anchor link

Co-authored-by: cornking03 <cornking03+git@gmail.com>

Co-authored-by: cornking03 <84036755+cornking03@users.noreply.github.com>
Co-authored-by: cornking03 <cornking03+git@gmail.com>

* Reorganize for v0.2.x and beyond

* rename GVH5075 doc

* update URLs and cleanup

* missed 1 URL

* improve command code a bit.

* publish after 5 minutes even if no value change

* port switchbot temp and humidity

* port switchbot motion sensor (WoPresence)
fix readme to represent current devices

* port switchbot contact sensor (WoContact)
fix binary_sensor publish_available

* fix print message prefix in drivers

* Add GVH5184 driver and associated blerry.be changes (#26)

* Uncommented GVH5184

* Ported over from old dev-blerry2 branch

This is driver written by ElksInNC and refactored by Tony-fav.

* Create GVH5184.md

* Create 5184 fake packet file

* Create 4 fake packets - 2 for each sequence

* Revised documentation for 5184 driver

* Fake MAC for injection of fake p messages

* Updated p-strings with fake MAC

* Changed alias to match p-faker

* Re-arranged fake packets

* setup script check for blerry_config.json

* Update README

* Update README: Tasmota Commands

* blerry setup now enables BLE if it is not
cleanup todo

* setup script as tasmota command

* setup script can act as upgrade script

* Port GVH5182

* Update README

* Port GVH5183. All drivers now ported to v0.2.x

* calibration and precision only for numbers

* initial switchbot bot support (#29)

Switchbot Bot support (WoHand)
added concept of BlerryActions, autodiscovered to HA Buttons
Discovery Settings Fix

* Update README.md

* Updated Firmware. See NOTES.md

* SetOption8 Support

* add discovery override
enables using state_class measurement for HA statistics.

* firmware updates

* firmware fix, update, idk, it broke somehow before

* try fix setoption8 behavior on non numeric values

* autoexec.be line to load BLErry

* publish less often

* try web display less

* only change webui display every 10s

* use built in string.toupper function 🤦

* remove twos_complement function (geti does this)

* add GVH5179 support to GVH5074 driver

* Update blerry_driver_Xiaomi.be

* single purpose blerry script for RadonEye

* Add HHCCJCY01 to Xiaomi Driver

Co-authored-by: cornking03 <84036755+cornking03@users.noreply.github.com>
Co-authored-by: cornking03 <cornking03+git@gmail.com>
Co-authored-by: ElksInNC <77821967+ElksInNC@users.noreply.github.com>
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.

None yet

2 participants