Skip to content

How to select field with reserved characters? #32

@halmartin

Description

@halmartin

Hello, thank you for this useful project, I have been using it for many years to read sensor data from Tasmota and Espurna sensors.

I have the following problem: I have a tasmota device which sends a sensor reading with a field that contains the reserved character .:

2023-12-02 13:20:52,756 DEBUG: mqtt_on_message tele/tasmota/tasmota_16268C/SENSOR b'{"Time":"2023-12-02T14:20:52","VINDRIKTNING":{"PM2.5":5}}'
2023-12-02 13:20:52,757 WARNING: different number of fields
2023-12-02 13:20:52,758 WARNING: empty fields

I am interested in transporting the value of field PM2.5 to influxdb, my config.yaml is the following:

  - measurement: pmtwodotfive
    topic: tele/tasmota/+/SENSOR
    fields:
      value: $.payload.VINDRIKTNING.'PM2.5'
    tags:           
      id: $.topic[2]

How should I properly declare the path of .payload.VINDRIKTNING.PM2.5? The above configuration is not working for me.

If I am understanding the documentation of jsonpath-ng correctly, single or double quotes should be sufficient to select a field with special characters:

Syntax Meaning
fieldname the field fieldname (from the “current” object)
"fieldname" same as above, for allowing special characters in the fieldname
'fieldname' ditto

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions