Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix variable_to_jsonpath: Param is a string, not an object #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mahiso
Copy link

@mahiso mahiso commented Nov 3, 2022

No description provided.

@kapitan-iglu
Copy link

Hi,
this helped me a lot. Just discovered same problem trying to recalculate payload (number, non-json) using expression:

2023-01-23 00:33:08,040 DEBUG: mqtt_on_message zigbee2mqtt/pir-chodba/battery b'100'
Traceback (most recent call last):
  File "/usr/bin/mqtt2influxdb", line 11, in <module>
    load_entry_point('mqtt2influxdb==1.5.2', 'console_scripts', 'mqtt2influxdb')()
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/cli.py", line 57, in main
    raise e
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/cli.py", line 45, in main
    m2i.run()
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/mqtt2influxdb.py", line 67, in run
    self._mqtt.loop_forever()
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 1779, in loop_forever
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 1181, in loop
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 1572, in loop_read
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 2310, in _packet_read
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 2936, in _packet_handle
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 3216, in _handle_publish
  File "/usr/lib/python3.7/site-packages/paho/mqtt/client.py", line 3444, in _handle_on_message
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/mqtt2influxdb.py", line 145, in _on_mqtt_message
    val = self._get_value_from_str_or_JSONPath(point['fields'][key]['value'], msg)
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/mqtt2influxdb.py", line 218, in _get_value_from_str_or_JSONPath
    json_field = variable_to_jsonpath(var)
  File "/usr/lib/python3.7/site-packages/mqtt2influxdb/expr.py", line 14, in variable_to_jsonpath
    return p.var.replace('JSON_', '$').replace('_', '.')
AttributeError: 'str' object has no attribute 'var'

Config:

# ...
  - measurement: voltage
    topic: zigbee2mqtt/+/voltage
    fields:
      value: = $.payload / 1000
    tags:
      id: $.topic[1]

With this patch mqtt message is precesed as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants