Skip to content

Commit

Permalink
Change HA script power to energy and UV index to float
Browse files Browse the repository at this point in the history
Closes #2909
  • Loading branch information
zuckschwerdt committed Apr 26, 2024
1 parent 8c7f214 commit 1296bf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions examples/rtl_433_mqtt_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@
"device_type": "sensor",
"object_suffix": "kwh",
"config": {
"device_class": "power",
"device_class": "energy",
"name": "Energy",
"unit_of_measurement": "kWh",
"value_template": "{{ value|float }}",
Expand All @@ -587,7 +587,7 @@
"device_type": "sensor",
"object_suffix": "V",
"config": {
"device_class": "power",
"device_class": "voltage",
"name": "Voltage",
"unit_of_measurement": "V",
"value_template": "{{ value|float }}",
Expand Down Expand Up @@ -624,7 +624,7 @@
"config": {
"name": "UV Index",
"unit_of_measurement": "UV Index",
"value_template": "{{ value|int }}",
"value_template": "{{ value|float|round(1) }}",
"state_class": "measurement"
}
},
Expand All @@ -634,7 +634,7 @@
"config": {
"name": "UV Index",
"unit_of_measurement": "UV Index",
"value_template": "{{ value|int }}",
"value_template": "{{ value|float|round(1) }}",
"state_class": "measurement"
}
},
Expand Down
23 changes: 21 additions & 2 deletions src/devices/cotech_36_7959.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ Data format:
TYPE:h ID:8h FLAGS:h WIND:8d GUST:8d DIR:8d ?:h RAIN:12d FLAGS:h TEMP:12d HUM:8d LIGHT:16d UV:8d CRC:8h
Field descriptions and error conditions:
|Instrument | Valid Range | Units | Errors | Errors Decimal | Bit Size | Formula
|-------------------|---------------|----------|-----------------------------------|----------------|----------|-----------
|Temperature | -40 to 140.0F | F | 0x7fa - invalid data | 2042 | 12 | (T-400)/10
| | | | 0x7fc - below minimum | 2044 | |
| | | | 0x7fd - above maximum | 2045 | |
|Humidity | 10-99 | %rH | 0x7a - invalid if temperature bad | 122 | 8 |
|Average Wind Speed | 0.0-50.0 | m/s | >500 (?) | | 9 | AWS/10
|Wind Gust | 0.0-5.0 | m/s | >500 (?) | | 9 | WG/10
|Wind Direction | 0-359 | degrees | | | 9 |
|Light | 0-128K | lux | 0x1fffa - invalid value | 131066 | 17 |
| | | | 0x1fffb - no light | 131067 | |
| | | | 0x1fffd - above maximum | 131069 | |
|UV Index | 0-20.0 | UV units | 0xfa - invalid data | 250 | 8 | UV/10
| | | | 0xfb - No UV | 251 | |
| | | | 0xfd - Above Maximum | 253 | |
|Rain | 0-6553.5 | mm | Rolls over at top? | | 16 | Rain/10
*/

static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
Expand Down Expand Up @@ -106,14 +125,14 @@ static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
//int flags = (b[7] & 0xf0) >> 4; // [56:4]
int temp_raw = ((b[7] & 0x0f) << 8) | (b[8]); // [60:12]
int humidity = (b[9]); // [72:8]
int light_lux = (b[10] << 8) | b[11] | ((b[7] & 0x80) << 9); // [56:1][80:16]
int light_lux = ((b[7] & 0x80) << 9) | (b[10] << 8) | b[11]; // [56:1][80:16]
int uv = (b[12]); // [96:8]
//int crc = (b[13]); // [104:8]

float temp_c = (temp_raw - 400) * 0.1f;

// On models without a light sensor, the value read for UV index is out of bounds with its top bits set
int light_is_valid = (uv <= 150); // error value seems to be 0xfb, lux would be 0xfffb
int light_is_valid = (uv <= 200); // error value e.g. 0xfb, lux would be 0xfffb

/* clang-format off */
data = data_make(
Expand Down

0 comments on commit 1296bf0

Please sign in to comment.