Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[smappee] Smappee Binding initial contribution #2815

Closed
wants to merge 40 commits into from

Conversation

nikotanghe
Copy link

@nikotanghe nikotanghe commented Oct 30, 2017

Signed-off-by: Niko Tanghe ntanghe@gmail.com

Introduction

The Smappee energy monitor monitors how much power your appliances consume and how much you gain from your solar power system in realtime. It can automatically detect the appliances based on their energy consumption pattern. Smappee also offers a water and a gas sensor consumption monitor.

Both the Energy monitor and the Solar energy monitor can be used. These can be bought online in the [smappee webshop] (http://www.smappee.com/be_en/eshop/monitors.html).

The smappee supports clamps for 3 phase and 1 phase systems and there is a separate circuit clamp for your solar system. Installation manuals can be found on their support page

Supported Things

This binding provides one bridge thing type : 'smappee'. There should be only one smappee device installed in your home.
This thing act like a bridge and represents your smappee monitor device and should be configured first. Once configured, this will autodetect all other smappee things.

Detected things:

  • appliance: A detected appliance. The appliances that are not categorized yet (type is "Find Me") are skipped.
  • actuator: A paired smappee switch.
  • sensor: A paired water or gas sensor.

Discovery

The smappee thing must be configured manually. Appliances, actuators and the sensors are autodetected.

Smappee thing configuration

As described on their [support page] (https://support.smappee.com/hc/en-us/articles/202153935-Where-can-I-find-the-API-documentation-), you need to email [support@smappee.com] (mailto:support@smappee.com) to get a client ID and a client secret to access the API. In that mail you need to provide them:

  • Full name: your full name
  • Monitor serial number: this can be found at the back of your smappee
  • Account username: the username you use to log in in Smappee, same as thing setting 'Username'

Following settings must be configured in order to make your smappee binding work:

Smappee Bridge

Setting
ClientId The Smappee Api Oauth client id (obtain by mail from smappee support)
ClientSecret The Smappee Api Oauth client secret (obtain by mail from smappee support)
Username The username for your Smappee Account
Password The password for your Smappee Account
ServiceLocationName The name of your Smappee installation
PollingInterval How often (in minutes) does the smappee needs to be checked ?

Appliance Thing

Setting
Id The unique identifier of the detected appliance, This is the number after "Find Me" for unlabeled appliances
Type This is the smappee category ("Air Conditioner", "Blinds", "Microwave", ...

Actuator Thing

Setting
Id The unique identifier of the linked plug, This is a unique number starting from 1 for each installed plug

Sensor Thing

Setting
Id The unique identifier of the sensor, is a combined identifier. Format: [SensorId-ChannelId], eg 1-1

Channels

The following channels are supported:

Smappee Bridge

Channel Type ID Item Type Description
monitor-consumption Number The amount of energy that is being consumed now
monitor-solar Number The amount of energy that is being generated by your solar power panels now
monitor-alwayson Number The amount of energy that is always consumed

Appliance Thing

Channel Type ID Item Type Description
appliance-power Number The amount of energy that is being consumed now
Note: sometimes the API doesn't return any reading,
This can be validated in the appliance settings, show events

Actuator Thing

Channel Type ID Item Type Description
actuator-switch Switch Turn on the switch

Sensor Thing

Channel Type ID Item Type Description
sensor-value String The measured value of this sensor

Full Example

A manual setup through a things/smappee.things file could look like this:

Bridge smappee:monitor:mySmappee "Smappee" @ "Living Room" [clientId="xxx", clientSecret="xxx", username="xxx", password="xxx", serviceLocationName="xxx", pollingInterval=5]
{
    Thing smappee:appliance:myAppliance [ id="xxx", type="Blinds" ]
    Thing smappee:actuator:myPlug [ id="xxx" ]
    Thing smappee:sensor:mySensor [ id="xxx" ]
}

A manual configuration through a demo.items file could look like this:

Number mySmappee_Consumption     "Consumption [%s]"      { channel="smappee:monitor:mySmappee:monitor-consumption" }
Number mySmappee_Solar           "Solar [%s]"            { channel="smappee:monitor:mySmappee:monitor-solar" } 
Number mySmappee_AlwaysOn        "Always On [%s]"        { channel="smappee:monitor:mySmappee:monitor-alwayson" }

Number mySmappee_AppliancePower  "Appliance Power [%s]"  { channel="smappee:appliance:myAppliance:appliance-power" }

The sitemap could look like this:

sitemap home label="My home" {
    Frame label="Energy" {
        Text item=mySmappee_Consumption label="Consumption [%s]" icon="energy"
        Text item=mySmappee_Solar label="Solar [%s]" icon="sun"
        Text item=mySmappee_AlwaysOn label="Always On [%s]" icon="energy"
    }
}

Testing

Questions ? Remarks ?
Leave a message on the forum topic https://community.openhab.org/t/smappee-binding/35670

clinique and others added 7 commits October 26, 2017 13:50
Corrected Attenuation Factor calculation in this case.
Removed initial started delay


Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
… into Smappee

Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/some-new-bindings-to-offer-azure-iot-hub-seneye-monitor-smappee-monitor/35577/7

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/smappee-binding/35670/2

@nikotanghe nikotanghe changed the title Smappee Added new 2.0 binding for the Smappee energy monitor Oct 30, 2017
@nikotanghe nikotanghe changed the title Added new 2.0 binding for the Smappee energy monitor [Smappee] Added new 2.0 binding for the Smappee energy monitor Oct 30, 2017
@Hilbrand
Copy link
Member

Hilbrand commented Nov 1, 2017

Just some general comment as a start to get the code approved. You might know all of the following, but just to help you further:

  • Build the project with mvn install and look in the file: target/code-analysis/report.html. This will give you a lot of feedback already.
  • Conform to the java coding standards, like method names start with a lowercase.
  • Please do add JavaDoc to public methods and classes.
  • Also, if you haven't take a look at the coding guidelines: http://docs.openhab.org/developers/development/guidelines.html

@stefferber
Copy link

Thx! Two hints for the above description

  • you mention "...your sneeze binding...". I guess it is "...your smappee binding"
  • you mention that "The binding requires no special configuration" but as it does not auto discover this binding needs multiple config files
    .../openhab2/services/smappee.cfg
    .../openhab2/things/smappee.things
    .../openhab2/item/smappee.items

and one question: Do you have sample config files you can add here?

@nikotanghe
Copy link
Author

This binding does not need to detect your smappee device in your network, since it will contact the online API to get it's readings. It is a 2.0 binding, so everything can be configured through the openhab UI.

@kaikreuzer
Copy link
Member

everything can be configured through the openhab UI

It can, but it must also be possible to configure it textually.
So please make sure to add a Full Example section as we have for all other bindings as well.

Changed thing name

Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Changed thing name




Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/smappee-binding/35670/5

Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be commited.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file removed

@@ -0,0 +1,15 @@
# binding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file if you don't add localization. It's an example template file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file removed

<label>Client Id</label>
<description>The Smappee Api Oauth client id (obtain by mail from smappee support)</description>
<advanced>false</advanced>
<required>true</required>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use required as parameter element or as tag. Here both are used, which is a bit of an overkill

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node required removed

http://www.eclipse.org/legal/epl-v10.html

-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="binding.smappee">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferable use the @component annotation on ThingHandlerFactory.Then you can remove this file and add a .gitignore to this map (OSGI-INF) with content: *.xml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@component used and removed xml config file


### Configuration in PaperUi

Following settings must be configured in order to make your seneye binding work :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smappee instead of seneye

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

consumption.solar = consumption.solar * 12;
}

logger.debug("smappee'{}' read", new Object[] { this.serviceLocationId });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do new Object, just pass the value directly as argument.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}

public boolean isInitialized() {
return isInitialized;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean variable should be called initialized the action(method) is called isInitialized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


String accessTokenToInclude = GetAccessToken();
if (accessTokenToInclude.isEmpty()) {
logger.error("Could not get access token");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this error log a bug or a problem with the external service? If it's not a bug it should not log to error. Same question for the other log to errors in this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored code and logged errors like this :

warn -> external service fails (there is something wrong getting an access/refresh token)
error -> bug while parsing the response from smappee api

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the review :-)


this.gson = new Gson();

this.isInitialized = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is false so no initialization to false is not needed.


logger.debug("Initialize Network handler.");
smappeeService = new SmappeeService(param_client_id, param_client_secret, param_username, param_password,
param_serviceLocationName, polltime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both polltime and refreshInterval used for what seems to be the same thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed RefreshInterval to pollTime (it's the same)

@martinvw martinvw added the new binding If someone has started to work on a binding. For a new binding PR. label Nov 10, 2017
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
@Hilbrand
Copy link
Member

You need to (re)add the map OSGI-INF with the file .gitignore with content in that file: *.xml. This will both fix the compile error as well as make the generated OSGI-INF to be ignored (they are generated in that directory if you open the project in eclipse, but should not be committed to git).
Also run mvn install to get the code report (target/code-analysis/report.html) that will give some more hints on code issues.

Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
Signed-off-by: Niko Tanghe <ntanghe@gmail.com>
@Hilbrand
Copy link
Member

Hilbrand commented Dec 4, 2017

It looks like you added your other binding for seneye in the last commit (openhab/openhab2-addons@690b8e3) to this pull request. I guess that was not intended?

Also when you merge the master into your branch you need to do a pull --rebase that way all your changes in your branch will be added on top of the master instead of between the master. When doing a rebase you then need to do a push --force (or probably use push --force-with-lease) Otherwise the branch on github will do a merge commit on github itself. With the force option it will override the branch on github with your newly rebased branch. As you have nothing committed (or pushed) you could reset the 3 last merge commits, do the rebase and then a push force to fix this. One note. These are dangerous commands as they rewrite the branch so be careful and/or read about what these commands do if you are unsure about it.

@Hilbrand
Copy link
Member

Ok that went wrong 🤕 but it's reverted now. I wanted to push to my fork, but ended up force pushing to this pull request...

I did make some changes to this code. I've moved to the new build system and also replaced authentication with OAuth2 that is part of openHAB. There is still be some work to do, and I haven't tested anything as I don't have any of these devices. So if someone is willing to pick this up that person can start with my branch. https://github.com/Hilbrand/openhab-addons/tree/smappee I'll leave it there, but have not time to continue working on it. But i think it might be a good starting point.

@Hilbrand
Copy link
Member

Closing this pr for now due to long time not activity. I still have a branch with the improvements (e.g. new build system/OAuth2 support) that I will also keep in case someone wants to continue work on this binding.

@Hilbrand Hilbrand closed this Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted new binding If someone has started to work on a binding. For a new binding PR. stale As soon as a PR is marked stale, it can be removed 6 months later.
Projects
None yet
Development

Successfully merging this pull request may close these issues.