Integrating Youless energy monitoring devices into Telegraf

I’m playing a lot with Telegraf in recent time in order to get a handle on monitoring an Exadata or the Oracle DB with it. As I don’t have an Exadata at home my source of data for my first steps with Telegraf were my IoT devices at home.

I have Youless energy monitoring devices in my home to log the energy consumption of my home. You will find some information about them at this site(sorry, it’s in Dutch). They can count LED blinks (which works really well) and they can count the passing of the red line on Ferraris wheel based power meters (which works well when it works but doesn’t work sometimes at all. I have to four meters in my house, three of them are Ferraris based, two can be read, one not … and they look absolutely identical).

To integrate them into Telegraf is really straightforward. The nice thing about the Youless devices is that they deliver the data directly as JSON output by sending a HTTP request to them like http://aaa.bbb.xxx.yyy/a?f=j

{"cnt":" 7515,292","pwr":331,"lvl":0,"dev":"","det":"","con":"","sts":"","raw":0}

What i really hate about them, is the point that they deliver the count as a string with a leading whitespace. So i had to convert the string into a float.

So i just put the following file as youless.conf into /etc/telegraf/telegraf.d in order to read the data into my InfluxDB.

[[inputs.http]]
  urls = [
    "http://aaa.bbb.xxx.yyy/a?f=j",
    "http://aaa.bbb.xxx.yyy/a?f=j"
  ]
  data_format = "json"
  interval = "60s"
  json_string_fields = ["cnt"]
  [inputs.http.tags]
   sourcedevice = "youless"

[[processors.regex]]
  order=1
  [processors.regex.tagpass]
    sourcedevice = ["youless"]
  [[processors.regex.fields]]
    key = "cnt"
    pattern = "^\\s*([0-9]*),([0-9]*)$"
    replacement = "${1}.${2}"
    result_key = "cnt_kwh"
    drop_original = true

[[processors.converter]]
  order=2
  [processors.converter.tagpass]
    sourcedevice = ["youless"]
  [processors.converter.fields]
    float = ["cnt_kwh"]

This currently works reasonably well.