maximvelichko / pyvera

A python library to control devices via the Vera hub
GNU General Public License v2.0
26 stars 31 forks source link

Remotes recognised within Home Assistant #97

Closed grantclem closed 6 years ago

grantclem commented 6 years ago

As it currently stands there appears to be no support for the use of Z- Wave “remote controllers” in HA via Vera. As an example I can use the Aeotec Minimote and create automations through HA, because it is recognised as a sensor. With the Fibaro KeyFob, it is not recognised at all… this means i have to create scenes on Vera for it to work, which is not ideal.

My intentions with my VeraPlus hub is for it to be used solely as a Z-Wave hub and nothing more. be751f81a6a9fd1cb4368c1e07d6f235ad3ae4a2

alanfischer commented 6 years ago

@grantclem I do not have a Fibaro KeyFob to test this with, but if you are willing to get some data for me, I could attempt a fix.

I'd need you to visit these 2 urls on your vera and send the result: http://your_vera_url:3480/data_request?id=sdata http://your_vera_url:3480/data_request?id=status

Thanks

grantclem commented 6 years ago

Hi Alan,

Thanks for making contact and having a look at this request for me - I have attached the requested files. Currently I have a minimote device that works fine and produces itself as a sensor within Home Asssistant. The states changes briefly when you push the buttons from either 1-9. Keyfob does not present itself in HA at all.

Regards

Grant

Happy to do any testing you require

On 27 Jul 2018, at 3:02 am, Alan Fischer notifications@github.com wrote:

@grantclem https://github.com/grantclem I do not have a Fibaro KeyFob to test this with, but if you are willing to get some data for me, I could attempt a fix.

I'd need you to visit these 2 urls on your vera and send the result: http://your_vera_url:3480/data_request?id=sdata http://your_vera_url:3480/data_request?id=status

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pavoni/pyvera/issues/97#issuecomment-408201487, or mute the thread https://github.com/notifications/unsubscribe-auth/AdLnQmwn0rejMO2BhyRlrLZDs74LXXMcks5uKhIvgaJpZM4VS_F1.

alanfischer commented 6 years ago

It looks like the files didn't attach.

grantclem commented 6 years ago

Hope this works?

On 27 Jul 2018, at 8:26 am, Alan Fischer notifications@github.com wrote:

It looks like the files didn't attach.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pavoni/pyvera/issues/97#issuecomment-408274840, or mute the thread https://github.com/notifications/unsubscribe-auth/AdLnQp79bGezzsJNt4v-2uku_cbK82h-ks5uKl5GgaJpZM4VS_F1.

grantclem commented 6 years ago

Zip version

On 27 Jul 2018, at 8:26 am, Alan Fischer notifications@github.com wrote:

It looks like the files didn't attach.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pavoni/pyvera/issues/97#issuecomment-408274840, or mute the thread https://github.com/notifications/unsubscribe-auth/AdLnQp79bGezzsJNt4v-2uku_cbK82h-ks5uKl5GgaJpZM4VS_F1.

alanfischer commented 6 years ago

Not seeing it. Please email them to alan.fischer@gmail.com

alanfischer commented 6 years ago

Ok, getting closer. If you could email me http://your_vera_url:3480/data_request?id=status with you pressing 1 button on one of the remotes, and then press a different button on the same remote and send http://your_vera_url:3480/data_request?id=status again I might be able to figure it out.

alanfischer commented 6 years ago

Ok, I have an experimental branch that may support remotes. Are you comfortable with git & python enough to run some commands I could give you to test it?

grantclem commented 6 years ago

Lol, never comfortable, but happy to try.

Sent from my iPhone

On 27 Jul 2018, at 10:53, Alan Fischer notifications@github.com wrote:

Ok, I have an experimental branch that may support remotes. Are you comfortable with git & python enough to run some commands I could give you to test it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

alanfischer commented 6 years ago

Fix merged in

grantclem commented 5 years ago

Hi all, Alan was working on this issue mid last year and the fix provided was working fine up until the "Great Migration" of Home Assistant. It was never merged in the end as Alan was busy with other things and as a workround I simply used the modified sensor.py file as a Custom Component. I am not quite sure why it has stopped working as was wondering if it could actually be merged if resolved and not use it as CC anymore. Code attached

"""
Support for Vera sensors.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.vera/
"""
import logging
from datetime import timedelta

from homeassistant.const import (
    TEMP_CELSIUS, TEMP_FAHRENHEIT)
from homeassistant.helpers.entity import Entity
from homeassistant.components.sensor import ENTITY_ID_FORMAT
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.util import convert
from homeassistant.components.vera import (
    VERA_CONTROLLER, VERA_DEVICES, VeraDevice)

DEPENDENCIES = ['vera']

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(seconds=5)

EVENT_VERA_REMOTE = "vera_remote"

ATTR_BUTTON = "button"

def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Vera controller devices."""
    add_entities(
        [VeraSensor(device, hass.data[VERA_CONTROLLER])
         for device in hass.data[VERA_DEVICES]['sensor']], True)

class VeraSensor(VeraDevice, Entity):
    """Representation of a Vera Sensor."""

    def __init__(self, vera_device, controller):
        """Initialize the sensor."""
        self.current_value = None
        self._temperature_units = None
        self.last_changed_time = None
        VeraDevice.__init__(self, vera_device, controller)
        self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)

    @property
    def state(self):
        """Return the name of the sensor."""
        return self.current_value

    @property
    def unit_of_measurement(self):
        """Return the unit of measurement of this entity, if any."""
        import pyvera as veraApi
        if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
            return self._temperature_units
        if self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
            return 'lx'
        if self.vera_device.category == veraApi.CATEGORY_UV_SENSOR:
            return 'level'
        if self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
            return '%'
        if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
            return 'watts'

    def update(self):
        """Update the state."""
        import pyvera as veraApi
        if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
            self.current_value = self.vera_device.temperature

            vera_temp_units = (
                self.vera_device.vera_controller.temperature_units)

            if vera_temp_units == 'F':
                self._temperature_units = TEMP_FAHRENHEIT
            else:
                self._temperature_units = TEMP_CELSIUS

        elif self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
            self.current_value = self.vera_device.light
        elif self.vera_device.category == veraApi.CATEGORY_UV_SENSOR:
            self.current_value = self.vera_device.light
        elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
            self.current_value = self.vera_device.humidity
        elif (self.vera_device.category == veraApi.CATEGORY_SCENE_CONTROLLER or
              self.vera_device.category == veraApi.CATEGORY_REMOTE):
            value = self.vera_device.get_last_scene_id(True)
            time = self.vera_device.get_last_scene_time(True)

            if time is not None and time == self.last_changed_time:
                self.current_value = None
            else:
                self.current_value = value

                self.hass.bus.fire(EVENT_VERA_REMOTE, {
                    ATTR_ENTITY_ID: self.entity_id,
                    ATTR_BUTTON: self.current_value
                })

            self.last_changed_time = time
        elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
            power = convert(self.vera_device.power, float, 0)
            self.current_value = int(round(power, 0))
        elif self.vera_device.is_trippable:
            tripped = self.vera_device.is_tripped
            self.current_value = 'Tripped' if tripped else 'Not Tripped'
        else:
            self.current_value = 'Unknown'