Fetch Tesla Power Wall State of charge using EmonHub

I’ve updated the code on the EmonHub repository to use PROTOCOL_SSLv23 for the time being Update EmonHubTeslaPowerWallInterfacer.py · openenergymonitor/emonhub@d4633e3 · GitHub

That doesn’t work:

ctx = ssl.SSLContext(ssl.PROTOCOL_SSL)
AttributeError: ‘module’ object has no attribute ‘PROTOCOL_SSL’

I have the script working with Python3 now :slight_smile:

1 Like

Its PROTOCOL_TLS rather than SSL … hopefully that will work

Yes indeed it does.

OK showing my complete ignorance here, how do I update the Powerwall interfacer?!

Great that the TLS options works, sounds like that might mean we’ve made a secure connection!

cd /opt/openenergymonitor/emonhub
git pull origin powerwall
sudo service emonhub restart

Did you run the above without PYTHONHTTPSVERIFY=0?

Yes, but we’ll soon find out if it really works when I update :wink:

1 Like

Yay it works!
I even remebered to check I’d disabled my crontab :slight_smile:
Output from emonhub.log:

2020-05-11 14:55:46,230 DEBUG PowerWall Request response: {“percentage”:100}
2020-05-11 14:55:46,231 DEBUG PowerWall 7 NEW FRAME :
2020-05-11 14:55:46,232 DEBUG PowerWall 7 Timestamp : 1589205346.23
2020-05-11 14:55:46,233 DEBUG PowerWall 7 From Node : powerwall
2020-05-11 14:55:46,234 DEBUG PowerWall 7 Values : [100]
2020-05-11 14:55:46,234 DEBUG PowerWall 7 Sent to channel(start)’ : ToEmonCMS
2020-05-11 14:55:46,235 DEBUG PowerWall 7 Sent to channel(end)’ : ToEmonCMS
2020-05-11 14:55:46,416 DEBUG MQTT Publishing: emon/powerwall/soc 100
2020-05-11 14:55:46,418 INFO MQTT Publishing: emonhub/rx/powerwall/values 100

As you can see, it is sunny here today :sweat_smile:

1 Like

Great news, I’ve merged this in to the main emonhub branch now, would you mind switching back and testing one more time?

cd /opt/openenergymonitor/emonhub
git checkout emon-pi
git pull origin emon-pi
sudo service emonhub restart

Strictly

sudo systemctl restart emonhub.service
1 Like

Confirmed it works. Happy days.

1 Like

Great, thanks for all of your help @PeteF it will be great to look at expanding on this once we are on python3 with the tesla-powerwall specific library @borpin mentioned

Trystan, before you update the Tags etc, can the default emonhub.conf be tidied up especially for the Serial interfacer please. And the documentation for the new interfacer?

1 Like

Documentation updated and tags created:

Im not sure what you meant re serial interfacer configuration @borpin?

I had to do something odd to edit the default emonhub to work with a serial interface. Can’t remember what now…

[edit] This was what I ended up with.

[[SerialTx]]
     Type = EmonHubTx3eInterfacer
      [[[init_settings]]]
           com_port= /dev/ttyAMA0
           com_baud = 115200
      [[[runtimesettings]]]
           pubchannels = ToEmonCMS,

[edit] Oh I know - it isn’t in the docs at all! @TrystanLea

Could you add an explanation of pubchannels and subchannels to the docs please as well and also remove the pubchannel entry from the HTTP interfacer as I’m sure in another thread you said it wasn’t implemented. Just adds to the confusion…

@TrystanLea

This thread is most timely as later this week I’ll be installing 3 x PowerWall’s at my son’s place. He has a large 30kWp PV installation.
In anticipation I’ve set up an RPi with the Oct 2019 emon image which is fully updated via the Admin web page.

First question …
Given there’s more than one PowerWall, do I add multiple EmonHubTeslaPowerWallInterfacers to emonhub.conf or can there be multiple ‘url = ’ lines in just one Interfacer?

Second question …
Charge level is not the only interesting battery parameter. Charge/discharge power are equally important. Do you know the API’s for this info? And would each require a separate Interfacer or will multiple ‘url = ’ lines handle it?

Perhaps there are clues here …

or here … Tesla Powerwall2 data to PVoutput? - Powerwall - PVOutput Community

So instead of url = http://POWERWALL-IP/api/system_status/soe

USE url = http://POWERWALL-IP/api/meters/battery/instant_power

OR url = http://POWERWALL-IP/api/meters/aggregates/battery/instant_power

Thanks in advance

Yes, add multiple interfacers, one for each powerwall.

On the basis of the answer below I suggest not. However, I did point @TrystanLea to the Python package for the Powerwall which could in theory do it.

There is also a good node for Node-RED that could then feed into emoncms.

@TrystanLea
The PowerWalls at my son’s place are now up and running but not yet optimised.

In a browser I can go to 192.168.1.140/api/system_status/soe and PowerWall reports the battery charge level % which is great.

However, an on-site RPi running emon updated to 10.2.3 with the PowerWall interfacer included in emonhub.conf has problems.

This is an excerpt from the log:

2020-07-05 01:09:35,499 WARNING  MainThread PowerWall thread is dead.
2020-07-05 01:09:35,500 WARNING  MainThread Attempting to restart thread PowerWall (thread has been restarted 1 times...
2020-07-05 01:09:35,501 INFO     MainThread Creating EmonHubTeslaPowerWallInterfacer 'PowerWall' 
2020-07-05 01:09:35,502 INFO     MainThread Setting PowerWall name: powerwall
2020-07-05 01:09:35,502 INFO     MainThread Setting PowerWall url: http://192.168.1.140/api/system_status/soe
2020-07-05 01:09:35,502 INFO     MainThread Setting PowerWall readinterval: 10
2020-07-05 01:09:35,503 DEBUG    MainThread Setting PowerWall pubchannels: ['ToEmonCMS']
2020-07-05 01:09:41,875 INFO     MainThread EmonHub emonHub emon-pi variant v3-beta
2020-07-05 01:09:41,875 INFO     MainThread Opening hub...
2020-07-05 01:09:41,876 INFO     MainThread Logging level set to DEBUG
2020-07-05 01:09:41,876 INFO     MainThread Creating EmonHubJeeInterfacer 'RFM2Pi' 
2020-07-05 01:09:41,878 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2020-07-05 01:09:43,881 WARNING  MainThread Device communication error - check settings
2020-07-05 01:09:43,882 INFO     MainThread Setting RFM2Pi baseid: 5 (5i)
2020-07-05 01:09:44,885 INFO     MainThread Setting RFM2Pi frequency: 433 (4b)
2020-07-05 01:09:45,888 INFO     MainThread Setting RFM2Pi group: 210 (210g)
2020-07-05 01:09:46,890 INFO     MainThread Setting RFM2Pi quiet: 1 (1q)
2020-07-05 01:09:47,893 INFO     MainThread Setting RFM2Pi calibration: 230V (1p)
2020-07-05 01:09:48,895 DEBUG    MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2020-07-05 01:09:48,896 DEBUG    MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2020-07-05 01:09:48,898 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2020-07-05 01:09:48,901 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2020-07-05 01:09:48,902 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2020-07-05 01:09:48,903 INFO     MainThread Setting MQTT node_format_enable: 1
2020-07-05 01:09:48,903 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2020-07-05 01:09:48,904 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2020-07-05 01:09:48,905 INFO     MainThread Creating EmonHubTeslaPowerWallInterfacer 'PowerWall' 
2020-07-05 01:09:48,907 INFO     MainThread Setting PowerWall name: powerwall
2020-07-05 01:09:48,907 INFO     MainThread Setting PowerWall url: http://192.168.1.140/api/system_status/soe
2020-07-05 01:09:48,908 INFO     MainThread Setting PowerWall readinterval: 10
2020-07-05 01:09:48,908 DEBUG    MainThread Setting PowerWall pubchannels: ['ToEmonCMS']
2020-07-05 01:09:48,910 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'To_watchman' 
2020-07-05 01:09:48,912 DEBUG    MainThread Setting To_watchman pubchannels: ['ToRFM12']
2020-07-05 01:09:48,912 DEBUG    MainThread Setting To_watchman subchannels: ['ToEmonCMS']
2020-07-05 01:09:48,913 INFO     MainThread Setting To_watchman apikey: set
2020-07-05 01:09:48,913 INFO     MainThread Setting To_watchman url: http://192.168.1.10/emoncms
2020-07-05 01:09:48,914 INFO     MainThread Setting To_watchman senddata: 1
2020-07-05 01:09:48,914 INFO     MainThread Setting To_watchman sendstatus: 0
2020-07-05 01:09:59,280 WARNING  PowerWall  PowerWall couldn't send to server: HTTPSConnectionPool(host='192.168.1.140', port=443): Max retries exceeded with url: /api/system_status/soe (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
2020-07-05 01:09:59,307 WARNING  PowerWall  Exception caught in PowerWall thread. Traceback (most recent call last):
  File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 32, in wrapper
    return f(*args)
  File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 99, in run
    rxc = self.read()
  File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubTeslaPowerWallInterfacer.py", line 49, in read
    jsonstr = reply.text.rstrip()
UnboundLocalError: local variable 'reply' referenced before assignment

It seems to be an SSL Certificate error that’s the problem?

@TrystanLea

I really would appreciate your advice/suggestions

Many thx