Added support for tellstick devices and sensors

This commit is contained in:
Gustav Ahlberg 2014-11-11 06:49:35 +01:00 committed by Paulus Schoutsen
parent c856c117a8
commit f4e54719b9
8 changed files with 6999 additions and 8852 deletions

View File

@ -9,6 +9,7 @@ It offers the following functionality through built-in components:
* Track and control [WeMo switches](http://www.belkin.com/us/Products/home-automation/c/wemo-home-automation/)
* Track and control [Google Chromecasts](http://www.google.com/intl/en/chrome/devices/chromecast)
* Track running services by monitoring `ps` output
* Track and control [Tellstick devices and sensors](http://www.telldus.se/products/tellstick)
* Turn on the lights when people get home after sun set
* Turn on lights slowly during sun set to compensate for light loss
* Turn off all lights and devices when everybody leaves the house
@ -218,6 +219,9 @@ Registers service `downloader/download_file` that will download files. File to d
**browser**
Registers service `browser/browse_url` that opens `url` as specified in event_data in the system default browser.
**tellstick_sensor**
Shows the values of that sensors that is connected to your Tellstick.
<a name='API'></a>
## Rest API

View File

@ -113,4 +113,16 @@ def setup(hass, config):
hass.states.set("chromecast.Living_Rm", "Netflix",
{'friendly_name': 'Living Room'})
# Setup tellstick sensors
hass.states.set("tellstick_sensor.Outside_temperature", "15.6",
{
'friendly_name': 'Outside temperature',
'unit_of_measurement': '°C'
})
hass.states.set("tellstick_sensor.Outside_humidity", "54",
{
'friendly_name': 'Outside humidity',
'unit_of_measurement': '°C'
})
return True

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "560228cee9ffd6de4dfdb5816b2f9a23"
VERSION = "feab16c797a25155a29f805b01fdd29b"

File diff suppressed because one or more lines are too long

View File

@ -43,6 +43,9 @@
case "light":
return "image:wb-incandescent"
case "tellstick_sensor":
return "trending-up";
default:
return "bookmark-outline";
}

View File

@ -171,6 +171,22 @@ def get_wemo_switches(config):
if isinstance(switch, pywemo.Switch)]
# pylint: disable=unused-argument
def get_tellstick_switches(config):
""" Find and return Tellstick switches. """
try:
import tellcore.telldus as telldus
except ImportError:
_LOGGER.exception(
"Failed to import tellcore")
return []
core = telldus.TelldusCore()
switches = core.devices()
return [TellstickSwitch(switch) for switch in switches]
class WemoSwitch(ToggleDevice):
""" represents a WeMo switch within home assistant. """
def __init__(self, wemo):
@ -196,3 +212,42 @@ class WemoSwitch(ToggleDevice):
def get_state_attributes(self):
""" Returns optional state attributes. """
return self.state_attr
class TellstickSwitch(ToggleDevice):
""" represents a Tellstick switch within home assistant. """
def __init__(self, tellstick):
self.tellstick = tellstick
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick.name}
def get_name(self):
""" Returns the name of the switch if any. """
return self.tellstick.name
# pylint: disable=unused-argument
def turn_on(self, dimming=None):
""" Turns the switch on. """
self.tellstick.turn_on()
def turn_off(self):
""" Turns the switch off. """
self.tellstick.turn_off()
def is_on(self):
""" True if switch is on. """
try:
import tellcore.constants as tellcore_constants
except ImportError:
_LOGGER.exception(
"Failed to import tellcore")
return False
last_sent_command_mask = tellcore_constants.TELLSTICK_TURNON | \
tellcore_constants.TELLSTICK_TURNOFF
return self.tellstick.last_sent_command(last_sent_command_mask) == \
tellcore_constants.TELLSTICK_TURNON
def get_state_attributes(self):
""" Returns optional state attributes. """
return self.state_attr

View File

@ -0,0 +1,134 @@
"""
homeassistant.components.tellstick_sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows sensor values from tellstick sensors.
Possible config keys:
id of the sensor: Name the sensor with ID
135=Outside
only_named: Only show the named sensors
only_named=1
temperature_scale: The scale of the temperature value
temperature_scale=°C
datatype_mask: mask to determine which sensor values to show based on
https://tellcore-py.readthedocs.org/en/v1.0.4/constants.html#module-tellcore.constants
datatype_mask=1 # only show temperature
datatype_mask=12 # only show rain rate and rain total
datatype_mask=127 # show all sensor values
"""
import logging
from collections import namedtuple
import homeassistant.util as util
from homeassistant.components import (ATTR_FRIENDLY_NAME,
ATTR_UNIT_OF_MEASUREMENT)
# The domain of your component. Should be equal to the name of your component
DOMAIN = "tellstick_sensor"
# List of component names (string) your component depends upon
# If you are setting up a group but not using a group for anything,
# don't depend on group
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + '.{}'
DatatypeDescription = namedtuple("DatatypeDescription", ['name', 'unit'])
def setup(hass, config):
""" Register services or listen for events that your component needs. """
logger = logging.getLogger(__name__)
try:
import tellcore.telldus as telldus
import tellcore.constants as tellcore_constants
except ImportError:
logger.exception(
"Failed to import tellcore")
return False
core = telldus.TelldusCore()
sensors = core.sensors()
if len(sensors) == 0:
logger.error("No Tellstick sensors found")
return False
sensor_value_datatype_descriptions = {
tellcore_constants.TELLSTICK_TEMPERATURE:
DatatypeDescription('temperature',
config[DOMAIN]['temperature_scale']),
tellcore_constants.TELLSTICK_HUMIDITY:
DatatypeDescription('humidity', ' %'),
tellcore_constants.TELLSTICK_RAINRATE:
DatatypeDescription('rain rate', ''),
tellcore_constants.TELLSTICK_RAINTOTAL:
DatatypeDescription('rain total', ''),
tellcore_constants.TELLSTICK_WINDDIRECTION:
DatatypeDescription('wind direction', ''),
tellcore_constants.TELLSTICK_WINDAVERAGE:
DatatypeDescription('wind average', ''),
tellcore_constants.TELLSTICK_WINDGUST:
DatatypeDescription('wind gust', '')
}
def update_sensor_value_state(sensor_name, sensor_value):
sensor_value_datatype_description = \
sensor_value_datatype_descriptions[sensor_value.datatype]
sensor_value_name = '{} {}'.format(
sensor_name, sensor_value_datatype_description.name)
entity_id = ENTITY_ID_FORMAT.format(
util.slugify(sensor_value_name))
state = sensor_value.value
state_attr = {
ATTR_FRIENDLY_NAME: sensor_value_name,
ATTR_UNIT_OF_MEASUREMENT:
sensor_value_datatype_description.unit
}
hass.states.set(entity_id, state, state_attr)
sensor_value_datatypes = [
tellcore_constants.TELLSTICK_TEMPERATURE,
tellcore_constants.TELLSTICK_HUMIDITY,
tellcore_constants.TELLSTICK_RAINRATE,
tellcore_constants.TELLSTICK_RAINTOTAL,
tellcore_constants.TELLSTICK_WINDDIRECTION,
tellcore_constants.TELLSTICK_WINDAVERAGE,
tellcore_constants.TELLSTICK_WINDGUST
]
def update_sensor_state(sensor):
try:
sensor_name = config[DOMAIN][str(sensor.id)]
except KeyError:
if 'only_named' in config[DOMAIN]:
return
sensor_name = str(sensor.id)
for datatype in sensor_value_datatypes:
if datatype & int(config[DOMAIN]['datatype_mask']) and \
sensor.has_value(datatype):
update_sensor_value_state(sensor_name, sensor.value(datatype))
# pylint: disable=unused-argument
def update_sensors_state(time):
for sensor in sensors:
update_sensor_state(sensor)
update_sensors_state(None)
hass.track_time_change(update_sensors_state, second=[0, 30])
return True

View File

@ -2,3 +2,4 @@ requests>=2.0
pychromecast>=0.5
pyephem>=3.7
pyuserinput>=0.1.9
tellcore-py>=1.0.4