Przeglądaj źródła

## 2023-09-09
- add readingType option in meters config YAML - used as topic name in MQTT output if defined, otherwise subtopic name = "reading"

FloKra 1 rok temu
rodzic
commit
2408eff3f7

+ 3 - 0
S0Meters_py/CHANGELOG.md

@@ -1,5 +1,8 @@
 # CHANGELOG s0meters.py
 
+## 2023-09-09
+ - add readingType option in meters config YAML - used as topic name in MQTT output if defined, otherwise subtopic name = "reading"
+
 ## 2023-01-03
  - fix issue in lastyearlastweek calculation - used code not working on Python < 3.9 (3.7.3 is the "current" version on Raspberry Pi OS Buster)
 

+ 3 - 0
S0Meters_py/README.md

@@ -133,6 +133,7 @@ In this YAML styled config file, all meters/counters are declared. The main iden
   impPerUnit: 1000
   unit: "kWh"
   digits: 3
+  readingType: "Energy_Total__kWh"
   momType: "power"
   momUnit: "W"
   momDigits: 0
@@ -159,6 +160,7 @@ In this YAML styled config file, all meters/counters are declared. The main iden
   impPerUnit: 100
   unit: "m3"
   digits: 2
+  #readingType: ""
   type: "usage"
   conv_unit: "kWh"
   conv_factor: 10.73184
@@ -198,6 +200,7 @@ In this YAML styled config file, all meters/counters are declared. The main iden
 - **impPerUnit**: integer, normally 10, 100 or 1000, used for calculation of momentary units
 - **unit**: free text, but only ``A-Z a-z _ and -`` should be used. Used for MQTT topics ``Yesterday__unit`` and ``Today__unit``
 - **digits**: integer, number of digits in output of counter reading
+- **readingType**: text string - used as topic name in MQTT output if defined, otherwise subtopic name = "reading"
 - **type**: "usage" - not really used for anything right now
 - **conv_unit**: unit for converted value, used for Today and Yesterday readings (currently not for Total)
 - **conv_factor**: factor for conversion to a different unit

+ 5 - 1
S0Meters_py/s0meters.py

@@ -177,6 +177,7 @@ def processMeterData(data):
         
         momUnit = meters_yaml[cNum].get('momUnit', None)
         momType = meters_yaml[cNum].get('momType', None)
+        readingType = meters_yaml[cNum].get('readingType', None)
         
         momUnit_conv1 = meters_yaml[cNum].get('momUnit_conv1', None)
         momType_conv1 = meters_yaml[cNum].get('momType_conv1', None)
@@ -380,7 +381,10 @@ def processMeterData(data):
         # publish current reading to MQTT
         if statTopic:
             if MQTTenabled and cReading_formatted is not None:
-                mqttc.publish(statTopic + "/reading", str(cReading_formatted), qos=0, retain=False)
+                if readingType is not None:
+                    mqttc.publish(statTopic + "/" + readingType, str(cReading_formatted), qos=0, retain=False)
+                else:
+                    mqttc.publish(statTopic + "/reading", str(cReading_formatted), qos=0, retain=False)
         
         
         data_energy[cNum][meters_yaml[cNum].get('influxFieldName_energy', 'energyTotal')] = round(float(cReading), digits)

+ 4 - 0
S0Meters_py/s0meters.yml

@@ -3,6 +3,8 @@
   impPerUnit: 1000
   unit: "kWh"
   digits: 3
+  # readingType is used as topic name in MQTT output if defined, otherwise subtopic name = "reading"
+  readingType: "Energy_Total__kWh"
   momType: "power"
   momUnit: "W"
   momDigits: 0
@@ -30,6 +32,8 @@
   impPerUnit: 100
   unit: "m3"
   digits: 2
+  # readingType is used as topic name in MQTT output if defined, otherwise subtopic name = "reading"
+  #readingType: "Gas_Total__m3"
   type: "usage"
   conv_unit: "kWh"
   conv_factor: 10.73184