Skip to content

Commit

Permalink
added frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Nov 6, 2023
1 parent a3af5ae commit 7f6bff1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dbus-mqtt-pv/dbus-mqtt-pv.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,23 @@ def on_message(client, userdata, msg):
pv_L1_power = float(jsonpayload['pv']['L1']['power'])
pv_L1_current = float(jsonpayload['pv']['L1']['current']) if 'current' in jsonpayload['pv']['L1'] else pv_L1_power/float(config['DEFAULT']['voltage'])
pv_L1_voltage = float(jsonpayload['pv']['L1']['voltage']) if 'voltage' in jsonpayload['pv']['L1'] else float(config['DEFAULT']['voltage'])
pv_L1_frequency = float(jsonpayload['pv']['L1']['frequency']) if 'frequency' in jsonpayload['pv']['L1'] else float(config['DEFAULT']['frequency'])
pv_L1_forward = float(jsonpayload['pv']['L1']['energy_forward']) if 'energy_forward' in jsonpayload['pv']['L1'] else 0

# check if L2 and L2 -> power exists
if 'L2' in jsonpayload['pv'] and 'power' in jsonpayload['pv']['L2']:
pv_L2_power = float(jsonpayload['pv']['L2']['power'])
pv_L2_current = float(jsonpayload['pv']['L2']['current']) if 'current' in jsonpayload['pv']['L2'] else pv_L2_power/float(config['DEFAULT']['voltage'])
pv_L2_voltage = float(jsonpayload['pv']['L2']['voltage']) if 'voltage' in jsonpayload['pv']['L2'] else float(config['DEFAULT']['voltage'])
pv_L2_frequency = float(jsonpayload['pv']['L2']['frequency']) if 'frequency' in jsonpayload['pv']['L2'] else float(config['DEFAULT']['frequency'])
pv_L2_forward = float(jsonpayload['pv']['L2']['energy_forward']) if 'energy_forward' in jsonpayload['pv']['L2'] else 0

# check if L3 and L3 -> power exists
if 'L3' in jsonpayload['pv'] and 'power' in jsonpayload['pv']['L3']:
pv_L3_power = float(jsonpayload['pv']['L3']['power'])
pv_L3_current = float(jsonpayload['pv']['L3']['current']) if 'current' in jsonpayload['pv']['L3'] else pv_L3_power/float(config['DEFAULT']['voltage'])
pv_L3_voltage = float(jsonpayload['pv']['L3']['voltage']) if 'voltage' in jsonpayload['pv']['L3'] else float(config['DEFAULT']['voltage'])
pv_L3_frequency = float(jsonpayload['pv']['L3']['frequency']) if 'frequency' in jsonpayload['pv']['L3'] else float(config['DEFAULT']['frequency'])
pv_L3_forward = float(jsonpayload['pv']['L3']['energy_forward']) if 'energy_forward' in jsonpayload['pv']['L3'] else 0
else:
logging.error("Received JSON MQTT message does not include a power object in the pv object. Expected at least: {\"pv\": {\"power\": 0.0}\"}")
Expand Down

0 comments on commit 7f6bff1

Please sign in to comment.