Jan200101 / ShellyPy

Python library to interact with Shelly devices
MIT License
22 stars 14 forks source link

Support for Shelly Plus Add-On #15

Open masterpo88 opened 1 year ago

masterpo88 commented 1 year ago

I just started using ShellyPy to control my hot water heater. I need to add temperature sensing to managing the solar heat exchanger. I have purchased a Shelly Plus Add-On to add to the Shelly Plus 1 UL that I am using to control the resistive heating element of the hot water heater from an RPI3 over my local network. The RPI3 monitors a Tesla Powerwall and controls a pool pump motor. I am a novice Python programmer and a retired electrical/systems engineer. I have never developed software for production release and would like some suggestions to help me get started on adding the temperature sensor capability to ShellyPy or the best way I can help implement this addition.

Jan200101 commented 1 year ago

Hey,

the best start would be to look at the documentation.

Shelly Plus 1 is a Gen 2 device for which the documentation can be found here: https://shelly-api-docs.shelly.cloud/gen2/

Since you are using an Addon I assume the correct page would be https://shelly-api-docs.shelly.cloud/gen2/Addons/ShellySensorAddon

Gen 2 Shelly Devices (also called Shelly-NG) are controlled via JSON-RPC 2.0 (specification) through HTTP

The documentation tends to have examples using a normal HTTP get method, using curl and using mos so you can poke the API to see what kind of responses you receive

There are also some tools around that make sending these a bit easier


In regards to contributions the released version of ShellyPy is a bit of a mess and initially designed around the Gen 1 devices so things may be a bit rocky.

The relevant code for Gen 2 devices is in ShellyPy/gen2.py, you will have to add a new function that calls the appropriate method.

Requests are made using self.post(method, params) which is then directly turned into JSON-RPC and send to the device so, for example

self.post("Switch.Set", {"id: 0, "on": True})

would turn the switch on. The relay and roller functions may be helpful to reference

I sadly don't own a Shelly Addon, so I can't help a whole lot.

masterpo88 commented 1 year ago

Thanks for the suggestions. I've already started looking at the documentation. It will take a few more passes to understand. The addon looks to be an extension of the plus 1 and might just show up in the status like the switch does. Just received the addon so I should know something soon.

On Sat, Sep 30, 2023, 04:20 Jan @.***> wrote:

Hey,

the best start would be to look at the documentation.

Shelly Plus 1 is a Gen 2 device for which the documentation can be found here: https://shelly-api-docs.shelly.cloud/gen2/

Since you are using an Addon I assume the correct page would be https://shelly-api-docs.shelly.cloud/gen2/Addons/ShellySensorAddon

Gen 2 Shelly Devices (also called Shelly-NG) are controlled via JSON-RPC 2.0 (specification https://www.jsonrpc.org/specification) through HTTP

The documentation tends to have examples using a normal HTTP get method, using curl and using mos so you can poke the API to see what kind of responses you receive

There are also some tools around that make sending these a bit easier


In regards to contributions the released version of ShellyPy is a bit of a mess and initially designed around the Gen 1 devices so things may be a bit rocky.

The relevant code for Gen 2 devices is in ShellyPy/gen2.py https://github.com/Jan200101/ShellyPy/blob/master/ShellyPy/gen2.py, you will have to add a new function that calls the appropriate method.

Requests are made using self.post(method, params) which is then directly turned into JSON-RPC and send to the device so, for example

self.post("Switch.Set", {"id: 0, "on": True})

would turn the switch on. The relay and roller functions may be helpful to reference

I sadly don't own a Shelly Addon, so I can't help a whole lot.

— Reply to this email directly, view it on GitHub https://github.com/Jan200101/ShellyPy/issues/15#issuecomment-1741743889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMRZRKEWDKDL6OMX4LJTXMDX4756ZANCNFSM6AAAAAA5MYMOKA . You are receiving this because you authored the thread.Message ID: @.***>

masterpo88 commented 1 year ago

Once the addon was attached, enabled and configured on the local shelly plus one website and using the example on

https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Temperature

I entered http://192.168.0.53/rpc/Temperature.GetStatus?id=100 on the rpi3 browser which returned {"id": 100, "tC":37.3, "tF":99.2}

ids 100 through 104 were assigned to the 5 DS18B20 temperature sensors attached to the addon

Now the hard part for me... figure out how to add this to ShellyPy.......

On Sat, Sep 30, 2023 at 8:32 AM Mark Eidson @.***> wrote:

Thanks for the suggestions. I've already started looking at the documentation. It will take a few more passes to understand. The addon looks to be an extension of the plus 1 and might just show up in the status like the switch does. Just received the addon so I should know something soon.

On Sat, Sep 30, 2023, 04:20 Jan @.***> wrote:

Hey,

the best start would be to look at the documentation.

Shelly Plus 1 is a Gen 2 device for which the documentation can be found here: https://shelly-api-docs.shelly.cloud/gen2/

Since you are using an Addon I assume the correct page would be https://shelly-api-docs.shelly.cloud/gen2/Addons/ShellySensorAddon

Gen 2 Shelly Devices (also called Shelly-NG) are controlled via JSON-RPC 2.0 (specification https://www.jsonrpc.org/specification) through HTTP

The documentation tends to have examples using a normal HTTP get method, using curl and using mos so you can poke the API to see what kind of responses you receive

There are also some tools around that make sending these a bit easier


In regards to contributions the released version of ShellyPy is a bit of a mess and initially designed around the Gen 1 devices so things may be a bit rocky.

The relevant code for Gen 2 devices is in ShellyPy/gen2.py https://github.com/Jan200101/ShellyPy/blob/master/ShellyPy/gen2.py, you will have to add a new function that calls the appropriate method.

Requests are made using self.post(method, params) which is then directly turned into JSON-RPC and send to the device so, for example

self.post("Switch.Set", {"id: 0, "on": True})

would turn the switch on. The relay and roller functions may be helpful to reference

I sadly don't own a Shelly Addon, so I can't help a whole lot.

— Reply to this email directly, view it on GitHub https://github.com/Jan200101/ShellyPy/issues/15#issuecomment-1741743889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMRZRKEWDKDL6OMX4LJTXMDX4756ZANCNFSM6AAAAAA5MYMOKA . You are receiving this because you authored the thread.Message ID: @.***>

masterpo88 commented 1 year ago

Hi Jan, At this stage of my life I do not have the energy to make any sense out of the ShellyPy code or to add addon functionality. However, in the process of trying I developed the following python script that performs the function I needed, maybe that will help someone else to add it to ShellyPy. Thanks, me.

On Sat, Sep 30, 2023 at 5:14 PM Mark Eidson @.***> wrote:

Once the addon was attached, enabled and configured on the local shelly plus one website and using the example on

https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Temperature

I entered http://192.168.0.53/rpc/Temperature.GetStatus?id=100 on the rpi3 browser which returned {"id": 100, "tC":37.3, "tF":99.2}

ids 100 through 104 were assigned to the 5 DS18B20 temperature sensors attached to the addon

Now the hard part for me... figure out how to add this to ShellyPy.......

On Sat, Sep 30, 2023 at 8:32 AM Mark Eidson @.***> wrote:

Thanks for the suggestions. I've already started looking at the documentation. It will take a few more passes to understand. The addon looks to be an extension of the plus 1 and might just show up in the status like the switch does. Just received the addon so I should know something soon.

On Sat, Sep 30, 2023, 04:20 Jan @.***> wrote:

Hey,

the best start would be to look at the documentation.

Shelly Plus 1 is a Gen 2 device for which the documentation can be found here: https://shelly-api-docs.shelly.cloud/gen2/

Since you are using an Addon I assume the correct page would be https://shelly-api-docs.shelly.cloud/gen2/Addons/ShellySensorAddon

Gen 2 Shelly Devices (also called Shelly-NG) are controlled via JSON-RPC 2.0 (specification https://www.jsonrpc.org/specification) through HTTP

The documentation tends to have examples using a normal HTTP get method, using curl and using mos so you can poke the API to see what kind of responses you receive

There are also some tools around that make sending these a bit easier


In regards to contributions the released version of ShellyPy is a bit of a mess and initially designed around the Gen 1 devices so things may be a bit rocky.

The relevant code for Gen 2 devices is in ShellyPy/gen2.py https://github.com/Jan200101/ShellyPy/blob/master/ShellyPy/gen2.py, you will have to add a new function that calls the appropriate method.

Requests are made using self.post(method, params) which is then directly turned into JSON-RPC and send to the device so, for example

self.post("Switch.Set", {"id: 0, "on": True})

would turn the switch on. The relay and roller functions may be helpful to reference

I sadly don't own a Shelly Addon, so I can't help a whole lot.

— Reply to this email directly, view it on GitHub https://github.com/Jan200101/ShellyPy/issues/15#issuecomment-1741743889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMRZRKEWDKDL6OMX4LJTXMDX4756ZANCNFSM6AAAAAA5MYMOKA . You are receiving this because you authored the thread.Message ID: @.***>