BobRak / OpenHAB-Smartthings

53 stars 54 forks source link

Adding gasMeter to OpenHAB binding #91

Closed Boeeerb closed 3 years ago

Boeeerb commented 4 years ago

Hello BobRak,

I've managed to get the binding working (although took a few goes to get it right!) with my ST hub v3 and latest OH2 to 2way control all my Zigbee stuff. The bit that caused me the issue was in the instructions for the integration part, last section "Configuration in the Smartthings Classic App" on https://github.com/BobRak/OpenHAB-Smartthings/blob/master/org.openhab.binding.smartthings/SmartthingsInstallation.md. At first this line; In the selection screen select the devices you want to interact with OpenHAB. Warning devices not enabled (lacking the check mark in the box for the specific device) will be ** ignored ** by OpenHAB. Just didn't seem to click in my mind, so just a slight clarification, such as enabling the Input handlers for example, Switch/Power Meter/Contact Sensor for each device you have. After I eventually got this it all worked... But anyway that isn't my issue...

I have my Smart Meter connected to my ST hub and I can read the Energy Meter readings no problem, as it comes up as energy, so OpenHAB reads this fine, but the binding doesn't have gasMeter, so is this something easy to add in? I don't have a java environment to contribute to the jar. Clip from Event Devices on ST dev console smartmeter

Thanks again for your hard work on putting all this together

BobRak commented 4 years ago

Hi: Unfortunately the Smartthings Capability Reference doesn't define a gasMeter. I'm not sure if I could just add it to the capabilities defined in the OpenHabAppV2 or not. I don't have time to investigate right now but I'll see what I can do in the next couple of weeks. Are you familiar with a program called curl? If so, I could update the OpenHabAppV2 and have you test it in your environment where you have a gasMeter. What platform are you running openHAB on?

Boeeerb commented 4 years ago

Thank you, that would be appreciated.

As I had the meter installed about 6 months ago, I have forgotten the linking process between the meter and ST, which I believe is via API from the energy company.

There must be an undocumented compatibility somewhere within the SmartThings environment to allow the data for this intergration to be read. It can only be read on the new app, on the ST Classic it only reports Electricity (not gas) under a "Tiles Missing" option.

I'm familiar with Curl, and it's running on a Pi 3 Openhabian image. I fully understand the need to keep it completely inline with the capability reference for the OpenHAB process still keeping fingers crossed on getting your work accepted!

BobRak commented 4 years ago

Sorry for the slow response. I've been busy updating the Smartthings binding based on feedback for the openHAB review. Quite a bit to do.

I was wondering if your gasMeter has a custom device handler. Look in My Devices and see what the TYPE is. Then look in My Devices and see if there is a matching TYPE. Maybe the device type could be changed in there.

Bob

Boeeerb commented 4 years ago

It's no problem, just greatful of the work you're doing.

In My Devices, the meter (containing both the electricity and gas readings) shows as placeholder;

image

Full details;

image

And finally the events coming from the device;

image

BobRak commented 4 years ago

Look in My Devices and see if there is a device handler named placeholder. If there is click on it. Copy the code to the clipboard and then paste it in this issue and send it to me.

Thanks,

Bob

Boeeerb commented 4 years ago

Bob,

There isn't a placeholder device in the My Devices list, just the Bulb meter;

image

There isn't anything else apart from the OH2 handler in My Smartapps and My Device Handlers

Sorry don't feel I'm being that helpful, there is quite a lack of supporting additional stuff for the Bulb meter

BobRak commented 4 years ago

I think / hope we can figure something out.

Does this Bulb Energy Meter capture both electric energy and gas usage?

Using your phone:

  1. Go to SmartApps -> click on OpenHabAppV2
  2. Scroll down to Energy Meter and click on it.
  3. What are the choices there?
  4. What have you selected?

Providing there was something you could select in step 4 above then have a look at the logs: In the graph.api.smartthings.com website, select Live Logging. Do you see any messages: "Sending '{"path":"/smartthings/state" ... capabilityAttribute:energy

If so we might be on the right track. If you see energy messages above try the following in the graph.api.smartthings.com website

  1. Click SmartApps (at the top)
  2. Click OpenHabAppV2
  3. Around line 151 you should see energyMeter.
  4. Below attributes you should see "energy". Change that to: "energy", "gasMeter"
  5. Save. Was the save successful? any error messages?
  6. Publish

Now go back to Live Logging. Any messages with: capabilityAttribute:gasMeter

Boeeerb commented 4 years ago

Bob,

Sorry for the delay, only just back on the laptop, and the gas meter can take up to 12/13 hours at time to update. A little insight... The gas meter is battery powered and sends its reading sparodically to the electricity meter to send data to the energy company, but with Zigbee enabled it also sends its data to Smartthings, electricity every minute or so, gas ... whenever.

First part, on the phone, these options have been ticked from day one;

Screenshot_20200629-201323

I've made the amendments to the code, and waited for the gas meter to kick in...

Smartthings event log on Bulb; image

Smartthings Live Log; image

OpenHAB logging; image

So it can see the data, and sent it over for OpenHAB to ignore - Which I think is good?

Thanks again, Jason

BobRak commented 4 years ago

Yes it is good that the gasMeter is now picked up and sent over to openHAB. Most importantly for me is that it confirms this is just another attribute of the energy meter.

I think it is possible to get openHAB to recognize it by making a change to one file inside of the org.openhab.binding.smartthings-2.5.5-SNAPSHOT.jar. A jar file is really just a zip file with some additional data inside of it. I use ZipGenius to look in jar files. Do you think you could extract a file \bundles\org.openhab.binding.smartthings\src\main\resources\ESH-INF\thing\thing-types.xml, edit it and then add it back? If so I could send you the instructions.

I'll think about adding it into my build. I do hate to add attributes that are not defined by smartthings but I do see the need in your case. Plus it is currently being reviewed but I think there will be more changes for me to make.

Bob

Boeeerb commented 4 years ago

Bob,

Editing won't be a problem at all, WinRAR seems to be fine with JAR's also so just let me know where to edit.

I fully understand about keeping it all 'above board' on the specification front, at present I haven't seen many smart meters with Zigbee support, but maybe mine is one of the first of its' breed ..? I'm still new to the SmartThings world with a special offer of hub and plugs (and smartmeter support) but loving the ease so far over adding WiFi devices.

Thanks, Jason

BobRak commented 4 years ago

Jason:

Find the following at about line 300

    <thing-type id="energyMeter">
        <supported-bridge-type-refs>
            <bridge-type-ref id="smartthings" />
        </supported-bridge-type-refs>
        <label>Energy Meter</label>
        <description>Read the energy consumption of an energy metering device</description>
        <channels>
            <channel id="energy" typeId="energy-channel">
                <label>Energy</label>
            </channel>
        </channels>
        <config-description-ref uri="thing-type:smartthings:thing-type-parameters" />
    </thing-type>

Replace it with

    <thing-type id="energyMeter">
        <supported-bridge-type-refs>
            <bridge-type-ref id="smartthings" />
        </supported-bridge-type-refs>
        <label>Energy Meter</label>
        <description>Read the energy consumption of an energy metering device</description>
        <channels>
            <channel id="energy" typeId="energy-channel">
                <label>Energy</label>
            </channel>
            <channel id="gasMeter" typeId="gasMeter-channel">
                <label>Gas Meter</label>
            </channel>
        </channels>
        <config-description-ref uri="thing-type:smartthings:thing-type-parameters" />
    </thing-type>

Now find the following at around line 1287:

    <channel-type id="energy-channel">
        <item-type>Number</item-type>
        <label>Energy</label>
        <category>Energy</category>
    </channel-type>

Add the following below it (NOT NOT REPLACE WHAT IS THERE)

    <channel-type id="gasMeter-channel">
        <item-type>Number</item-type>
        <label>Gas Meter</label>
        <category>Energy</category>
    </channel-type>

Restart openHAB. And, you make need to clear the caches.

Bob

BobRak commented 4 years ago

Did this work out? Can I close this issue?

Boeeerb commented 3 years ago

Hello Bob,

Sorry for the AWOL, I done the amendments, and not sure what happened but the connection between ST and OpenHAB broke, with nothing sending between them - It was at that point I left it to tackle another day, and the days turned in to weeks due to many non-OpenHAB things happening taking priority.

Anyway, come back to have another go and voila;

image

Both figures are readable throughout, although got to remember how to use Grafana now.

Thanks again, and fingers crossed on your OpenHAB approval!

Boeeerb commented 3 years ago

Although for other devices reporting as an Energy Meter (showing total energy consumption), it does show the Gas meter;

image

But easily remidied by unlinking the Gas Meter channel in the device properties