From yves911

What are we doing here

After the generic RF protocol, let me introduce my generic Wifi sensor module.
With this project you will be able to monitor your electricity and gas consumption.

My gas meter is similar to this one (there is a magnet inside that allow me to count “ticks”, 1 imp = 0,01m³)gas meter

Electric meter is similar to this one (there is a led that we will use, 1imp = 1 Wh)
electric meter

Hardware side

You don’t need any arduino or ATmega! We will use the chip of the ESP8266.

Connect things together

schema

Some notes : when you want to load the sketch connect the green wires accordingly AND IO0 to GND(for flash mode!), when sketch is loaded connect IO0 to VCC.

Software (ESP8266 side)

  1. Install this Arduino IDE for ESP8266 : https://github.com/esp8266/Arduino
  2. go here https://github.com/Yves911/PimaticClient and download : PimaticClient.ino or PimaticClient2.ino
  3. open PimaticClient.ino into the Arduino IDE for ESP8266 and adjust
    • ssid and password (ie your wifi details)
    • Pimatic_host (the server that is currently running pimatic)
    • httpPort (WARNING : here enter a port that is not used by any service on your pimatic server : ie a FREE port, for our example it will be 8888)
  4. load the sketch on your ESP8266 (remember connect all green wires)

On pimatic side

  1. run a netcat server on the pimatic server (remember 8888 was a free port)
    nc -d -l 8888 > /dd_extern/tmp/conso.log &
  2. check that you see some info coming from the ESP8266 module, you should see something like
    E,622,488,7366
  3. add those devices (and adjust depending on your specific needs)
      {
      "id": "consoelec",
      "name": "elec data",
      "class": "LogWatcher",
      "file": "/dd_extern/tmp/conso.log",
      "attributes": [
        {
          "name": "tick_elec",
          "type": "number"
        },
        {
          "name": "cons_elec_inst",
          "type": "number",
          "unit": "Wh",
          "discrete": true,
          "acronym": "inst."
        },
        {
          "name": "tick_e_time",
          "type": "number",
          "unit": "ms"
        }
      ],
      "lines": [
        {
          "match": "^E,(.*),(.*),(.*)",
          "tick_elec": "$1"
        },
        {
          "match": "^E,(.*),(.*),(.*)",
          "cons_elec_inst": "$2"
        },
        {
          "match": "^E,(.*),(.*),(.*)",
          "tick_e_time": "$3"
        }
      ]
    },
    {
      "variables": [
        {
          "name": "Compteur",
          "expression": "61400 * 1000 + $consoelec.tick_elec",
          "unit": "Wh",
          "type": "number",
          "label": "Compteur"
        },
        {
          "name": "Conso_inst",
          "expression": "$consoelec.cons_elec_inst",
          "unit": "Wh",
          "type": "number",
          "label": "inst.",
          "discrete": true,
          "acronym": "inst."
        },
        {
          "name": "Conso_jour",
          "expression": "$elec_display.Compteur - $elec_morning",
          "unit": "Wh",
          "type": "number",
          "label": "Journée",
          "acronym": "j."
        }
      ],
      "id": "elec_display",
      "name": "Électricité",
      "class": "VariablesDevice"
    },
    {
      "id": "consogaz",
      "name": "gaz data",
      "class": "LogWatcher",
      "file": "/dd_extern/tmp/conso.log",
      "attributes": [
        {
          "name": "tick_gaz",
          "type": "number"
        },
        {
          "name": "cons_gaz_inst",
          "type": "number",
          "unit": "m³",
          "discrete": true,
          "acronym": "inst."
        },
        {
          "name": "tick_g_time",
          "type": "number",
          "unit": "ms"
        }
      ],
      "lines": [
        {
          "match": "G,(.*),(.*),(.*)",
          "tick_gaz": "$1"
        },
        {
          "match": "G,(.*),(.*),(.*)",
          "cons_gaz_inst": "$2"
        },
        {
          "match": "G,(.*),(.*),(.*)",
          "tick_g_time": "$3"
        }
      ]
    },
    {
      "variables": [
        {
          "name": "Compteur",
          "expression": "17852.000 + $consogaz.tick_gaz/100",
          "unit": "m³",
          "type": "number",
          "label": "Compteur"
        },
        {
          "name": "Conso_inst",
          "expression": "$consogaz.cons_gaz_inst/100",
          "unit": "m³",
          "type": "number",
          "label": "inst.",
          "discrete": true,
          "acronym": "inst."
        },
        {
          "name": "Conso_jour",
          "expression": "$gaz_display.Compteur - $gas_morning",
          "unit": "m³",
          "type": "number",
          "label": "Journée",
          "acronym": "j."
        }
      ],
      "id": "gaz_display",
      "name": "Gaz",
      "class": "VariablesDevice"
    },

Results

You can now start pimatic and enjoy live data coming from your electric and gas meters…
pimatic conso

Few remarks

You can adapt this example to your need (for example my electric has a led that flash every watt maybe not yours).
Also i think i will change the way to transmit data to pimatic (but waiting the MQQT plugin first: http://forum.pimatic.org/topic/344/pimatic-mqtt-would-be-nice/2)