From 6aec99371d66bee67be5580803141d09e04151da Mon Sep 17 00:00:00 2001 From: vg8020 <40881962+vg8020@users.noreply.github.com> Date: Fri, 6 Jul 2018 09:38:04 +0200 Subject: [PATCH] Add support for Nexus Temperature sensor Please, edit as needed. pi@raspberrypi:~ $ sudo PYTHONPATH=/usr/share/weewx python /usr/share/weewx/user/sdr.py parsed: {'temperature.1:55.NexusTemperaturePacket': 26.7, 'battery.1:55.NexusTemperaturePacket': 0, 'usUnits': 16, 'dateTime': 1530316225} parsed: {'temperature.1:173.NexusTemperaturePacket': 27.2, 'battery.1:173.NexusTemperaturePacket': 1, 'usUnits': 16, 'dateTime': 1530316234} Nexus sensor protocol from rtl_433 https://github.com/merbanan/rtl_433/blob/master/src/devices/nexus.c --- bin/user/sdr.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/bin/user/sdr.py b/bin/user/sdr.py index ab5b103..4fb49d1 100755 --- a/bin/user/sdr.py +++ b/bin/user/sdr.py @@ -1518,6 +1518,39 @@ def parse_json(obj): pkt = Packet.add_identifiers(pkt, sensor_id, ProloguePacket.__name__) return pkt +class NexusTemperaturePacket(Packet): + # 2018-06-30 01:12:12 : Nexus Temperature + # House Code: 55 + # Battery: OK + # Channel: 1 + # Temperature: 27.10 C + + IDENTIFIER = "Nexus Temperature" + PARSEINFO = { + 'House Code': ['house_code', None, lambda x: int(x)], + 'Battery': ['battery', None, lambda x: 0 if x == 'OK' else 1], + 'Channel': ['channel', None, lambda x: int(x)], + 'Temperature': + ['temperature', re.compile('([\d.-]+) C'), lambda x : float(x)]} + + @staticmethod + def parse_text(ts, payload, lines): + pkt = dict() + pkt['dateTime'] = ts + pkt['usUnits'] = weewx.METRIC + pkt.update(Packet.parse_lines(lines, NexusTemperaturePacket.PARSEINFO)) + return OS.insert_ids(pkt, NexusTemperaturePacket.__name__) + + @staticmethod + def parse_json(obj): + pkt = dict() + pkt['dateTime'] = Packet.parse_time(obj.get('time')) + pkt['usUnits'] = weewx.METRIC + pkt['house_code'] = obj.get('id') + pkt['battery'] = 0 if obj.get('battery') == 'OK' else 1 + pkt['channel'] = obj.get('channel') + pkt['temperature'] = Packet.get_float(obj, 'temperature_C') + return OS.insert_ids(pkt, NexusTemperaturePacket.__name__) class PacketFactory(object): @@ -1552,7 +1585,8 @@ class PacketFactory(object): OSWGR800Packet, OSTHN802Packet, OSBTHGN129Packet, - ProloguePacket] + ProloguePacket, + NexusTemperaturePacket] @staticmethod def create(lines):