python-mystrom


Namepython-mystrom JSON
Version 2.2.0 PyPI version JSON
download
home_pagehttps://github.com/home-assistant-ecosystem/python-mystrom
SummaryAsynchronous Python API client for interacting with myStrom devices
upload_time2023-05-21 18:50:24
maintainer
docs_urlNone
authorFabian Affolter
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            python-mystrom |License| |PyPI|
===================================

Asynchronous Python API client for interacting with `myStrom <https://mystrom.ch>`_
devices.

This module is not official, developed, supported or endorsed by myStrom AG.
For questions and other inquiries, use the issue tracker in this repo please.

Without the support of myStrom AG it would have taken much longer to create
this module which is the base for the integration into
`Home Assistant <https://home-assistant.io>`_. myStrom AG has provided hardware.
Their continuous support make further development of this module possible.

Requirements
------------

You need to have `Python <https://www.python.org>`_ installed.

- `myStrom <https://mystrom.ch>`_ device (bulb, plug or button)
- The ``python-mystrom`` requirements
- Network connection
- Devices connected to your network

Installation
------------

The package is available in the `Python Package Index <https://pypi.python.org/>`_ .

.. code:: bash

    $ pip3 install python-mystrom

On a Fedora-based system or on a CentOS/RHEL machine which has EPEL enabled.

.. code:: bash

    $ sudo dnf -y install python3-mystrom

For Nix or NixOS users is a package available. Keep in mind that the lastest releases might only
be present in the ``unstable`` channel.

.. code:: bash

    $ nix-env -iA nixos.python3Packages.python-mystrom


Plug/switch
-----------

At the moment the following endpoints are covered according `https://api.mystrom.ch <https://api.mystrom.ch>`_:

- ``/report``: for getting the current state and the power consumption
- ``/relay``: for setting the relay state

You will still be able to use your device with the smartphone application,
``curl`` or other tools. The samples below shows how to use the switch with
``httpie`` and ``curl`` along with ``python-mystrom``.

.. code:: bash

    $ http http://IP_ADDRESS_PLUG/report
    HTTP/1.1 200 OK
    Content-Length: 39
    Content-Type: application/json
    Date: Mon, 15 Feb 2016 17:52:21 GMT

    {
        "power": 51.630947,
        "relay": true
    }

.. code:: bash

    $ curl -X GET http://IP_ADDRESS_PLUG/relay?state=1


Bulb
----

If the bulb is on then you should be able to retrieve the current state of
the bulb.

Browse to http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB or use a
command-line tool.

.. code:: bash

    $ curl -d "color=0;0;100" -d "action=on" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
    {
	"5DFF7FAHZ987": 	{
		"on": true,
		"color": "0;0;100",
		"mode": "hsv",
		"ramp": 100,
		"notifyurl": ""
	    }
    }

The bulbs are not able to handle payload formatted as JSON. It's required to
use ``application/x-www-form-urlencoded``. Keep that in mind if something is
not working, especially around setting the color with HSV.

If you are planning to use your bulbs with `Home Assistant <https://home-assistant.io>`_
set the bulb to a state from `Colors` with the app or use the command below.

.. code:: bash

    $ curl -d "color=0;0;100" IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB


Set State
`````````

You can set the state with a POST request and a payload.

- **on**: ``curl -d "action=on" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
- **off**:  ``curl -d "action=off" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
- **toggle**: ``$ curl -d "action=toggle" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``

Set Color RGB
`````````````

One of the supported modes for setting the color is **RBG**.

- **white**: ``$ curl -d "color=FF000000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
- **red**: ``$ curl -d "color=00FF0000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
- **green**: ``$ curl -d "color=0000FF00" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
- **blue**: ``$ curl -d "color=000000FF" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``

Set Color HSV (Hue, Saturation, Value)
``````````````````````````````````````

It's also possible to use **HSV**.

.. code:: bash

    $ curl -d "color=0;0;100" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB

While "color=" is composed with hue, saturation, and value.

Set Mono (white)
````````````````

If you only want to set the "white" color of the bulb, use **mono**.

.. code:: bash

    $ curl -d "color=10;100" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB

"color=" contains the value for the color temperature (from 1 to 18) and the
brightness (from 0 to 100).

Dimming (ramp)
``````````````

Add **ramp** and an interval to set up the transition time while changing
colors.

.. code:: bash

    $ curl -d "action=on&ramp=1000&color=00FF0000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB

The unit of measurement for ramp is milliseconds (ms).

Button
------

The buttons can be set with the myStrom app or directly via HTTP requests.

To set the configuration the payload must contains the relevant details for
the actions:

``$ curl -v -d "single=<url>&double=<url>&long=<url>&touch=<url>" http://IP_ADDRESS_BUTTON/api/v1/device/MAC_ADDRESS_BUTTON``

Available actions:

- **single**: Short push (approx. 1/2 seconds)
- **double**: 2x sequential short pushes (within 2 seconds)
- **long**: Long push (approx. 2 seconds)
- **touch**: Touch of the button's surface (only affective for the WiFi
  Button +)

The button is set up to extend the life span of the battery as much as
possible. This means that only within the first 3 minutes or when connected
to an USB port/USB charger and the battery is not full, the button is able
to receive configuration information or publish its details.

``mystrom`` helper tool
-----------------------

The command-line tool ``mystrom`` can help to set up the buttons and get the
details from bulbs and plugs.

.. code:: bash

   $ mystrom
   Usage: mystrom [OPTIONS] COMMAND [ARGS]...

     Simple command-line tool to get and set the values of a myStrom devices.

     This tool can set the targets of a myStrom button for the different
     available actions single, double, long and touch.

   Options:
     --version  Show the version and exit.
     --help     Show this message and exit.

   Commands:
     bulb    Get and set details of a myStrom bulb.
     button  Get and set details of a myStrom button.
     config  Get and set the configuration of a myStrom...

The examples shows how to get the details of a given bulb.

.. code:: bash

   $ mystrom config read
   IP address of the myStrom device: IP_ADDRESS_BULB
   MAC address of the device: MAC_ADDRESS_BULB
   Read configuration from IP_ADDRESS_BULB
   {
      'MAC_ADDRESS_BULB':{
         'type':'rgblamp',
         'battery':False,
         'reachable':True,
         'meshroot':False,
         'on':True,
         'color':'191;90;14',
         'mode':'hsv',
         'ramp':100,
         'power':0.953,
         'fw_version':'2.25'
      }
   }

Example usage of the module
---------------------------

Examples for the bulb can be found in the directory ``examples``.

License
-------

``python-mystrom`` is licensed under MIT, for more details check LICENSE.

.. |License| image:: https://img.shields.io/badge/License-MIT-green.svg
   :target: https://pypi.python.org/pypi/python-mystrom
   :alt: License

.. |PyPI| image:: https://img.shields.io/pypi/v/python-mystrom.svg
   :target: https://pypi.python.org/pypi/python-mystrom
   :alt: PyPI release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/home-assistant-ecosystem/python-mystrom",
    "name": "python-mystrom",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fabian Affolter",
    "author_email": "fabian@affolter-engineering.ch",
    "download_url": "https://files.pythonhosted.org/packages/94/18/76754f29de8b40b1172548c68932c19a9fe09258be52ced6b9f74b109db6/python-mystrom-2.2.0.tar.gz",
    "platform": null,
    "description": "python-mystrom |License| |PyPI|\n===================================\n\nAsynchronous Python API client for interacting with `myStrom <https://mystrom.ch>`_\ndevices.\n\nThis module is not official, developed, supported or endorsed by myStrom AG.\nFor questions and other inquiries, use the issue tracker in this repo please.\n\nWithout the support of myStrom AG it would have taken much longer to create\nthis module which is the base for the integration into\n`Home Assistant <https://home-assistant.io>`_. myStrom AG has provided hardware.\nTheir continuous support make further development of this module possible.\n\nRequirements\n------------\n\nYou need to have `Python <https://www.python.org>`_ installed.\n\n- `myStrom <https://mystrom.ch>`_ device (bulb, plug or button)\n- The ``python-mystrom`` requirements\n- Network connection\n- Devices connected to your network\n\nInstallation\n------------\n\nThe package is available in the `Python Package Index <https://pypi.python.org/>`_ .\n\n.. code:: bash\n\n    $ pip3 install python-mystrom\n\nOn a Fedora-based system or on a CentOS/RHEL machine which has EPEL enabled.\n\n.. code:: bash\n\n    $ sudo dnf -y install python3-mystrom\n\nFor Nix or NixOS users is a package available. Keep in mind that the lastest releases might only\nbe present in the ``unstable`` channel.\n\n.. code:: bash\n\n    $ nix-env -iA nixos.python3Packages.python-mystrom\n\n\nPlug/switch\n-----------\n\nAt the moment the following endpoints are covered according `https://api.mystrom.ch <https://api.mystrom.ch>`_:\n\n- ``/report``: for getting the current state and the power consumption\n- ``/relay``: for setting the relay state\n\nYou will still be able to use your device with the smartphone application,\n``curl`` or other tools. The samples below shows how to use the switch with\n``httpie`` and ``curl`` along with ``python-mystrom``.\n\n.. code:: bash\n\n    $ http http://IP_ADDRESS_PLUG/report\n    HTTP/1.1 200 OK\n    Content-Length: 39\n    Content-Type: application/json\n    Date: Mon, 15 Feb 2016 17:52:21 GMT\n\n    {\n        \"power\": 51.630947,\n        \"relay\": true\n    }\n\n.. code:: bash\n\n    $ curl -X GET http://IP_ADDRESS_PLUG/relay?state=1\n\n\nBulb\n----\n\nIf the bulb is on then you should be able to retrieve the current state of\nthe bulb.\n\nBrowse to http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB or use a\ncommand-line tool.\n\n.. code:: bash\n\n    $ curl -d \"color=0;0;100\" -d \"action=on\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB\n    {\n\t\"5DFF7FAHZ987\": \t{\n\t\t\"on\": true,\n\t\t\"color\": \"0;0;100\",\n\t\t\"mode\": \"hsv\",\n\t\t\"ramp\": 100,\n\t\t\"notifyurl\": \"\"\n\t    }\n    }\n\nThe bulbs are not able to handle payload formatted as JSON. It's required to\nuse ``application/x-www-form-urlencoded``. Keep that in mind if something is\nnot working, especially around setting the color with HSV.\n\nIf you are planning to use your bulbs with `Home Assistant <https://home-assistant.io>`_\nset the bulb to a state from `Colors` with the app or use the command below.\n\n.. code:: bash\n\n    $ curl -d \"color=0;0;100\" IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB\n\n\nSet State\n`````````\n\nYou can set the state with a POST request and a payload.\n\n- **on**: ``curl -d \"action=on\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n- **off**:  ``curl -d \"action=off\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n- **toggle**: ``$ curl -d \"action=toggle\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n\nSet Color RGB\n`````````````\n\nOne of the supported modes for setting the color is **RBG**.\n\n- **white**: ``$ curl -d \"color=FF000000\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n- **red**: ``$ curl -d \"color=00FF0000\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n- **green**: ``$ curl -d \"color=0000FF00\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n- **blue**: ``$ curl -d \"color=000000FF\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``\n\nSet Color HSV (Hue, Saturation, Value)\n``````````````````````````````````````\n\nIt's also possible to use **HSV**.\n\n.. code:: bash\n\n    $ curl -d \"color=0;0;100\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB\n\nWhile \"color=\" is composed with hue, saturation, and value.\n\nSet Mono (white)\n````````````````\n\nIf you only want to set the \"white\" color of the bulb, use **mono**.\n\n.. code:: bash\n\n    $ curl -d \"color=10;100\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB\n\n\"color=\" contains the value for the color temperature (from 1 to 18) and the\nbrightness (from 0 to 100).\n\nDimming (ramp)\n``````````````\n\nAdd **ramp** and an interval to set up the transition time while changing\ncolors.\n\n.. code:: bash\n\n    $ curl -d \"action=on&ramp=1000&color=00FF0000\" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB\n\nThe unit of measurement for ramp is milliseconds (ms).\n\nButton\n------\n\nThe buttons can be set with the myStrom app or directly via HTTP requests.\n\nTo set the configuration the payload must contains the relevant details for\nthe actions:\n\n``$ curl -v -d \"single=<url>&double=<url>&long=<url>&touch=<url>\" http://IP_ADDRESS_BUTTON/api/v1/device/MAC_ADDRESS_BUTTON``\n\nAvailable actions:\n\n- **single**: Short push (approx. 1/2 seconds)\n- **double**: 2x sequential short pushes (within 2 seconds)\n- **long**: Long push (approx. 2 seconds)\n- **touch**: Touch of the button's surface (only affective for the WiFi\n  Button +)\n\nThe button is set up to extend the life span of the battery as much as\npossible. This means that only within the first 3 minutes or when connected\nto an USB port/USB charger and the battery is not full, the button is able\nto receive configuration information or publish its details.\n\n``mystrom`` helper tool\n-----------------------\n\nThe command-line tool ``mystrom`` can help to set up the buttons and get the\ndetails from bulbs and plugs.\n\n.. code:: bash\n\n   $ mystrom\n   Usage: mystrom [OPTIONS] COMMAND [ARGS]...\n\n     Simple command-line tool to get and set the values of a myStrom devices.\n\n     This tool can set the targets of a myStrom button for the different\n     available actions single, double, long and touch.\n\n   Options:\n     --version  Show the version and exit.\n     --help     Show this message and exit.\n\n   Commands:\n     bulb    Get and set details of a myStrom bulb.\n     button  Get and set details of a myStrom button.\n     config  Get and set the configuration of a myStrom...\n\nThe examples shows how to get the details of a given bulb.\n\n.. code:: bash\n\n   $ mystrom config read\n   IP address of the myStrom device: IP_ADDRESS_BULB\n   MAC address of the device: MAC_ADDRESS_BULB\n   Read configuration from IP_ADDRESS_BULB\n   {\n      'MAC_ADDRESS_BULB':{\n         'type':'rgblamp',\n         'battery':False,\n         'reachable':True,\n         'meshroot':False,\n         'on':True,\n         'color':'191;90;14',\n         'mode':'hsv',\n         'ramp':100,\n         'power':0.953,\n         'fw_version':'2.25'\n      }\n   }\n\nExample usage of the module\n---------------------------\n\nExamples for the bulb can be found in the directory ``examples``.\n\nLicense\n-------\n\n``python-mystrom`` is licensed under MIT, for more details check LICENSE.\n\n.. |License| image:: https://img.shields.io/badge/License-MIT-green.svg\n   :target: https://pypi.python.org/pypi/python-mystrom\n   :alt: License\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/python-mystrom.svg\n   :target: https://pypi.python.org/pypi/python-mystrom\n   :alt: PyPI release\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous Python API client for interacting with myStrom devices",
    "version": "2.2.0",
    "project_urls": {
        "Homepage": "https://github.com/home-assistant-ecosystem/python-mystrom"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "941876754f29de8b40b1172548c68932c19a9fe09258be52ced6b9f74b109db6",
                "md5": "b56b2ed0f841dc559d80c128115b3bbb",
                "sha256": "545b1303f8ac070d07eea5d084e5fa2b6a7541c5713bbab94c8cdff188af5607"
            },
            "downloads": -1,
            "filename": "python-mystrom-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b56b2ed0f841dc559d80c128115b3bbb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 16427,
            "upload_time": "2023-05-21T18:50:24",
            "upload_time_iso_8601": "2023-05-21T18:50:24.437255Z",
            "url": "https://files.pythonhosted.org/packages/94/18/76754f29de8b40b1172548c68932c19a9fe09258be52ced6b9f74b109db6/python-mystrom-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-21 18:50:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "home-assistant-ecosystem",
    "github_project": "python-mystrom",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "python-mystrom"
}
        
Elapsed time: 0.14464s