Telegraf config for shelly3em/status

421 Views Asked by At

I am collecting power consumption data using a shelly 3EM. I don't like the MQTT approach, as this disables the cloud data feature. Thus, I want to connect to the shelly "status" endpoint using telegraph [[inputs.html]] plugin.

The json from "status" looks like this:

{
"wifi_sta":{"connected":true,"ssid":"HelloNetWorld","ip":"yip","rssi":-62},
"cloud":{"enabled":true,"connected":true},
"mqtt":{"connected":false},
"time":"18:27",
"unixtime":1685636832,
"serial":14404,
"has_update":false,
"mac":"mimic",
"cfg_changed_cnt":1,
"actions_stats":{"skipped":0},"relays":[{"ison":false,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"overpower":false,"is_valid":true,"source":"input"}],
"emeters":
[
{"power":59.25,"pf":0.58,"current":0.44,"voltage":233.62,"is_valid":true,"total":80595.1,"total_returned":215.4},
{"power":67.61,"pf":0.26,"current":1.12,"voltage":232.00,"is_valid":true,"total":213500.9,"total_returned":92953.7},
{"power":3.36,"pf":0.05,"current":0.30,"voltage":233.77,"is_valid":true,"total":113106.8,"total_returned":1469.6}
],
"total_power":130.22,"emeter_n":{"current":0.00,"ixsum":1.04,"mismatch":false,"is_valid":false},"fs_mounted":true,"v_data":1,"ct_calst":0,"update":{"status":"idle","has_update":false,"new_version":"20230510-083155/v1.13.1-gda6f9f2","old_version":"20230510-083155/v1.13.1-gda6f9f2"},"ram_total":49920,"ram_free":31204,"fs_size":233681,"fs_free":154616,"uptime":87421}

I am looking for a telegram configuration, where the emeters readings (each meters array item is one electrical phase) are persisted to InfluxDB like this (

phase1 power=double_value1,pf=double_value1,... unixtime
phase2 power=double_value2,pf=double_value2,... unixtime
phase3 power=double_value3,pf=double_value3,... unixtime

I already played around with the telegraf config for quite a while, but didn't get anywhere. Debugging the output is complicated as I am running telegraph in a Docker container on a Synology DS720+...

Thanks for any help

1

There are 1 best solutions below

0
On

I studied Telegraf's documentation quite much and I think what I want is not possible. Telegraf treats the array like data as individual measures, resulting in an individual Influx line, but all 3 lines will have the same measurement ID and the same timestamp. In the end the last line written to InfluxDB will "win" overwriting all lines with the same ID/timestamp.

To differentiate between the individual phases, I came out with the following config:

    [[inputs.http.json_v2]]
      timestamp_path = "unixtime"
      timestamp_format = "unix"
      measurement_name = "shelly_em3_main"
      excluded_keys = ["host"]
      [[inputs.http.json_v2.field]]
        path = "emeters.0.power"
        rename = "power1"
      [[inputs.http.json_v2.field]]
        path = "emeters.1.power"
        rename = "power2"
      [[inputs.http.json_v2.field]]
        path = "emeters.2.power"
        rename = "power3"
      [[inputs.http.json_v2.field]]
        path = "emeters.0.current"
        rename = "current1"
      [[inputs.http.json_v2.field]]
        path = "emeters.1.current"
        rename = "current2"
      [[inputs.http.json_v2.field]]
        path = "emeters.2.current"
        rename = "current3"
      [[inputs.http.json_v2.field]]
        path = "emeters.0.voltage"
        rename = "voltage1"
      [[inputs.http.json_v2.field]]
        path = "emeters.1.voltage"
        rename = "voltage2"
      [[inputs.http.json_v2.field]]
        path = "emeters.2.voltage"
        rename = "voltage3

This results in ONE influx-line like this:

shelly_main,host=my.host,url=http://my.ip/status P2=230.66,P3=2.74,I1=0.49,I2=1.29,I3=0.25,P1=68.6 1685799394000000000

This is not as elegant I wanted it, but fulfills my needs.