Fetch Tesla Power Wall State of charge using EmonHub

Post the conf please.

Have you done an update recently? emonhub should be at this commit.

pi@emonpi:~ $ git -C /opt/openenergymonitor/emonhub show
commit c241601f5d2cf2836a401a8b88b0f9eb9380137a (HEAD -> stable, origin/stable)
Merge: 1e723a6 19a8835
Author: TrystanLea <[email protected]>
Date:   Mon Jun 22 14:54:08 2020 +0100

    Merge branch 'stable' of https://github.com/openenergymonitor/emonhub into stable

[edit]

That specific exception has been addressed and merged to master. It is raised because the python3 works slightly differently.

I thought the SSL error had been fixed above.

You might want to switch branch to master and see if that changes things.

@TrystanLea it looks like this never made it to master or therefore stable.

The interfacer in emon-pi branch is different to the stable or master versions.

@borpin

I did an update yesterday just before reporting the above errors.

Herewith my emonhub.conf …

#######################################################################
#######################      emonhub.conf     #########################
#######################################################################
### emonHub configuration file, for info see documentation:
### https://github.com/openenergymonitor/emonhub/blob/emon-pi/conf/emonhub.conf
#######################################################################
#######################    emonHub  settings    #######################
#######################################################################

[hub]
### loglevel must be one of DEBUG, INFO, WARNING, ERROR, and CRITICAL
loglevel = DEBUG
### Uncomment this to also send to syslog
# use_syslog = yes
#######################################################################
#######################       Interfacers       #######################
#######################################################################

[interfacers]
### This interfacer manages the RFM12Pi/RFM69Pi/emonPi module
[[RFM2Pi]]
    Type = EmonHubJeeInterfacer
    [[[init_settings]]]
        com_port = /dev/ttyAMA0
        com_baud = 38400                        # 9600 for old RFM12Pi
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

        group = 210
        frequency = 433
        baseid = 5                              # emonPi / emonBase nodeID
        calibration = 230V                      # (UK/EU: 230V, US: 110V)
        quiet = true                            # Disable quite mode (default enabled) to enable RF packet debugging, show packets which fail crc
        # interval =  300                         # Interval to transmit time to emonGLCD (seconds)
        

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        mqtt_host = 127.0.0.1
        mqtt_port = 1883
        mqtt_user = emonpi
        mqtt_passwd = emonpimqtt2016

    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,

        # emonhub/rx/10/values format
        # Use with emoncms Nodes module
        node_format_enable = 1
        node_format_basetopic = emonhub/

        # emon/emontx/power1 format - use with Emoncms MQTT input
        # http://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/MQTT.md
        nodevar_format_enable = 1
        nodevar_format_basetopic = emon/

[[PowerWall]]
    Type = EmonHubTeslaPowerWallInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        name = powerwall
        url = http:/192.168.1.140/api/system_status/soe
        readinterval = 10

[[To_watchman]]
    Type = EmonHubEmoncmsHTTPInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,
        url = http://192.168.1.10/emoncms     # watchman’s FIXED IP address
        apikey = 4448328134be7b9b3f0447f49f910e8b
        senddata = 1      # To _watchman
        sendstatus = 0

#######################################################################
#######################          Nodes          #######################
#######################################################################

[nodes]

## See config user guide: https://github.com/openenergymonitor/emonhub/blob/emon-pi/conf/emonhub.conf

[[5]]
    nodename = emonpi
    [[[rx]]]
        names = power1,power2,power1pluspower2,vrms,t1,t2,t3,t4,t5,t6,pulsecount
        datacodes = h, h, h, h, h, h, h, h, h, h, L
        scales = 1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
        units = W,W,W,V,C,C,C,C,C,C,p

[[6]]
    nodename = emontxshield
    [[[rx]]]
       names = power1, power2, power3, power4, vrms
       datacode = h
       scales = 1,1,1,1,0.01
       units = W,W,W,W,V

[[7]]
   nodename = emontx4
   [[[rx]]]
      names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
      datacodes = h,h,h,h,h,h,h,h,h,h,h,L
      scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
      units = W,W,W,W,V,C,C,C,C,C,C,p

[[8]]
    nodename = emontx3
    [[[rx]]]
       names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[9]]
   nodename = emontx2
   [[[rx]]]
      names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
      datacodes = h,h,h,h,h,h,h,h,h,h,h,L
      scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
      units = W,W,W,W,V,C,C,C,C,C,C,p

[[10]]
    nodename = emontx1
    [[[rx]]]
       names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[11]]
    nodename = 3phase
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
       units = W,W,W,W,V,C,C,C,C,C,C,p
       
[[12]]
    nodename = 3phase2
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[13]]
    nodename = 3phase3
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[14]]
    nodename = 3phase4
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[15]]
    nodename = emontx3cm15
    [[[rx]]]
       names = MSG, Vrms, P1, P2, P3, P4, E1, E2, E3, E4, T1, T2, T3, pulse
       datacodes = L,h,h,h,h,h,L,L,L,L,h,h,h,L
       scales = 1,0.01,1,1,1,1,1,1,1,1,0.01,0.01,0.01,1
       units = n,V,W,W,W,W,Wh,Wh,Wh,Wh,C,C,C,p
       whitening = 1

[[16]]
    nodename = emontx3cm16
    [[[rx]]]
       names = MSG, Vrms, P1, P2, P3, P4, E1, E2, E3, E4, T1, T2, T3, pulse
       datacodes = L,h,h,h,h,h,L,L,L,L,h,h,h,L
       scales = 1,0.01,1,1,1,1,1,1,1,1,0.01,0.01,0.01,1
       units = n,V,W,W,W,W,Wh,Wh,Wh,Wh,C,C,C,p
       whitening = 1

[[19]]
   nodename = emonth1
   [[[rx]]]
      names = temperature, external temperature, humidity, battery
      datacode = h
      scales = 0.1,0.1,0.1,0.1
      units = C,C,%,V

[[20]]
   nodename = emonth2
   [[[rx]]]
      names = temperature, external temperature, humidity, battery
      datacode = h
      scales = 0.1,0.1,0.1,0.1
      units = C,C,%,V

[[21]]
   nodename = emonth3
   [[[rx]]]
      names = temperature, external temperature, humidity, battery
      datacode = h
      scales = 0.1,0.1,0.1,0.1
      units = C,C,%,V

[[22]]
   nodename = emonth4
   [[[rx]]]
      names = temperature, external temperature, humidity, battery
      datacode = h
      scales = 0.1,0.1,0.1,0.1
      units = C,C,%,V

[[23]]
    nodename = emonth5
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulsecount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[24]]
    nodename = emonth6
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulsecount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[25]]
    nodename = emonth7
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulsecount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[26]]
    nodename = emonth8
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulsecount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[5]]
    nodename = emonPi
    firmware = emonPi_RFM69CW_RF12Demo_DiscreteSampling.ino
    hardware = emonpi
    [[[rx]]]
        names = power1,power2,power1_plus_power2,Vrms,T1,T2,T3,T4,T5,T6,pulseCount
        datacodes = h, h, h, h, h, h, h, h, h, h, L
        scales = 1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
        units = W,W,W,V,C,C,C,C,C,C,p

[[6]]
    nodename = emonTxShield
    firmware =emonTxShield
    hardware = emonTxShield
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms
       datacode = h
       scales = 1,1,1,1,0.01
       units =W,W,W,W,V

[[7]]
    nodename = emonTx_4
    firmware =V2_3_emonTxV3_4_DiscreteSampling
    hardware = emonTx_(NodeID_DIP_Switch1:OFF)
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 
       units =W,W,W,W,V,C,C,C,C,C,C,p

[[8]]
    nodename = emonTx_3
    firmware =V2_3_emonTxV3_4_DiscreteSampling
    hardware = emonTx_(NodeID_DIP_Switch1:OFF)
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 
       units =W,W,W,W,V,C,C,C,C,C,C,p 

[[9]]
    nodename = emonTx_2
    firmware =V1_6_emonTxV3_4_DiscreteSampling
    hardware = emonTx_(NodeID_DIP_Switch1:ON)
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse #Firmware V1.6
       #names = power1, power2, power3, power4, Vrms, temp                                           #Firmware =<V1.4 (un-comment)
       datacode = h
       scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 #Firmware V1.6
       units =W,W,W,W,V,C,C,C,C,C,C,p                   #FirmwareV1.6
       #scales = 1,1,1,1,0.01,0.1                       #Firmware =<V1.4 (un-comment) 
       #units =W,W,W,W,V,C                              #Firmware =<V1.4 (un-comment)

[[10]]
    nodename = emonTx_1
    firmware =V1_6_emonTxV3_4_DiscreteSampling
    hardware = emonTx_(NodeID_DIP_Switch1:OFF)
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse #Firmware V1.6
       #names = power1, power2, power3, power4, Vrms, temp                                           #Firmware =<V1.4 (un-comment)
       datacode = h
       scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 #Firmware V1.6
       units =W,W,W,W,V,C,C,C,C,C,C,p                   #FirmwareV1.6
       #scales = 1,1,1,1,0.01,0.1                       #Firmware =<V1.4 (un-comment) 
       #units =W,W,W,W,V,C                              #Firmware =<V1.4 (un-comment)

[[11]]
    nodename = 3phase
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
       units =W,W,W,W,V,C,C,C,C,C,C,p

[[12]]
    nodename = 3phase2
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
       units =W,W,W,W,V,C,C,C,C,C,C,p

[[13]]
    nodename = 3phase3
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[14]]
    nodename = 3phase4
    [[[rx]]]
       names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
       datacodes = h,h,h,h,h,h,h,h,h,h,h,L
       scales = 1,1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
       units = W,W,W,W,V,C,C,C,C,C,C,p

[[15]]
    nodename = emontx3cm15
    [[[rx]]]
        names = MSG, Vrms, P1, P2, P3, P4, E1, E2, E3, E4, T1, T2, T3, pulse
        datacodes = L,h,h,h,h,h,L,L,L,L,h,h,h,L
        scales = 1,0.01,1,1,1,1,1,1,1,1,0.01,0.01,0.01,1
        units = n,V,W,W,W,W,Wh,Wh,Wh,Wh,C,C,C,p
        whitening = 1

[[16]]
    nodename = emontx3cm16
    [[[rx]]]
        names = MSG, Vrms, P1, P2, P3, P4, E1, E2, E3, E4, T1, T2, T3, pulse
        datacodes = L,h,h,h,h,h,L,L,L,L,h,h,h,L
        scales = 1,0.01,1,1,1,1,1,1,1,1,0.01,0.01,0.01,1
        units = n,V,W,W,W,W,Wh,Wh,Wh,Wh,C,C,C,p
        whitening = 1

[[19]]
    nodename = emonTH_1
    firmware = emonTH_DHT22_DS18B20_RFM69CW
    hardware = emonTH_(Node_ID_Switch_DIP1:OFF_DIP2:OFF)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery
       datacode = h
       scales = 0.1,0.1,0.1,0.1
       units = C,C,%,V

[[20]]
    nodename = emonTH_2
    firmware = emonTH_DHT22_DS18B20_RFM69CW
    hardware = emonTH_(Node_ID_Switch_DIP1:ON_DIP2:OFF)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery
       datacode = h
       scales = 0.1,0.1,0.1,0.1
       units = C,C,%,V

[[21]]
    nodename = emonTH_3
    firmware = emonTH_DHT22_DS18B20_RFM69CW
    hardware = emonTH_(Node_ID_Switch_DIP1:OFF_DIP2:ON)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery
       datacode = h
       scales = 0.1,0.1,0.1,0.1
       units = C,C,%,V

[[22]]
    nodename = emonTH_4
    firmware = V1_5_emonTH_DHT22_DS18B20_RFM69CW
    hardware = emonTH_(Node_ID_Switch_DIP1:ON_DIP2:ON)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery
       datacode = h
       scales = 0.1,0.1,0.1,0.1
       units = C,C,%,V

[[23]]
    nodename = emonTH_5
    firmware = V2.x_emonTH_DHT22_DS18B20_RFM69CW_Pulse
    hardware = emonTH_(Node_ID_Switch_DIP1:OFF_DIP2:OFF)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulseCount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[24]]
    nodename = emonTH_6
    firmware = V2.x_emonTH_DHT22_DS18B20_RFM69CW_Pulse
    hardware = emonTH_(Node_ID_Switch_DIP1:ON_DIP2:OFF)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulseCount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[25]]
    nodename = emonTH_7
    firmware = V2.x_emonTH_DHT22_DS18B20_RFM69CW_Pulse
    hardware = emonTH_(Node_ID_Switch_DIP1:OFF_DIP2:ON)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulseCount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

[[26]]
    nodename = emonTH_8
    firmware = V2.x_emonTH_DHT22_DS18B20_RFM69CW_Pulse
    hardware = emonTH_(Node_ID_Switch_DIP1:ON_DIP2:ON)
    [[[rx]]]
       names = temperature, external temperature, humidity, battery, pulseCount
       datacodes = h,h,h,h,L
       scales = 0.1,0.1,0.1,0.1,1
       units = C,C,%,V,p

Herewith /opt/openenergymonitor/emonhub/src/interfacers/EmonhubTeslaWallInterfacer.py …

import time, json, Cargo, requests
from emonhub_interfacer import EmonHubInterfacer

"""class EmonHubTeslaPowerWallInterfacer

Fetch Tesla Power Wall state of charge

"""

class EmonHubTeslaPowerWallInterfacer(EmonHubInterfacer):

    def __init__(self, name):
        """Initialize Interfacer
        
        """

        # Initialization
        super(EmonHubTeslaPowerWallInterfacer, self).__init__(name)

        self._settings.update(self._defaults)

        # Interfacer specific settings
        self._template_settings = {'name':'powerwall', 'url':False, 'readinterval':10.0}
        
        # set an absolute upper limit for number of items to process per post
        self._item_limit = 250
        
        # Fetch first reading at one interval lengths time
        self._last_time = time.time()

    def read(self):
        """

        """
        
        # Request Power Wall data at user specified interval
        if (time.time()-self._last_time)>=self._settings['readinterval']:
            self._last_time = time.time()

            # If URL is set, fetch the SOC
            if self._settings['url']:
                # HTTP Request
                try:
                    reply = requests.get(self._settings['url'],timeout=int(self._settings['readinterval']))
                    reply.raise_for_status()  # Raise an exception if status code isn't 200
                except requests.exceptions.RequestException as ex:
                    self._log.warning(self.name + " couldn't send to server: " + str(ex))
                
                jsonstr = reply.text.rstrip()
                self._log.debug("Request response: "+str(jsonstr))
                
                # Decode JSON
                try:
                    data = json.loads(jsonstr)
                except:
                    self._log.warning("Invalid JSON")
                    return
            
                # Check if battery percentage key is in data object
                if not 'percentage' in data:
                    self._log.warning("Percentage key not found")
                    return
                
                # Extract SOC value
                soc = data['percentage']
 
                # Create cargo object
                c = Cargo.new_cargo()
                c.nodeid = self._settings['name']
                c.names = ["soc"]
                c.realdata = [soc]
                return c
        
        # return empty if not time
        return

    def set(self, **kwargs):
        """

        """

        for key, setting in self._template_settings.items():
            # Decide which setting value to use
            if key in kwargs.keys():
                setting = kwargs[key]
            else:
                setting = self._template_settings[key]
            if key in self._settings and self._settings[key] == setting:
                continue
            elif key == 'readinterval':
                self._log.info("Setting " + self.name + " readinterval: " + str(setting))
                self._settings[key] = float(setting)
                continue
            elif key == 'name':
                self._log.info("Setting " + self.name + " name: " + str(setting))
                self._settings[key] = setting
                continue
            elif key == 'url':
                self._log.info("Setting " + self.name + " url: " + str(setting))
                self._settings[key] = setting
                continue
            else:
                self._log.warning("'%s' is not valid for %s: %s" % (str(setting), self.name, key))

        # include kwargs from parent
        super(EmonHubTeslaPowerWallInterfacer, self).set(**kwargs)

Do you need anything else?

Would greatly appreciate your guidance on the changes I should now make.

Please be explicit - I’m not very good at this master, stable, commit kind of stuff
Many thanks

Until the change is pushed to the repo, all you can do is change the file EmonhubTeslaWallInterfacer.py to match the link I posted above.

The downside is that when you try and update later on it will fail so you need to put it back.

I suggest copy existing file and create a new file. So,

nano /opt/openenergymonitor/emonhub/src/interfacers/EmonHubTeslaPowerWallInterfacer.py

delete the contents and the paste the contents of the file from GitHub.

then restart emonHub (from the UI)

Once the repo is updated, before you update

git -C /opt/openenergymonitor/emonhub checkout src/interfacers/EmonHubTeslaPowerWallInterfacer.py

will put it back to how it was.

@borpin
Thx
I’ve copied the new Interfacer file (dated 11 May with 117 lines) but because I’m working remotely used WCP.
Here’s how the elevant directory now looks …

 pi@emonpi-node-15:/opt/openenergymonitor/emonhub/src/interfacers $ ls -l
total 148
-rw-r--r-- 1 pi pi  9849 Jun 14 22:39 EmonHubBMWInterfacer.py
-rw-r--r-- 1 pi pi  5379 Jun 14 22:39 EmonHubEmoncmsHTTPInterfacer.py
-rw-r--r-- 1 pi pi  4305 Jun 14 22:39 EmonHubGraphiteInterfacer.py
-rw-r--r-- 1 pi pi  8995 Jun 14 22:39 EmonHubJeeInterfacer.py
-rw-r--r-- 1 pi pi 10126 Jun 14 22:39 EmonHubMqttInterfacer.py
-rw-r--r-- 1 pi pi  4819 Jun 14 22:39 EmonHubPacketGenInterfacer.py
-rw-r--r-- 1 pi pi  2339 Jun 14 22:39 EmonHubSerialInterfacer.py
-rw-r--r-- 1 pi pi 12479 Jul  3 13:07 EmonHubSMASolarInterfacer.py
-rw-r--r-- 1 pi pi  5317 Jul  3 13:07 EmonHubSocketInterfacer.py
-rw-r--r-- 1 pi pi  4156 Jun 14 22:39 EmonHubTemplateInterfacer.py
-rw-r--r-- 1 pi pi  4224 Jul  5 13:27 EmonHubTeslaPowerWallInterfacer.py
-rwxr-xr-x 1 pi pi  4224 Jul  5 11:52 EmonHubTeslaPowerWallInterfacer.py.new
-rw-r--r-- 1 pi pi  3686 Jul  5 12:06 EmonHubTeslaPowerWallInterfacer.py.old
-rw-r--r-- 1 pi pi  2701 Jun 14 22:39 EmonHubTx3eInterfacer.py
-rw-r--r-- 1 pi pi  6237 Jun 14 22:39 EmonHubVEDirectInterfacer.py
-rw-r--r-- 1 pi pi  9692 Jun 14 22:39 EmonModbusTcpInterfacer.py
-rw-r--r-- 1 pi pi   534 Jun 14 22:39 __init__.py
drwxr-xr-x 2 pi pi  4096 Jun 14 22:39 tmp

So it’s easy to switch between old & new files just using cp and then doing an emonhub restart .

However, when using the new file there is nothing in the emonhub log window
There are no Inputs (or Feeds).
And no data is being sent to watchman another RPi on the local network.

Emon is running on an RPi without any connected emonTx or sensors.
Clearly there’s something missing in the emon.conf file or I’ve missed another setup step?

Any pointers?
Thx

Is the emonhub service running?

check syslog (either directly or using journalctl)

@borpin

I did a service restart and then checked status with the following result …

pi@emonpi-node-15:/var/log $ sudo systemctl restart emonhub.service
pi@emonpi-node-15:/var/log $ sudo systemctl status emonhub.service
● emonhub.service - emonHub service description
   Loaded: loaded (/opt/openenergymonitor/emonhub/service/emonhub.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-07-05 16:41:46 BST; 10s ago
  Process: 27410 ExecStartPre=/bin/mkdir -p /var/log/emonhub/ (code=exited, status=0/SUCCESS)
  Process: 27411 ExecStartPre=/bin/chgrp -R emonhub /var/log/emonhub/ (code=exited, status=0/SUCCESS)
  Process: 27412 ExecStartPre=/bin/chmod 775 /var/log/emonhub/ (code=exited, status=0/SUCCESS)
  Process: 27413 ExecStart=/usr/local/bin/emonhub/emonhub.py --config-file=/etc/emonhub/emonhub.conf --logfile=/var/log/emonhub/emonhub.
 Main PID: 27413 (code=exited, status=1/FAILURE)

Jul 05 16:41:46 emonpi-node-15 systemd[1]: emonhub.service: Service RestartSec=100ms expired, scheduling restart.
Jul 05 16:41:46 emonpi-node-15 systemd[1]: emonhub.service: Scheduled restart job, restart counter is at 5.
Jul 05 16:41:46 emonpi-node-15 systemd[1]: Stopped emonHub service description.
Jul 05 16:41:46 emonpi-node-15 systemd[1]: emonhub.service: Start request repeated too quickly.
Jul 05 16:41:46 emonpi-node-15 systemd[1]: emonhub.service: Failed with result 'exit-code'.
Jul 05 16:41:46 emonpi-node-15 systemd[1]: Failed to start emonHub service description.
lines 1-15/15 (END)

It fails to start …

Anything?

journalctl -u emonhub

@borpin

pi@emonpi-node-15:/opt/openenergymonitor/emonhub/src/interfacers $ journalctl -u emonhub
-- Logs begin at Sun 2020-07-05 14:20:22 BST, end at Sun 2020-07-05 17:53:45 BST. --
Jul 05 14:20:23 emonpi-node-15 systemd[1]: Starting emonHub service description...
Jul 05 14:20:23 emonpi-node-15 systemd[1]: Started emonHub service description.
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]: Traceback (most recent call last):
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]:   File "/usr/local/bin/emonhub/emonhub.py", line 26, in <module>
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]:     from interfacers import *
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]:   File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubTeslaPowerWallInterfacer.p
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]:     import time, json, Cargo, urllib2, ssl
Jul 05 14:20:25 emonpi-node-15 emonhub.py[341]: ModuleNotFoundError: No module named 'urllib2'
Jul 05 14:20:25 emonpi-node-15 systemd[1]: emonhub.service: Main process exited, code=exited, status=1/FAILURE
Jul 05 14:20:25 emonpi-node-15 systemd[1]: emonhub.service: Failed with result 'exit-code'.
Jul 05 14:20:26 emonpi-node-15 systemd[1]: emonhub.service: Service RestartSec=100ms expired, scheduling restart.
Jul 05 14:20:26 emonpi-node-15 systemd[1]: emonhub.service: Scheduled restart job, restart counter is at 1.
Jul 05 14:20:26 emonpi-node-15 systemd[1]: Stopped emonHub service description.
Jul 05 14:20:26 emonpi-node-15 systemd[1]: Starting emonHub service description...
Jul 05 14:20:26 emonpi-node-15 systemd[1]: Started emonHub service description.
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]: Traceback (most recent call last):
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]:   File "/usr/local/bin/emonhub/emonhub.py", line 26, in <module>
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]:     from interfacers import *
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]:   File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubTeslaPowerWallInterfacer.p
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]:     import time, json, Cargo, urllib2, ssl
Jul 05 14:20:27 emonpi-node-15 emonhub.py[428]: ModuleNotFoundError: No module named 'urllib2'
Jul 05 14:20:27 emonpi-node-15 systemd[1]: emonhub.service: Main process exited, code=exited, status=1/FAILURE
Jul 05 14:20:27 emonpi-node-15 systemd[1]: emonhub.service: Failed with result 'exit-code'.
Jul 05 14:20:27 emonpi-node-15 systemd[1]: emonhub.service: Service RestartSec=100ms expired, scheduling restart.
Jul 05 14:20:27 emonpi-node-15 systemd[1]: emonhub.service: Scheduled restart job, restart counter is at 2.
Jul 05 14:20:27 emonpi-node-15 systemd[1]: Stopped emonHub service description.
Jul 05 14:20:27 emonpi-node-15 systemd[1]: Starting emonHub service description...
Jul 05 14:20:27 emonpi-node-15 systemd[1]: Started emonHub service description.
Jul 05 14:20:28 emonpi-node-15 emonhub.py[442]: Traceback (most recent call last):
Jul 05 14:20:28 emonpi-node-15 emonhub.py[442]:   File "/usr/local/bin/emonhub/emonhub.py", line 26, in <module>
lines 

Does this help?

Yes

Mmmm.

So urllib2 does not seem to be available from apt. Try editing the file to import urllib3 and

sudo apt-install python3-urllib3

then restart emonhub.

@bwduncan @TrystanLea, this item suggest it should use requests rather than urllib. I note other interfacers use requests. python - What are the differences between the urllib, urllib2, urllib3 and requests module? - Stack Overflow

[edit] I updated the Issue to include this.

@borpin

apt-get install worked and I found that urllib3 was already installed.

Changed Interfacer file urllib2 to urllib3 and … BINGO! until it hit the next hurdle …

2020-07-05 18:25:29,298 INFO     MainThread EmonHub emonHub emon-pi variant v3-beta
2020-07-05 18:25:29,298 INFO     MainThread Opening hub...
2020-07-05 18:25:29,299 INFO     MainThread Logging level set to DEBUG
2020-07-05 18:25:29,299 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2020-07-05 18:25:29,302 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2020-07-05 18:25:29,303 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2020-07-05 18:25:29,303 INFO     MainThread Setting MQTT node_format_enable: 0
2020-07-05 18:25:29,303 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2020-07-05 18:25:29,303 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2020-07-05 18:25:29,304 INFO     MainThread Creating EmonHubTeslaPowerWallInterfacer 'PowerWall' 
2020-07-05 18:25:29,305 ERROR    MainThread Unable to create 'PowerWall' interfacer: 'dict' object has no attribute 'iteritems'
2020-07-05 18:25:29,306 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'To_watchman' 
2020-07-05 18:25:29,306 DEBUG    MainThread Setting To_watchman pubchannels: ['ToRFM12']
2020-07-05 18:25:29,307 DEBUG    MainThread Setting To_watchman subchannels: ['ToEmonCMS']
2020-07-05 18:25:29,307 INFO     MainThread Setting To_watchman apikey: set
2020-07-05 18:25:29,307 INFO     MainThread Setting To_watchman url: http://192.168.1.10/emoncms
2020-07-05 18:25:29,307 INFO     MainThread Setting To_watchman senddata: 1
2020-07-05 18:25:29,308 INFO     MainThread Setting To_watchman sendstatus: 0

You can ignore the watchman stuff.
Thx

It is using requests. As you say it looks like these changes never made it into the emon-pi branch. The error in the next post is also a result of old code from the python2 days.

Could you offer John a modified version to test?

@borpin

In parallel with the RPi you have been helping me with in the thread above, I have been experimenting with another RPi on the same network. It has an emonTx & sensors connected to monitor an EV charger.

I updated it to 10.2.3 but did not need to copy the latest PWInterfacer as it was already there - strange? And there was no /opt/openenergymonitor directory - also strange?.
I added the PWinterfacer lines into emonhub.conf
This time apt-get install found the need to install python3-six and python3-urllib3
I changed urllib2 to urllib3 in the PWinterfacer.py file … all as per yr suggestions
I restarted emonhub.service with the following log results …

2020-07-05 18:51:51,949 WARNING  MainThread PowerWall thread is dead.
2020-07-05 18:51:51,950 WARNING  MainThread Attempting to restart thread PowerWall (thread has been restarted 20 times...
2020-07-05 18:51:51,951 INFO     MainThread Creating EmonHubTeslaPowerWallInterfacer 'PowerWall' 
2020-07-05 18:51:51,952 INFO     MainThread Setting PowerWall url: http://192.168.1.140/api/system_status/soe
2020-07-05 18:51:51,952 INFO     MainThread Setting PowerWall readinterval: 10
2020-07-05 18:51:51,953 INFO     MainThread Setting PowerWall name: powerwall
2020-07-05 18:51:51,953 DEBUG    MainThread Setting PowerWall pubchannels: ['ToEmonCMS']
2020-07-05 18:51:57,313 DEBUG    SerialTx   23 NEW FRAME : 14 7 0 0 0 25326 0
2020-07-05 18:51:57,314 DEBUG    SerialTx   23 Timestamp : 1593971517.31
2020-07-05 18:51:57,315 DEBUG    SerialTx   23 From Node : 14
2020-07-05 18:51:57,315 DEBUG    SerialTx   23    Values : [7, 0, 0, 0, 253.26000000000002, 0]
2020-07-05 18:51:57,315 DEBUG    SerialTx   23 Sent to channel(start)' : ToEmonCMS
2020-07-05 18:51:57,316 DEBUG    SerialTx   23 Sent to channel(end)' : ToEmonCMS
2020-07-05 18:51:57,518 DEBUG    MQTT       Publishing: emon/1phase_node14/powerL1 7
2020-07-05 18:51:57,519 DEBUG    MQTT       Publishing: emon/1phase_node14/powerL2 0
2020-07-05 18:51:57,520 DEBUG    MQTT       Publishing: emon/1phase_node14/powerL3 0
2020-07-05 18:51:57,522 DEBUG    MQTT       Publishing: emon/1phase_node14/power4 0
2020-07-05 18:51:57,523 DEBUG    MQTT       Publishing: emon/1phase_node14/Vrms 253.26
2020-07-05 18:51:57,524 DEBUG    MQTT       Publishing: emon/1phase_node14/temp1 0
2020-07-05 18:52:02,030 WARNING  PowerWall  Exception caught in PowerWall thread. Traceback (most recent call last):
  File "/home/pi/emonhub/src/emonhub_interfacer.py", line 40, in wrapper
    return f(*args)
  File "/home/pi/emonhub/src/emonhub_interfacer.py", line 102, in run
    rxc = self.read()
  File "/home/pi/emonhub/src/interfacers/EmonHubTeslaPowerWallInterfacer.py", line 46, in read
    except urllib2.HTTPError as e:
NameError: global name 'urllib2' is not defined

We’re being strangled by bloody pythons! :slight_smile:

Only what is in the master branch until #119 is fixed

Incidentally, my emonpi doesn’t use the /opt structure either. Which SD image introduced that?

The latest one. Keeping things in home was causing issues so when the emonScripts were created, the whole directory structure was changed. It is only emonhub that actually gets migrated though I think.

1 Like

Well that explains why I couldn’t find urllib :angry:.

@johnbanks, I think I led you down the garden path - sorry.

try copying back the original file, deleting the other file then

git -C  /opt/openenergymonitor/emonhub checkout master

It might complain about unstaged changes.

restart emonhub.

Bruce, I think what is in the original commit for TLS, are changes made to the Python2 code, that you didn’t pick up as that commit refers to urllib2 and not requests.

There does not seem to be a corresponding line to this in the python3 code.

Oh.

Well that’s disappointing. It looks like Tesla are providing an HTTPS server with a self-signed certificate. If that’s the case, you can replicate this error:

import requests
requests.get('https://self-signed.badssl.com/')

Obviously the fix is for the PowerWall to provide a valid certificate.

Incidentally, the conf that was posted says

url = http:/192.168.1.140/api/system_status/soe

Which is missing the double slash. Requests will refuse to work with this. Either this was edited before it was posted or we haven’t seen the error message that goes with it.

Given that it would be a bit odd for Tesla to redirect an http request to a broken https server, I suggest we fix that URL and be certain what code we’re running before we go looking for workarounds.

@bwduncan, there was some testing above on this. Can requests replicate this or does it need urllib?