mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Added support for tellstick devices and sensors
This commit is contained in:
parent
c856c117a8
commit
f4e54719b9
48
README.md
48
README.md
@ -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
|
||||
@ -51,7 +52,7 @@ docker run -d --name="home-assistant" -v /path/to/homeassistant/config:/config -
|
||||
After you got the demo mode running it is time to enable some real components and get started. An example configuration file has been provided in [/config/home-assistant.conf.example](https://github.com/balloob/home-assistant/blob/master/config/home-assistant.conf.example).
|
||||
|
||||
### Philips Hue
|
||||
To get Philips Hue working you will have to connect Home Assistant to the Hue bridge.
|
||||
To get Philips Hue working you will have to connect Home Assistant to the Hue bridge.
|
||||
|
||||
Run the following command from your config dir and follow the instructions:
|
||||
|
||||
@ -146,11 +147,11 @@ When a state is changed a state_changed event is fired for which the device_sun_
|
||||
In the event that the state of device 'Paulus Nexus 5' changes to the 'Home' state:
|
||||
If the sun has set and the lights are not on:
|
||||
Turn on the lights
|
||||
|
||||
|
||||
In the event that the combined state of all tracked devices changes to 'Not Home':
|
||||
If the lights are on:
|
||||
Turn off the lights
|
||||
|
||||
|
||||
In the event of the sun setting:
|
||||
If the lights are off and the combined state of all tracked device equals 'Home':
|
||||
Turn on the lights
|
||||
@ -167,7 +168,7 @@ Action: maintains state of `weather.sun` including attributes `next_rising` and
|
||||
|
||||
**device_tracker**
|
||||
Keeps track of which devices are currently home.
|
||||
Action: sets the state per device and maintains a combined state called `all_devices`. Keeps track of known devices in the file `config/known_devices.csv`.
|
||||
Action: sets the state per device and maintains a combined state called `all_devices`. Keeps track of known devices in the file `config/known_devices.csv`.
|
||||
|
||||
**light**
|
||||
Keeps track which lights are turned on and can control the lights. It has [4 built-in light profiles](https://github.com/balloob/home-assistant/blob/master/homeassistant/components/light/light_profiles.csv) which you're able to extend by putting a light_profiles.csv file in your config dir.
|
||||
@ -195,8 +196,8 @@ Turns lights on or off using a light control component based on state of the sun
|
||||
Depends on: light control, track_sun, device_tracker
|
||||
Action:
|
||||
|
||||
* Turns lights off when all devices leave home.
|
||||
* Turns lights on when a device is home while sun is setting.
|
||||
* Turns lights off when all devices leave home.
|
||||
* Turns lights on when a device is home while sun is setting.
|
||||
* Turns lights on when a device gets home after sun set.
|
||||
|
||||
**chromecast**
|
||||
@ -218,10 +219,13 @@ 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
|
||||
|
||||
Home Assistent runs a webserver accessible on port 8123.
|
||||
Home Assistent runs a webserver accessible on port 8123.
|
||||
|
||||
* At http://127.0.0.1:8123/ it will provide an interface allowing you to control Home Assistant.
|
||||
* At http://localhost:8123/api/ it provides a password protected API.
|
||||
@ -291,17 +295,17 @@ Returns a dict with as keys the entity_ids and as value the state.
|
||||
[
|
||||
{
|
||||
"attributes": {
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_setting": "18:00:31 29-10-2013"
|
||||
},
|
||||
"entity_id": "sun.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
},
|
||||
"entity_id": "sun.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
"state": "below_horizon"
|
||||
},
|
||||
{
|
||||
"attributes": {},
|
||||
"entity_id": "process.Dropbox",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
"attributes": {},
|
||||
"entity_id": "process.Dropbox",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
"state": "on"
|
||||
}
|
||||
]
|
||||
@ -313,11 +317,11 @@ Returns the current state from an entity
|
||||
```json
|
||||
{
|
||||
"attributes": {
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_setting": "18:00:31 29-10-2013"
|
||||
},
|
||||
"entity_id": "sun.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
},
|
||||
"entity_id": "sun.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
"state": "below_horizon"
|
||||
}
|
||||
```
|
||||
@ -330,11 +334,11 @@ optional parameter: attributes - JSON encoded object
|
||||
```json
|
||||
{
|
||||
"attributes": {
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_rising": "07:04:15 29-10-2013",
|
||||
"next_setting": "18:00:31 29-10-2013"
|
||||
},
|
||||
"entity_id": "weather.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
},
|
||||
"entity_id": "weather.sun",
|
||||
"last_changed": "23:24:33 28-10-2013",
|
||||
"state": "below_horizon"
|
||||
}
|
||||
```
|
||||
|
@ -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
|
||||
|
@ -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
@ -43,6 +43,9 @@
|
||||
case "light":
|
||||
return "image:wb-incandescent"
|
||||
|
||||
case "tellstick_sensor":
|
||||
return "trending-up";
|
||||
|
||||
default:
|
||||
return "bookmark-outline";
|
||||
}
|
||||
|
@ -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
|
||||
|
134
homeassistant/components/tellstick_sensor.py
Normal file
134
homeassistant/components/tellstick_sensor.py
Normal 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
|
@ -2,3 +2,4 @@ requests>=2.0
|
||||
pychromecast>=0.5
|
||||
pyephem>=3.7
|
||||
pyuserinput>=0.1.9
|
||||
tellcore-py>=1.0.4
|
||||
|
Loading…
x
Reference in New Issue
Block a user