Coder Social home page Coder Social logo

Comments (6)

fabian-lauer avatar fabian-lauer commented on July 28, 2024

HI @mpolak77 ,

thanks for the feedback - I agree, error handling is not the best - had a similar problem a few weeks ago.
But unfortunately I am missing a little bit of time to do so....

Would be happy for some support - proposals, code-snippets, etc..

Thx

from dbus-shelly-3em-smartmeter.

mpolak77 avatar mpolak77 commented on July 28, 2024

Here a first attempt which seems to work, and also prints exceptions more readable:

--- dbus-shelly-3em-smartmeter-master.py
+++ dbus-shelly-3em-smartmeter.py
@@ -104,7 +104,7 @@
  
   def _getShellyData(self):
     URL = self._getShellyStatusUrl()
-    meter_r = requests.get(url = URL)
+    meter_r = requests.get(url = URL, timeout=5)
     
     # check for response
     if not meter_r:
      
@@ -158,14 +156,20 @@
        logging.debug("House Reverse (/Ac/Energy/Revers): %s" % (self._dbusservice['/Ac/Energy/Reverse']))
        logging.debug("---");
        
-       # increment UpdateIndex - to show that new data is available
-       index = self._dbusservice['/UpdateIndex'] + 1  # increment index
-       if index > 255:   # maximum value of the index
-         index = 0       # overflow from 255 to 0
-       self._dbusservice['/UpdateIndex'] = index
+       # increment UpdateIndex - to show that new data is available an wrap
+       self._dbusservice['/UpdateIndex'] = (self._dbusservice['/UpdateIndex'] + 1 ) % 256
 
        #update lastupdate vars
        self._lastUpdate = time.time()              
+ 
+    except (ValueError, requests.exceptions.ConnectionError, requests.exceptions.Timeout, ConnectionError):
+       logging.critical('Error getting data from Shelly - check network or Shelly status. Setting power values to 0')
+       self._dbusservice['/Ac/L1/Power'] = 0                                       
+       self._dbusservice['/Ac/L2/Power'] = 0                                       
+       self._dbusservice['/Ac/L3/Power'] = 0
+       self._dbusservice['/Ac/Power'] = 0
+       self._dbusservice['/UpdateIndex'] = (self._dbusservice['/UpdateIndex'] + 1 ) % 256                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
+             
     except Exception as e:
        logging.critical('Error at %s', '_update', exc_info=e)
        
@@ -233,7 +237,12 @@
       logging.info('Connected to dbus, and switching over to gobject.MainLoop() (= event based)')
       mainloop = gobject.MainLoop()
       mainloop.run()            
+   
+  except (ValueError, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
+    logging.critical('Error in main type %s', str(e))
+
   except Exception as e:
     logging.critical('Error at %s', 'main', exc_info=e)
+
 if __name__ == "__main__"
```:

from dbus-shelly-3em-smartmeter.

mascheihei avatar mascheihei commented on July 28, 2024

@mpolak77 Good idea, but only works if the gridpower set point is 0 Watt. It would be better to set it to "/Settings/Cgwacs/AcPowerSetPoint". Then it is aligned to target of ESS control loop.
Another point: If the json decoding fails -> is this catched by ValueError? or should we add requests.exceptions.JSONDecodeError

from dbus-shelly-3em-smartmeter.

mpolak77 avatar mpolak77 commented on July 28, 2024

Good point - just realized that Multiplus starts to charge, if SetPoiint is >0 and Meter reads 0 ….
Now I need to find out, how to do this correctly depending on 1phase vs all phase Saldo mode.

from dbus-shelly-3em-smartmeter.

fabian-lauer avatar fabian-lauer commented on July 28, 2024

@mpolak77 thank you for your input - will add that to the next commit

from dbus-shelly-3em-smartmeter.

fabian-lauer avatar fabian-lauer commented on July 28, 2024

Should be all in now.
Thanks for the input

from dbus-shelly-3em-smartmeter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.