How to integrate “P1 Monitor” into Openhab

I use software “P1 monitor” on a PI Zero to read my Smart meter (Power and Gas consumption numbers)

I’m trying to integrate the values from “P1 Monitor” into Openhab 3.

The Software has some soort of API

When I access the URL below I get the following values

URL

http://1xx.xxx.xxx.2xx/api/v1/smartmeter?limit=1&json=object&round=on

Values

[{"CONSUMPTION_GAS_M3": 1232.0, "CONSUMPTION_KWH_HIGH": 3119.0, "CONSUMPTION_KWH_LOW": 3038.0, "CONSUMPTION_W": 325, "PRODUCTION_KWH_HIGH": 0.0, "PRODUCTION_KWH_LOW": 0.0, "PRODUCTION_W": 0, "RECORD_IS_PROCESSED": 0, "TARIFCODE": "D", "TIMESTAMP_UTC": 1626028279, "TIMESTAMP_lOCAL": "2021-07-11 20:31:19"}]

Below is a solution for home assistant (HA). I don’t know much about HA and I’m using Openhab 3 on a Rasspbarri pi.

 - platform: rest
    resource: http://ip.adress.p1.mon/api/v1/smartmeter?limit=1&json=object&round=on
    name: Current Consumption
    value_template: '{{ value_json.0.CONSUMPTION_W }}'
    unit_of_measurement: "W"

So I’m looking for a translation to Openhab 3 or a native solution for Openhab
And want to create a widget for Main UI similar to the native UI of “P1 Monitor” UI

Example “P1 Monitor” UI

Use the HTTP binding (see HTTP - Bindings | openHAB).

Create a Channel for each value you want to use.

Use the JSONPATH transformation to extract the value for each Channel. The whole thing is a JSON array so you’ll need to account for that in the JSONPATH. For example:

$[0].CONSUMPTION_GAS_M3

or something like that.

1 Like

Thanks Rich,

That’s just the stepping stone I needed.

If you figured it out I bet many on the forum would love to see the example. :wink:

Sorry for the late response, life was busy!

I will create (hopefully) a shot tutorial what I have done.

The P1 Monitor software now has an MQTT client built in so the method below is no longer necessary for me, but maybe someone can still use the techniques that are used

Supplies

  • Raspberry Pi Zero W and power cable (+case)
  • microUSB OTG kabel
  • P1 to usb cable
  • Micro SD card

hard and software (except Openhab :wink:) is for the Dutch Smart power meters with a P1 port. The techniques described can of course be used for many more things

Software: P1Monitor (https://www.ztatz.nl/)

Install P1Monitor as described on the website

In P1Monitor go to settings (wrench icon) > API

There you will find various URLs to the data from P1Monitor.

Example URL: http://IP_ADRES/api/v1/smartmeter

If you open this URL you will see a lot of data (too much).

Add, the following to the end of the URL ?limit=1&json=object&round=on

then it becomes http://IP_ADRES/api/v1/smartmeter?limit=1&json=object&round=on

If you open this URL you get a short JSON string as result:

[{"CONSUMPTION_GAS_M3": 1246, "CONSUMPTION_KWH_HIGH": 3304, "CONSUMPTION_KWH_LOW": 3187, "CONSUMPTION_W": 371, "PRODUCTION_KWH_HIGH": 0, "PRODUCTION_KWH_LOW": 0, "PRODUCTION_W": 0, "RECORD_IS_PROCESSED": 0, "TARIFCODE": "P", "TIMESTAMP_UTC": 1630327113, "TIMESTAMP_lOCAL": "2021-08-30 14:38:33"}]

See the names like CONSUMPTION_GAS_M3 and PRODUCTION_KWH_LOW in the JSON string. This names we goanna use later.

Openhab (3.x)

Install http binding

Install JSONPath Transformation ( you can find under Settings > transformations )

Things

Make a new http thing (New HTTP URL Thing)

Give the thing a name and a label for example :
Unique ID: p1monitor
Label: P1Monitor

Enter this URL as Base URL in the HTTP thing you are creating.

like the example http://p1monitor/api/v1/smartmeter?limit=1&json=object&round=on

Don’t forget to Save the Thing.

Channels

within your newly created Thing go to channels and create a new channel

Channel Identifier: power_consumption_watt

Label: Power consumption in Watt

Channel type: String Channel

Leave “State Transformation” blank, we filter the correct value at item level

repeat this for all the value in the JSON string you want to use (So create a channel for each value)

for example CONSUMPTION_GAS_M3 or CONSUMPTION_KWH_LOW

Items

Go to the channel and create a new item by pressing on de link “Add Link to Item…

Create a new item

Give it a name, label type, ect….

Under profile choose the option “JSONPATH

Profile Configuration” now appears as option on the bottom of the screen

JSONPath Expression: enter $[0]. plus the value you want to filter out of the string

in this example: $[0].CONSUMPTION_W

click Link button

Now you have created an item that you can display in your preferred UI