jessevl / homeassistant-greenchoice Goto Github PK
View Code? Open in Web Editor NEWThis is a Home Assistant custom component that connects to the Greenchoice API
License: MIT License
This is a Home Assistant custom component that connects to the Greenchoice API
License: MIT License
The current sensor is cumulative and shows me the total gas/energy used up to that point in time. It would be nice to make the plugin generate a delta sensor, which actually shows the used resources per day.
Maybe other people would like this as well?
i was playing with this integration but it seems not to work
i get this error, do you have any idea?
Error while setting up platform greenchoice
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 55, in setup_platform
greenchoice_api.update()
File "/usr/src/homeassistant/homeassistant/util/init.py", line 240, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 180, in update
json_result = json.loads(response.getresponse().read().decode('utf-8'))
File "/usr/local/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.7/jsoError while setting up platform greenchoice
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 55, in setup_platform
greenchoice_api.update()
File "/usr/src/homeassistant/homeassistant/util/init.py", line 240, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 180, in update
json_result = json.loads(response.getresponse().read().decode('utf-8'))
File "/usr/local/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)n/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Is this add-on up to date?
I can't get mine token.
In my JSON file there is no field: "Teruglevering". How do you become these data?
I thing the parsing of the API output is not correct. For the gas meter index 1 of the output is read. However, looking at the output I get when invoking the API manually, the gasmeter readings are at index 2. I think the code should look at the Product-field to determine the correct JSON-object for the meter readouts.
I also don't seem to get any 'Delivered' measurements but since I can't find any documentation about the Greenchoice API I'm not sure what the reason for this could be.
I pasted the output I got in the hope that it would help with the development.
[
{
"MeterstandenOutput": [
{
"MinNieuweStand": 0,
"MaxNieuweStand": 0,
"Hoog": 2484,
"Laag": 2905,
"Product": 1
}
],
"DatumInvoer": "2020-12-30T00:00:00"
},
{
"MeterstandenOutput": [
{
"MinNieuweStand": 0,
"MaxNieuweStand": 0,
"Hoog": 0,
"Laag": 0,
"Product": 2
}
],
"DatumInvoer": "2020-12-30T00:00:00"
},
{
"MeterstandenOutput": [
{
"MinNieuweStand": 0,
"MaxNieuweStand": 0,
"Hoog": 2931,
"Laag": 0,
"Product": 3
}
],
"DatumInvoer": "2020-12-30T00:00:00"
}
]
The MeterstandenOutput shows all time registered, not how they are registered do far after last registration (note year).
Example: my meters are installed 2 years ago, so my meters has about 8000kW registered (all time), but I have 3000kW used since last year (from note year).
The MeterstandenOutput should be changed to the current meter stand registered from last note year.
I added all info in my sensor.yaml ( config include !sensor.yaml)
Of cource also installed the HACS Greenchoice.
I found my contract id with the curl instructions.
But now I cannot find a sensor anywhere on HA.
Running the integration the following error comes up:
No 'version' key in the manifest file for custom integration 'greenchoice'.
This will not be allowed in a future version of Home Assistant.
Please report this to the maintainer of 'greenchoice'
Is it possible to adjust the timerange? Now the JSON only outputs 1 day. Is this correct?
Hi Jesse,
I have installed this plugin. And I received a id.
Everything is ok, but how can i implement or test this?
I can't find any entitie with 'meterstand' of with 'greenchoice'.
Hi, than you for creating this Custom sensor.
I try to retreive my access token but when I enter the command in POSTman, I get the following result:
{
"error": "invalid_clientId",
"error_description": "ClientId should be sent."
}
I've tried different entries for ClientID, like my e-mail address, customer number and even just my name, everythime with the same error.
Do I need to add my ClientID between special characters due to the fact it's an e-mailaddress? Or does it have something to do with my password (there are special characters in it).
Can you please help?
Thanks!
Michael
Hi,
I have obtained the contract id, and put it together with username/password in secrets.yaml. I'm getting the following error in the log file while trying to setup this component.
2021-04-11 14:23:48 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up greenchoice platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 57, in setup_platform
greenchoice_api.update()
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 278, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 203, in update
currentEnergy = [x for x in json_result if x['MeterstandenOutput'][0]['Product'] == 1]
File "/config/custom_components/greenchoice/sensor.py", line 203, in <listcomp>
currentEnergy = [x for x in json_result if x['MeterstandenOutput'][0]['Product'] == 1]
TypeError: string indices must be integers
sensors/greenchoice.yaml
- platform: greenchoice
name: meterstanden
password: !secret greenchoicepass
username: !secret greenchoiceuser
overeenkomst_id: !secret greenchoicecontract
Any idea what I am doing wrong?
Thanks,
Vic
When I start Home Assistant the following is shown in log and the custom integration is not loaded.
Error while setting up greenchoice platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 57, in setup_platform
greenchoice_api.update()
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 277, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 190, in update
response.request("POST", "/token", body = self._tokenquery, headers = self._tokenheaders)
File "/usr/local/lib/python3.9/http/client.py", line 1279, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1325, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1274, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1034, in _send_output
self.send(msg)
File "/usr/local/lib/python3.9/http/client.py", line 974, in send
self.connect()
File "/usr/local/lib/python3.9/http/client.py", line 1448, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/usr/local/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/local/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/local/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1129)
Hi,
I'm getting the following error while retrieving the token :
{
"error": "invalid_clientId",
"error_description": "ClientId should be sent."
}
I'm using Postman.
This is what i'm using as POST :
If you want, I can add some advanced CI to your repo in a PR. Let me know if you want that.
I succesfully installed the custom component.
When looking in the debug logfiles of HA, I also see the data is retrieved from Greenchoice.
However, I can not find en entity in HA with attributes of something like that.
How exactly can I use the data retrieved bij the Greenchoice Integration?
Besides yaml configuration also make it possible to add the configuration via the Home Assistant user interface.
In that case contract(s) could also be retrieved and displayed and selected by user. Or generate sensors for all contracts so that user can hide the contracts that he doesn't need.
It would be great if this integration was available via HACS!
Hi Jesse,
The plugin is working fine, thanks for that!
Do you happen to know where to find any API documentation?
I would like to extend your plugin with the "Tarieven" (tariffs), so I can see how much Euro is "consumed" rather than kWh.
The only thing missing is the right URL.
Thanks in advance.
Best,
Ron
I've installed the component and configured it. I was able to get my access token and contract ID via Postman. However, when running the platform I'm getting the following issue:
2020-05-07 13:39:39 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up greenchoice platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 55, in setup_platform
greenchoice_api.update()
File "/usr/src/homeassistant/homeassistant/util/init.py", line 240, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/greenchoice/sensor.py", line 175, in update
self.token = json_result["access_token"]
KeyError: 'access_token'
Looks like the platform can't get the access_token programmatically from the Greencoice API service anymore
Can the sensor be adapted for use with the new Energy dashboard in Home Assistant?
See https://www.home-assistant.io/more-info/statistics/
and https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics
Just tried out the integration, but get an error during setup:
Error while setting up greenchoice platform for sensor
Traceback (most recent call last):
File "/home/hass/.local/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 184, in _async_setup_platform
await asyncio.shield(task)
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/hass/.homeassistant/custom_components/greenchoice/sensor.py", line 56, in setup_platform
greenchoice_api.update()
File "/home/hass/.local/lib/python3.8/site-packages/homeassistant/util/__init__.py", line 239, in wrapper
result = method(*args, **kwargs)
File "/home/hass/.homeassistant/custom_components/greenchoice/sensor.py", line 195, in update
self.result["currentGas"] = json_result[1]["MeterstandenOutput"][0]["Hoog"]
IndexError: list index out of range
so it looks like it can't handle the result if there's no gas output.
I received data with the GET "https://app.greenchoice.nl/api/v2/meterstanden/getstanden?".
I did only receive 1 day. Is this common? Is there also a way to extend the data range?
I'm trying to get the contract id using the curl method.
I've succeeded in getting the token with my username/password. When executing the second command with the token, I get the following response:
{"Message":"Authorization has been denied for this request."}
What could be wrong here? I've tried to paste the following as token (replacing ******** directly after Authorization Bearer:
Any other options? Or possible root causes?
Would you be so kind to add screenshots to the readme section how to input the POST request?
I am not able to figure that out and I would love to use this component.
Great that you developed this plugin, but I don't understand the instructions. How to enter the full URL so I get a token?
Tried https://app.greenchoice.nl/token?grant_type=password&client_id=MobileApp&client_secret=A6E60EBF73521F57&username="MY EMAIL"&password="PASSWORD"
When using CURL instruction I cannot find the right token it looks like, but then the API responds authorization has been denied
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.