Hi! I am new to Home assistant, coming from FHEM. I am not really a programmer, but I stumbled across the problem that I want to dimm my lamp using pilight (it is an intertecho dimmer which I got working with “kaku_dimmer”, and it works fine in pilight). Unfortunalty there is no pilight light module, only the switch. So I started writing one up… For one it is a garstly hybrid of light and switch, second there are still some unused remnants of the light class, but anyhow, I hoped I might get it to work, but at the moment the system has stopped complaining about my module, but now started complaining about pilight_switch. Which is not really used in my config right now. Maybe someone has an idea where I am going wrong?
That is the code of my pilightli.py
"""
pilight light platform that implements lights.
For more details about this platform, please refer to the documentation
https://home-assistant.io
"""
import logging
import homeassistant.helpers.config_validation as cv
import homeassistant.components.pilight as pilight
import voluptuous as vol
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_NAME, CONF_ID, CONF_SWITCHES, CONF_STATE)
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, ATTR_WHITE_VALUE,
ATTR_XY_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR,
SUPPORT_WHITE_VALUE, Light)
LIGHT_COLORS = [
[237, 224, 33],
[255, 63, 111],
]
LIGHT_TEMPS = [240, 380]
SUPPORT_PILIGHTLI = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR |
SUPPORT_WHITE_VALUE)
_LOGGER = logging.getLogger(__name__)
CONF_BRIGHTNESS = 'brightness'
CONF_OFF_CODE = 'off'
CONF_SYSTEMCODE = 'systemcode'
CONF_UNIT = 'unit'
DEPENDENCIES = ['pilight']
COMMAND_SCHEMA = pilight.RF_CODE_SCHEMA.extend({
vol.Required('brightness'): cv.positive_int,
vol.Optional('off'): cv.positive_int,
vol.Optional(CONF_UNIT): cv.string,
vol.Optional(CONF_ID): cv.positive_int,
vol.Optional(CONF_STATE): cv.string,
vol.Optional(CONF_SYSTEMCODE): cv.string,
})
SWITCHES_SCHEMA = vol.Schema({
vol.Required(CONF_BRIGHTNESS): COMMAND_SCHEMA,
vol.Optional(CONF_OFF_CODE): COMMAND_SCHEMA,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_SWITCHES):
vol.Schema({cv.string: SWITCHES_SCHEMA}),
})
def setup_platform(hass, config, add_devices_callback, add_devices, discovery_info=None):
"""Set up the Pilight platform."""
switches = config.get(CONF_SWITCHES)
devices = []
for dev_name, properties in switches.items():
devices.append(
PilightLight(
hass,
properties.get(CONF_NAME, dev_name),
properties.get(CONF_BRIGHTNESS),
properties.get(CONF_OFF_CODE),
)
)
add_devices(devices)
class PilightLight(Light):
"""Represenation of a Pilight light."""
def __init__(
self, name, state, rgb=None, ct=None, brightness=15,
xy_color=(.5, .5), white=200):
"""Initialize the light."""
self._hass = hass
self._name = name
self._state = state
self._rgb = rgb
self._ct = ct or random.choice(LIGHT_TEMPS)
self._brightness = brightness
self._xy_color = xy_color
self._white = white
@property
def should_poll(self):
"""No polling needed for a demo light."""
return False
@property
def name(self):
"""Return the name of the light if any."""
return self._name
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._brightness
@property
def xy_color(self):
"""Return the XY color value [float, float]."""
return self._xy_color
@property
def rgb_color(self):
"""Return the RBG color value."""
return self._rgb
@property
def color_temp(self):
"""Return the CT color temperature."""
return self._ct
@property
def white_value(self):
"""Return the white value of this light between 0..255."""
return self._white
@property
def is_on(self):
"""Return true if light is on."""
return self._state
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_PILIGHTLI
def turn_on(self, **kwargs):
"""Turn the light on."""
self._state = True
if ATTR_RGB_COLOR in kwargs:
"""Turn the light on."""
self._state = True
if ATTR_RGB_COLOR in kwargs:
self._rgb = kwargs[ATTR_RGB_COLOR]
if ATTR_COLOR_TEMP in kwargs:
self._ct = kwargs[ATTR_COLOR_TEMP]
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
self._hass_service.call(pilight.DOMAIN, pilight.SERVICE_NAME,
self._brightness, blocking=True
if ATTR_XY_COLOR in kwargs:
self._xy_color = kwargs[ATTR_XY_COLOR]
if ATTR_WHITE_VALUE in kwargs:
self._white = kwargs[ATTR_WHITE_VALUE]
self.update_ha_state()
def turn_off(self, **kwargs):
"""Turn the light off."""
"""Turn the switch on by calling pilight.send service with off code."""
self._hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME,
self._code_off, blocking=True)
self._state = False
self.update_ha_state()