Permalink
Browse files

Issue #12: Broadcast outside temperature to KNX bus.

  • Loading branch information...
Julius2342 committed Nov 20, 2017
1 parent 30e6a6c commit 4a68fdd26297e7361e15a3d95acedeb1228e2b95
Showing with 27 additions and 0 deletions.
  1. +27 −0 home-assistant-plugin/custom_components/xknx.py
@@ -12,6 +12,7 @@
import voluptuous as vol
from homeassistant.helpers import discovery
from homeassistant.helpers.event import async_track_state_change
import homeassistant.helpers.config_validation as cv
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, \
CONF_HOST, CONF_PORT
@@ -28,6 +29,8 @@
CONF_XKNX_FIRE_EVENT_FILTER = "fire_event_filter"
CONF_XKNX_STATE_UPDATER = "state_updater"
CONF_XKNX_TIME_ADDRESS = "time_address"
CONF_XKNX_OUTSIDE_TEMPERATURE_SENSOR = "outside_temperature_sensor"
CONF_XKNX_OUTSIDE_TEMPERATURE_ADDRESS = "outside_temperature_address"
SERVICE_XKNX_SEND = "send"
SERVICE_XKNX_ATTR_ADDRESS = "address"
@@ -63,6 +66,10 @@
[cv.string]),
vol.Optional(CONF_XKNX_TIME_ADDRESS): cv.string,
vol.Optional(CONF_XKNX_STATE_UPDATER, default=True): cv.boolean,
vol.Inclusive(CONF_XKNX_OUTSIDE_TEMPERATURE_SENSOR, 'outside_temp'):
cv.string,
vol.Inclusive(CONF_XKNX_OUTSIDE_TEMPERATURE_ADDRESS, 'outside_temp'):
cv.string,
})
}, extra=vol.ALLOW_EXTRA)
@@ -223,6 +230,12 @@ def register_callbacks(self):
self.xknx.telegram_queue.register_telegram_received_cb(
self.telegram_received_cb, address_filters)
if CONF_XKNX_OUTSIDE_TEMPERATURE_ADDRESS in self.config[DOMAIN]:
sensor_entity_id = \
self.config[DOMAIN][CONF_XKNX_OUTSIDE_TEMPERATURE_SENSOR]
async_track_state_change(self.hass, sensor_entity_id,
self.async_broadcast_temperature)
@asyncio.coroutine
def telegram_received_cb(self, telegram):
"""Callback invoked after a KNX telegram was received."""
@@ -253,6 +266,20 @@ def calculate_payload(attr_payload):
telegram.group_address = address
yield from self.xknx.telegrams.put(telegram)
@asyncio.coroutine
def async_broadcast_temperature(self, entity_id, old_state, new_state):
"""Broadcast new temperature of sensor to KNX bus."""
from xknx.knx import Telegram, Address, DPTArray, DPTFloat
if new_state is None:
return
address = Address(
self.config[DOMAIN][CONF_XKNX_OUTSIDE_TEMPERATURE_ADDRESS])
payload = DPTArray(DPTFloat().to_knx(float(new_state.state)))
telegram = Telegram()
telegram.group_address = address
telegram.payload = payload
yield from self.xknx.telegrams.put(telegram)
class KNXAutomation():
"""Wrapper around xknx.devices.ActionCallback object.."""

0 comments on commit 4a68fdd

Please sign in to comment.