Jump to content

Battery Level for Open Z-Wave Devices with the help of Python Wrapper

Recommended Posts

Picking a Z-Wave controller can be troublesome, they all do similar things, where as in distinct ways. So it's an exceptionally subjective choice - relying upon the client's needs. This guide is our endeavor to clarify what I comprehend from the exploration is there isn't yet a repository for plugins that are written for the Beta Python plugin framework, so I am posting this in the discussion on the off chance that it can be useful to a few clients... 


What is the functionality of an Controller? 


The controller also known as hub or gateway, that controls your Z-Wave system. It allows adding and configuring the devices and to make and run 'scenes' that enable the system to do things naturally, to quote an example, turning on lights in based on the of motion or time. The controller additionally permits remote access by means of the Internet or cell phone notwithstanding when you are far from home. 

And justifying the topic, Fiblary is a Python module wrapping Fibaro Home Center REST API. This permits Python Programs to make calls straightforwardly to Home Center and control the Z-wave gadgets and run scenes oversaw by HC. It additionally gives access and strategies to factors, clients, room and sections characterized on Home Center. 

It's simple to get some essential data about the Home Center: 

from fiblary.client import Client

# Connect to Home Center
hc = Client('v3', '', 'admin', 'admin')
# Retrieve the basic info as returned by /api/info
info = hc.info.get()


will produce the similar output as below:

{u'batteryLowNotification': True, u'temperatureUnit': u'C', u'updateStableAvailable': False, u'sunsetHour': u'16:29',
u'softVersion': u'3.580', u'newestBetaVersion': u'3.581', u'serialNumber': u'HC2-000666', u'sunriseHour': u'07:24',
u'beta': False, u'defaultLanguage': u'pl', u'mac': u'38:60:77:92:bf:a5', u'serverStatus': 1390148753, u'hotelMode': True,
u'updateBetaAvailable': True, u'zwaveVersion': u'3.42'}

The returned info behaves like a dictionary:


print info['softVersion']


but also like a property:

print info.softVersion


That's Easy, right?

For the managers that Client supports the full set of options is implemented.

# put this in a file named custom_components/battery_state.py
import logging
from homeassistant.helpers.event import track_state_change
from homeassistant.const import STATE_ON, STATE_OFF, STATE_HOME, STATE_NOT_HOME, MATCH_ALL

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'battery'

def setup(hass, config=None):
    """Setup the Battery component. """
    _LOGGER.info("The 'battery' component is ready!")
    def state_changed(entity_id, old_state, new_state):
        if new_state is None:
        if 'battery_level' in new_state.attributes:
            hass.states.set('%s_battery' % entity_id,
                                'friendly_name': "%s Battery" % new_state.attributes['friendly_name'],
                                'unit_of_measurement': '%',
                                'icon': 'mdi:battery'

    track_state_change(hass, MATCH_ALL, state_changed)

    return True


Warning: This makes another battery sensor for each sensor it recognizes, so you may wind up with multiple battery sensors per gadget if that gadget reports various sensors. 

Alter for establishment directions: 

Save the above content as custom_components/battery_state.py and make the custom_components catalog on the off chance that it doesn't as of now exist 

Include battery_state: to your configuration.yaml to empower the component.


You can get more information from support on the google group: http://groups.google.com/d/forum/python-openzwave-discuss.

Source: Domoticz / Github


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...