aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--ShellyPy/gen1.py9
-rw-r--r--examples/meter.py17
-rw-r--r--examples/toggle_relay.py2
4 files changed, 42 insertions, 6 deletions
diff --git a/README.md b/README.md
index 7e844d6..b105dfc 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,9 @@ Python 2 and 3 Wrapper around the Shelly HTTP api
other packages like [pyShelly](https://github.com/StyraHem/pyShelly) only support CoAP or MSQT, neither I am comfortable with using in personal projects
-## example
-here is a simple working example for the Shelly 1 that turns a relay on
+## examples
+#### relay
+a simple working example for the Shelly 1 that turns a relay on
```python
import ShellyPy
@@ -16,7 +17,20 @@ device = ShellyPy.Shelly("192.168.0.5")
device.relay(0, turn=True)
```
-this example with comments can be found on [examples/toggle_relay.py](examples/toggle_relay.py)
+[examples/toggle_relay.py](examples/toggle_relay.py)
+
+#### monitor
+a simple working example for the Shelly 1 that request monitor information
+```python
+import ShellyPy
+
+device = ShellyPy.Shelly("192.168.68.121")
+
+deviceMeter = device.meter(0) #request meter information
+print(deviceMeter['power']) #print power information
+print(deviceMeter['total']) #print total information
+```
+other examples are available as well [examples/meter.py](examples/meter.py)
## devices
#### supported
diff --git a/ShellyPy/gen1.py b/ShellyPy/gen1.py
index de4a00f..13e9c2d 100644
--- a/ShellyPy/gen1.py
+++ b/ShellyPy/gen1.py
@@ -17,7 +17,7 @@ class ShellyGen1(ShellyBase):
def __init__(self, ip, port = "80", *args, **kwargs):
"""
@param ip the target IP of the shelly device. Can be a string, list of strings or list of integers
- @param port target port, may be useful for non Shelly devices that have the same HTTP Api
+ @param port target port, may be useful for non Shelly devices that have the same HTTP Api
@param login dict of login credentials. Keys needed are "username" and "password"
@param timeout specify the amount of time until requests are aborted.
@param debug enable debug printing
@@ -27,9 +27,11 @@ class ShellyGen1(ShellyBase):
super().__init__(ip, port, *args, **kwargs)
self.__generation__ = 1
- def update(self):
+ def update(self, index = 0):
"""
@brief update the Shelly attributes
+
+ @param index index of the relay
"""
status = self.settings()
@@ -46,6 +48,9 @@ class ShellyGen1(ShellyBase):
self.emeters = status.get("emeter", [])
+ # Request meter information
+ self.meter = self.meter(index)
+
def post(self, page, values = None):
"""
@brief returns settings
diff --git a/examples/meter.py b/examples/meter.py
new file mode 100644
index 0000000..757b4f6
--- /dev/null
+++ b/examples/meter.py
@@ -0,0 +1,17 @@
+import ShellyPy
+
+# try connecting to the Shelly device under that ip
+device = ShellyPy.Shelly("192.168.68.121")
+# WILL throw an exception if the device is not reachable, gives a bad response or requires a login
+
+deviceMeter = device.meter(0) #request meter information
+print(deviceMeter['power']) #print power information
+print(deviceMeter['overpower']) #print overpower information
+print(deviceMeter['is_valid']) #print is_valid information
+print(deviceMeter['timestamp']) #print timestamp information
+print(deviceMeter['counters']) #print counters information
+print(deviceMeter['total']) #print total information
+
+device.update()
+print(device)
+
diff --git a/examples/toggle_relay.py b/examples/toggle_relay.py
index a2e10a5..6b667fe 100644
--- a/examples/toggle_relay.py
+++ b/examples/toggle_relay.py
@@ -5,6 +5,6 @@ device = ShellyPy.Shelly("192.168.0.5")
# WILL throw an exception if the device is not reachable, gives a bad response or requires a login
device.relay(0, turn=True) # turn the relay at index 0 on
-device.relay(0, turn=False) # same as bove but turn it off
+device.relay(0, turn=False) # same as above but turn it off
device.relay(0, turn=True, delay=3) # turn the relay 0 on for 3 seconds then off
# most shelly devices only have 1 or 2 relays