From 1296bf02ae2e2073f9a415a2e7372e65a142e6d8 Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Fri, 26 Apr 2024 14:47:50 +0200 Subject: [PATCH] Change HA script power to energy and UV index to float Closes #2909 --- examples/rtl_433_mqtt_hass.py | 8 ++++---- src/devices/cotech_36_7959.c | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/examples/rtl_433_mqtt_hass.py b/examples/rtl_433_mqtt_hass.py index 0d6c34c48..f6f251ee6 100755 --- a/examples/rtl_433_mqtt_hass.py +++ b/examples/rtl_433_mqtt_hass.py @@ -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 }}", @@ -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 }}", @@ -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" } }, @@ -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" } }, diff --git a/src/devices/cotech_36_7959.c b/src/devices/cotech_36_7959.c index 41c61ac1a..b5dd2164a 100644 --- a/src/devices/cotech_36_7959.c +++ b/src/devices/cotech_36_7959.c @@ -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) @@ -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(