home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.3k stars 30.62k forks source link

Loop energy component not working #8137

Closed brinzlee closed 6 years ago

brinzlee commented 7 years ago

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version): 47.0

Python release (python3 --version): 3.4.2

Component/platform: Loop Energy

Description of problem:

I have followed the example of extracting the key and inserting them. But it returns an error every time

Expected:

Problem-relevant configuration.yaml entries and steps to reproduce:

sensor:
  - platform: loopenergy
    electricity:
      electricity_serial: 'ELECTRICAL_SERIAL'
      electricity_secret: 'ELECTRICAL_SECRET'
    gas:
      gas_serial: 'GAS_SERIAL'
      gas_secret: 'GAS_SECRET'

Traceback (if applicable):

2017-06-21 10:58:06 ERROR (LoopEnergy Event Thread) [pyloopenergy.loop_energy] Could not connect to https://www.your-loop.com
2017-06-21 10:58:06 ERROR (LoopEnergy Event Thread) [pyloopenergy.loop_energy] Please check your keys are correct. Terminating

Additional info: I have followed the example of extracting the key and inserting them. But it returns an error every time

matthewcky2k commented 7 years ago

Used to work fine for me until I upgraded to 47.1 now the log just says the component is initialised but doest get any data.

Coedy commented 7 years ago

Same issue here, worked fine but has been broken since update. About to update to the new release going it's fixed but don't see anything in the change log about it. I get this error in the log:

2017-07-16 00:13:05 ERROR (LoopEnergy Event Thread) [pyloopenergy.loop_energy] Could not connect to https://www.your-loop.com
2017-07-16 00:13:05 ERROR (LoopEnergy Event Thread) [pyloopenergy.loop_energy] Please check your keys are correct. Terminating

Despite no changes to my secret key/serial in the config. Front end is there in the UI but just states "unknown" Hope that helps!

BenWoodford commented 7 years ago

Mine isn't pulling data either, except I don't even get any errors in the logs. I have a "Power Usage" item in HASS but it's permanently at 0.

brinzlee commented 7 years ago

I still can't get this sensor to work runnig Hass.IO now version 0.53.1. I never have got this working on any version I've had so far

rt45433 commented 6 years ago

Hi there, I have just tried to setup the loop as above and just like BenWoodford. It all shows up in HA as "Power Usage" but reading is permanently 0. Can someone please look at this. I would be very grateful.

brinzlee commented 6 years ago

I also tried a new install from HassIO.....now version 0.57.3...I have no idea how others have managed to get this working.....I can only assume that they have been using a very early version of HomeAssistant. I flagged this back in June.....but I guess because of its limited market no one can be bothered to address it !!

rt45433 commented 6 years ago

Yeah its a shame. I only went out and bought one of these loop devices purely to use through home assistant as it has it listed a component. Currently, no use to me if not working.

matthewcky2k commented 6 years ago

Strange it works fine for me after I deleted my DB file it's working for me on. 58

rt45433 commented 6 years ago

Hi Matthew, do you know how I can delete my DB file? It's worth a try.

rt45433 commented 6 years ago

Update, I start home assistant, deleted the DB and restarted. This created the new DB and sadly still not got loop energy working.

brinzlee commented 6 years ago

I deleted my DB too with no resolution.....Matthew would you be kind enough to copy your entry in the configuration.yaml and redact the sensitive user information. I would just like to see if there is any difference to what I have. Thanks

matthewcky2k commented 6 years ago
 sensor 3:
  platform: loopenergy
  electricity:
    electricity_serial: redacted
    electricity_secret: redacted
  gas:
   gas_serial: redacted
   gas_secret: redacted
   gas_type: metric
brinzlee commented 6 years ago

Do you have the information that has been redacted in any form of quotes.

matthewcky2k commented 6 years ago

Nope

matthewcky2k commented 6 years ago

Think that's you problem if your using quote marks they are not required

brinzlee commented 6 years ago

Just doesn't want to play ball....the example gives quotes https://home-assistant.io/components/sensor.loop_energy/ .....but I have now removed them....reset the DB....I don't even get 0 as a reading all I get is Power Usage unknown kW Gas Usage unknown kW

brinzlee commented 6 years ago

Looking at the source code on github....it's been removed so I guess that doesn't bode well https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/sensor/loop_energy.py

MartinHjelmare commented 6 years ago

Your link is wrong. Here it is: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/sensor/loopenergy.py

brinzlee commented 6 years ago

Thanks....That was the link on the LoopEnergy page.... I have written an email to one of the authors asking for his assistance....

rt45433 commented 6 years ago

Please keep us posted on your outcome.

fabaff commented 6 years ago

Can somebody please check manually if the connection works? In your venv if needed.

$ python3
>>> import pyloopenergy
>>> elec_serial = 'your serial'
>>> elec_secret = 'your_secret'
>>> le = pyloopenergy.LoopEnergy(elec_serial, elec_secret)
>>> le.electricity_useage
[Should be the value]
>>> le.terminate()
brinzlee commented 6 years ago

Thanks for your help with this Fabian....I am not very knowledgeable with use of the command line so not really sure how to test this. Is there anybody else that has loopenergy who can try this. I originally started this thread back in June but haven’t really had any success with it. There are a few other users who are experiencing the same issues and some that have it working with exactly the same config.yaml. It’s very frustrating.

BenWoodford commented 6 years ago
>>> import pyloopenergy
>>> elec_serial = 'foo'
>>> elec_secret = 'bar'
>>> le = pyloopenergy.LoopEnergy(elec_serial, elec_secret)
>>> le.electricity_usage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: LoopEnergy instance has no attribute 'electricity_usage'
>>> le
<pyloopenergy.loop_energy.LoopEnergy instance at 0x7f918c545bd8>
>>> from pprint import pprint
>>> pprint(vars(le))
{'_elec_callback': None,
 '_event_thread': <Thread(LoopEnergy Event Thread, started 140263043999488)>,
 '_gas_callback': None,
 'connected_ok': True,
 'elec_kw': 0.609,
 'elec_secret': 'foo',
 'elec_serial': 'bar',
 'gas_device_timestamp': None,
 'gas_kw': None,
 'gas_meter_calorific': 39.11,
 'gas_meter_type': 'metric',
 'gas_old_reading': None,
 'gas_old_timestamp': None,
 'gas_reading': None,
 'gas_secret': None,
 'gas_serial': None,
 'reconnect_needed': False,
 'thread_exit': False,
 'updated_in_interval': True}

For the record, I have no gas monitor any more (smart meter, not compatible) which is why there's no secret/serial there.

The elec_kw is indeed accurate.

EDIT: Oh, it's useage not usage (spelling is wrong then...), that does spit out the value.

brinzlee commented 6 years ago

Where did you type that in Ben.....I'm not so good with Python....You wrote earlier in this thread yours wasn't working either.....although the script looks like it's outputting your electricity value

BenWoodford commented 6 years ago

pyloopenergy is the library, so there's an issue with the Home Assistant implementation, not the library which spits it out fine.

MartinHjelmare commented 6 years ago

@BenWoodford Can you make a PR with the fix? Otherwise I can make one, if you can test it. Edit: Nevermind, I thought you had found the cause.

brinzlee commented 6 years ago

@fabaff So @BenWoodford has run the script and deduced that it is a problem with the Home Assistant implementation...Is this something you can look at, or recommend how we can get a resolution.

BenWoodford commented 6 years ago

I’ve just been having a tinker with this and added some more debug lines to see if any callbacks are firing.

Unfortunately, it doesn’t seem like anything is firing at all. The callbacks work perfectly when done through the example script but through HASS everything sets up correctly, the web socket doesn’t show any errors (or lack of polling) but it never fires the callback in the component to update things and I’m not sure it ever fires the callback within the library that updates its internal values and subsequently calls the callback from the component either.

Very strange. It’s the same version too.

Maybe @pavoni can shed some light

BenWoodford commented 6 years ago

The plot thickens!

I just setup a dev HASS environment, for unrelated reasons. Guess what? No issues with Loop, I get my power usage as expected.

That makes absolutely 0 sense.

To those on this issue, are you using the Docker container? And if not, what version of Python do you have installed?

Update: Just tried the code @fabaff provided, but in my Docker container instead.

>>> Exception in thread LoopEnergy Event Thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/pyloopenergy/loop_energy.py", line 134, in _run_event_thread
    Namespace) as socket_io:
  File "/usr/local/lib/python3.6/site-packages/socketIO_client/__init__.py", line 356, in __init__
    resource, hurry_interval_in_seconds, **kw)
  File "/usr/local/lib/python3.6/site-packages/socketIO_client/__init__.py", line 54, in __init__
    self._transport
  File "/usr/local/lib/python3.6/site-packages/socketIO_client/__init__.py", line 62, in _transport
    self._engineIO_session = self._get_engineIO_session()
  File "/usr/local/lib/python3.6/site-packages/socketIO_client/__init__.py", line 76, in _get_engineIO_session
    transport.recv_packet())
StopIteration

This appears to be related to https://github.com/pavoni/pyloopenergy/issues/26

So it's environment specific, fantastic.

pavoni commented 6 years ago

I also couldn't get this working in hassio, I couldn't work out how to debug - so ended up switching back to run HA on my mac mini.

Very interesting it's the same error.

BTW I'm sure people realised - but any exception on that thread kills the monitoring - and it won't restart until you reload HA.

adsmf commented 6 years ago

I found that switching to socketIO client 0.5.7.2 seems to bring this back to life (the default installed is 0.5.6)

Loop use the 0.9 protocol and https://github.com/invisibleroads/socketIO-client says

If you want to communicate using socket.io protocol 0.9 (which is compatible with gevent-socketio), please use socketIO-client 0.5.7.2.

Coedy commented 6 years ago

Adsmf - That's great!! Could you knock up a quick how to? I'm a terrible newbie.... This would be really handy to get working given the cold snap and the start of the new month!

adsmf commented 6 years ago

I achieved my change the hacky way - by logging into hass via the resin.os core ssh, jumping into the homeassistant container and running pip3 install socketIO-client==0.5.7.2 Not sure it'd be the recommended approach (in fact I'm pretty sure it's not!).

I'll see if I can work out a more friendly way (other than the component itself being updated).

Coedy commented 6 years ago

Ahhh, I'm on Hassbian at the moment so imagine I would only need the Hacky install script, I'll hang on until yourself or someone works out a more eluant solution.

If I get bored though I'll totally do a backup of my install and use the quick and dirty method. So thanks again!

brinzlee commented 6 years ago

So who do we have to get to fix this.....There are so many clever people that must be able to address the issue...?

adsmf commented 6 years ago

So, I think the proper long term solution will be to get pyloopenergy to up the version in the requirements file - though I'm not sure if there's any other reason they've locked it to 0.5.6.

I think that a quick and dirty custom component may provide a temporary patch (I'm sure someone who knows better is going to shout at me for this suggestion).

In your config directory under the custom_components directory try creating a force_versions.py containing:

DOMAIN = 'force_versions'

REQUIREMENTS = [
    'socketIO-client==0.5.7.2'
]

def setup(hass, config):
    return True

Then add:

force_versions:

to your config.

pavoni commented 6 years ago

Thanks for tracking this down @adsmf

Have released pyloopenergy 0.0.18 with the change in library.

I'm not in the same place as my HA - so I tested the library works stand alone - but can't test it in HA/hassio.

If someone can check this works OK we can close the issue and get it in the next HA release.

brinzlee commented 6 years ago

I will try and test it....But have no idea what to do !!

adsmf commented 6 years ago

@pavoni Thanks for the quick turnaround on that - I'll create a temporary custom component that pulls the new version and report back :)

adsmf commented 6 years ago

Turns out that was faster than I thought to test. That's working well on my hass.io instance.

matthewcky2k commented 6 years ago

I assume this will also fix this issue?

https://github.com/home-assistant/home-assistant/issues/9687

brinzlee commented 6 years ago

@adsmf so what did you do to make it work.....Do I have to wait for the next version of Hass.IO to come out or is there some code I can update....

adsmf commented 6 years ago

The easiest and cleanest way is certainly to wait for a release with the update. The way I tested the update library was to clone the contents of https://github.com/home-assistant/home-assistant/blob/0.64.1/homeassistant/components/sensor/loopenergy.py into /config/custom_components/sensor/loopenergy.py and modify the requirements line (https://github.com/home-assistant/home-assistant/blob/0.64.1/homeassistant/components/sensor/loopenergy.py#L20) to be for version 0.0.18.

If you do go down that route you'll want to remove the custom component when the release rolls around so you don't miss out on any other changes to the file (as the custom version would always override).

brinzlee commented 6 years ago

Thanks for the heads up Alex.....I might wait for the next release then....