Browse Source

## 2022-11-16
- fix cost calculation when ``cost_from_conv: False`` is configured

FloKra 1 year ago
parent
commit
8eb7d5cdc4
2 changed files with 16 additions and 10 deletions
  1. 3 0
      S0Meters_py/CHANGELOG.md
  2. 13 10
      S0Meters_py/s0meters.py

+ 3 - 0
S0Meters_py/CHANGELOG.md

@@ -1,3 +1,6 @@
+## 2022-11-16
+ - fix cost calculation when ``cost_from_conv: False`` is configured
+
 ## 2022-11-16
  - added unit conversion so that on a gas meter (which measures m³) the usage can directly be displayed in kWh (only for MQTT output)
  - added basic cost today/yesterday calculation (only for MQTT output)

+ 13 - 10
S0Meters_py/s0meters.py

@@ -512,20 +512,20 @@ def processMeterData(data):
             
             if energy_today_total is not None:
                 cJson['Today__' + unit] = round(energy_today_total, digits)
-                
                 if MQTTenabled: 
                     mqttc.publish(statTopic + "/today__" + unit, str(round(energy_today_total, digits)), qos=0, retain=False)
                     if conv_unit and conv_factor is not None:
                         conv_value = energy_today_total * conv_factor
                         mqttc.publish(statTopic + "/today__" + conv_unit, str(round(conv_value, conv_digits)), qos=0, retain=False)
                         cJson['Today__' + conv_unit] = round(conv_value, conv_digits)
-                        if cost_unit and cost_per_unit is not None:
-                            if cost_from_conv:
-                                cost_value = round(conv_value * cost_per_unit, 2)
-                            else:
-                                cost_value = round(energy_today_total * cost_per_unit, 2)                                
+                        if cost_unit and cost_per_unit is not None and cost_from_conv:
+                            cost_value = round(conv_value * cost_per_unit, 2)
                             mqttc.publish(statTopic + "/cost_today__" + cost_unit, str(cost_value), qos=0, retain=False)
                             cJson['cost_today__' + cost_unit] = round(cost_value, 2)
+                    elif not cost_from_conv:
+                        cost_value = round(energy_today_total * cost_per_unit, 2)                                
+                        mqttc.publish(statTopic + "/cost_today__" + cost_unit, str(cost_value), qos=0, retain=False)
+                        cJson['cost_today__' + cost_unit] = round(cost_value, 2)
                 
             if energy_yesterday_total is not None:
                 cJson['Yesterday__' + unit] = round(energy_yesterday_total, digits)
@@ -538,10 +538,13 @@ def processMeterData(data):
                         if cost_unit and cost_per_unit is not None:
                             if cost_from_conv:
                                 cost_value = round(conv_value * cost_per_unit, 2)
-                            else:
-                                cost_value = round(energy_yesterday_total * cost_per_unit, 2)                                
-                            mqttc.publish(statTopic + "/cost_yesterday__" + cost_unit, str(cost_value), qos=0, retain=False)
-                            cJson['cost_yesterday__' + cost_unit] = round(cost_value, 2)
+                                mqttc.publish(statTopic + "/cost_yesterday__" + cost_unit, str(cost_value), qos=0, retain=False)
+                                cJson['cost_yesterday__' + cost_unit] = round(cost_value, 2)
+                    elif not cost_from_conv:
+                        cost_value = round(energy_yesterday_total * cost_per_unit, 2)                                
+                        mqttc.publish(statTopic + "/cost_yesterday__" + cost_unit, str(cost_value), qos=0, retain=False)
+                        cJson['cost_yesterday__' + cost_unit] = round(cost_value, 2)
+                        
         # END file log 
         
         if verbose: