New component for powerplugs for radio in first floor

This commit is contained in:
Martin Bauer 2020-05-03 08:29:35 +00:00
parent 250556adc2
commit 2cfc2f30f1
6 changed files with 146 additions and 661 deletions

View File

@ -95,6 +95,25 @@ def get_config():
'key_yellow': '[scene] wohnbereich_hell', 'key_yellow': '[scene] wohnbereich_hell',
'key_blue': '[scene] wohnbereich_blau_grun', 'key_blue': '[scene] wohnbereich_blau_grun',
} }
},
'first_floor_dining_room': {
'ir_host': 'esszimmerradio',
'media_player': 'media_player.esszimmer',
'group': 'first_floor',
'mapping': {
'btn_1': '[radio] Bayern 1',
'btn_2': '[radio] Bayern 2',
'btn_3': '[radio] BR Heimat',
'btn_4': '[radio] Bayern+',
'btn_5': '[radio] B 5 Aktuell',
'btn_6': '[radio] BR-Klassik',
'btn_7': '[playlist] Gesammelte Weihnachtslieder',
'btn_8': '[playlist] Harmonic Brass Christmas',
'btn_9': '[playlist] German Brass Christmas',
'key_numeric_star': '[playlist] Weihnachten mit den Wiener Sängerknaben',
'btn_0': '[playlist] Weihnachten mit den Wiener Sängerknaben',
'key_numeric_pound': '[playlist] SammlungGeorg',
}
} }
} }

View File

@ -112,6 +112,15 @@ notify:
dimmer: dimmer:
cover_half: cover_half:
switch:
- platform: httpsispmctl
name: esszimmer_oben_radio_steckdose
host: esszimmerradio.fritz.box
num_power_plugs: 4
long_click: long_click:
duration: 0.6 duration: 0.6
switches: switches:

View File

@ -1,3 +1,3 @@
local_ip: 192.168.178.80 local_ip: 127.0.0.1
knxd_host: 192.168.178.80 #directly the network bridge: 192.168.178.65 knxd_host: 127.0.0.1 #directly the network bridge: 192.168.178.65
homekit_name: BauerHome homekit_name: BauerHome

View File

@ -0,0 +1,116 @@
import logging
import voluptuous as vol
from collections import defaultdict
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import aiohttp_client
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_NAME
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from aiohttp import ClientConnectionError
DOMAIN = 'httpsispmctl'
CONF_NUM_PLUGS = "num_power_plugs"
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_PORT, default=2638): cv.port,
vol.Optional(CONF_NUM_PLUGS, default=4): int,
})
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
switches = []
session = aiohttp_client.async_get_clientsession(hass)
switches = []
for i in range(config[CONF_NUM_PLUGS]):
switches.append(HttpSispmctlSwitch(config[CONF_NAME], i+1))
host_obj = SispmctlHost(session, config[CONF_HOST], config[CONF_PORT], switches)
for s in switches:
s.set_host_object(host_obj)
async_add_entities(switches)
class SispmctlHost:
def __init__(self, session, hostname, port, switch_objects):
self._session = session
self.hostname = hostname
self.port = port
self._switch_objects = switch_objects
async def switch(self, number, on=True):
cmd = "on" if on else "off"
try:
url = f"http://{self.hostname}:{self.port}/{cmd}{number}.html"
async with self._session.get(url, timeout=3) as resp:
if resp.status == 200:
result = await resp.json()
await self.notify_switches(result)
else:
await self.set_switches_unreachable()
except ClientConnectionError:
await self.set_switches_unreachable()
async def update_state(self):
url = f"http://{self.hostname}:{self.port}"
async with self._session.get(url, timeout=20) as resp:
if resp.status == 200:
result = await resp.json()
await self.notify_switches(result)
else:
await self.set_switches_unreachable()
async def notify_switches(self, response):
for i, switch in enumerate(self._switch_objects):
state = bool(response[f"{i+1}"])
await switch.set_state(on=state, reachable=True)
async def set_switches_unreachable(self):
for switch in self._switch_objects:
await switch.set_state(on=None, reachable=False)
class HttpSispmctlSwitch(SwitchDevice):
def __init__(self, basename, number):
self._basename = basename
self._number = number
self._available = True
self._on = None
self._host = None
def set_host_object(self, host):
self._host = host
assert self._host
async def set_state(self, on, reachable):
self._on = on
await self.async_update_ha_state()
@property
def name(self):
return f"{self._basename}{self._number}"
@property
def available(self) -> bool:
return self._available
@property
def is_on(self):
return self._on
async def async_turn_on(self, **kwargs):
assert self._host, "Call set_host_object first"
self._on = True
await self._host.switch(self._number, on=True)
async def async_turn_off(self, **kwargs):
assert self._host, "Call set_host_object first"
self._on = False
await self._host.switch(self._number, on=False)
async def async_update(self):
await self._host.update_state()

View File

@ -1,659 +0,0 @@
- name: Arbeitszimmer Martin Orange
id: arbeitszimmer_martin_orange
entities:
light.arbeitszimmer_martin_deckenlampe:
state: false
light.arbeitszimmer_martin:
state: true
brightness: 229
color_temp: 484
light.arbeitszimmer_martin_oben:
state: true
brightness: 216
xy_color:
- 0.569
- 0.397
light.arbeitszimmer_martin_unten:
state: true
brightness: 214
xy_color:
- 0.2
- 0.102
- name: Arbeitszimmer Martin Blau Grün
id: arbeitszimmer_martin_blau_grun
entities:
light.arbeitszimmer_martin_deckenlampe:
state: false
light.arbeitszimmer_martin:
state: true
brightness: 173
xy_color:
- 0.429
- 0.483
light.arbeitszimmer_martin_oben:
state: true
brightness: 186
xy_color:
- 0.565
- 0.398
light.arbeitszimmer_martin_unten:
state: true
brightness: 247
xy_color:
- 0.219
- 0.137
- name: Arbeitszimmer Martin Hell
id: arbeitszimmer_martin_hell
entities:
light.arbeitszimmer_martin_deckenlampe:
state: true
brightness: 252
light.arbeitszimmer_martin:
state: true
brightness: 252
xy_color:
- 0.429
- 0.483
light.arbeitszimmer_martin_oben:
state: true
brightness: 247
xy_color:
- 0.44
- 0.485
light.arbeitszimmer_martin_unten:
state: true
brightness: 249
xy_color:
- 0.219
- 0.137
- name: Wohnbereich Orange
id: wohnbereich_orange
entities:
light.kuche_deckenlampe:
state: true
brightness: 38
light.wohnzimmer_deckenlampe:
state: true
brightness: 38
light.esszimmer_deckenlampe_west:
state: true
brightness: 38
light.esszimmer_deckenlampe_mitte:
state: true
brightness: 38
light.esszimmer_schrankleuchte:
state: false
light.kuche_links:
state: true
brightness: 153
xy_color:
- 0.54
- 0.435
light.kuche_rechts:
state: true
brightness: 242
xy_color:
- 0.557
- 0.396
light.kuche_vorne:
state: true
color_temp: 477
brightness: 114
light.wohnzimmer_kugel:
state: true
brightness: 229
color_temp: 492
light.wohnzimmer_stehlampe:
state: true
brightness: 191
color_temp: 428
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 127
color_temp: 492
light.wohnzimmer_regal_rechts:
state: true
brightness: 191
xy_color:
- 0.618
- 0.366
light.wohnzimmer_regal_links:
state: true
brightness: 191
xy_color:
- 0.53
- 0.443
- name: Wohnbereich Blau Grün
id: wohnberech_blau_grun
entities:
light.kuche_deckenlampe:
state: true
brightness: 38
light.wohnzimmer_deckenlampe:
state: true
brightness: 51
light.esszimmer_deckenlampe_west:
state: true
brightness: 38
light.esszimmer_deckenlampe_mitte:
state: true
brightness: 38
light.esszimmer_schrankleuchte:
state: false
light.kuche_links:
state: true
brightness: 198
xy_color:
- 0.156
- 0.218
light.kuche_rechts:
state: true
brightness: 252
xy_color:
- 0.171
- 0.353
light.kuche_vorne:
state: true
brightness: 130
xy_color:
- 0.158
- 0.053
light.wohnzimmer_kugel:
state: true
brightness: 252
xy_color:
- 0.46
- 0.408
light.wohnzimmer_stehlampe:
state: true
brightness: 153
xy_color:
- 0.183
- 0.062
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 150
xy_color:
- 0.184
- 0.068
light.wohnzimmer_regal_rechts:
state: true
brightness: 252
xy_color:
- 0.143
- 0.113
light.wohnzimmer_regal_links:
state: true
brightness: 252
xy_color:
- 0.222
- 0.636
- name: Wohnbereich Grün
id: wohnbereich_grun
entities:
light.kuche_deckenlampe:
state: false
light.wohnzimmer_deckenlampe:
state: false
light.esszimmer_deckenlampe_west:
state: false
light.esszimmer_deckenlampe_mitte:
state: false
light.esszimmer_schrankleuchte:
state: false
light.kuche_links:
state: true
brightness: 198
xy_color:
- 0.4038
- 0.555
light.kuche_rechts:
state: true
brightness: 252
xy_color:
- 0.4771
- 0.4957
light.kuche_vorne:
state: true
brightness: 130
xy_color:
- 0.1987
- 0.5792
light.wohnzimmer_kugel:
state: true
brightness: 252
xy_color:
- 0.4084
- 0.5168
light.wohnzimmer_stehlampe:
state: true
brightness: 153
xy_color:
- 0.4084
- 0.5168
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 150
xy_color:
- 0.4
- 0.53
light.wohnzimmer_regal_rechts:
state: true
brightness: 252
xy_color:
- 0.1635
- 0.3502
light.wohnzimmer_regal_links:
state: true
brightness: 252
xy_color:
- 0.2075
- 0.6584
- name: Wohnbereich Hell
id: wohnbereich_hell
entities:
light.esszimmer_deckenlampe_west:
state: true
brightness: 255
light.wohnzimmer_deckenlampe:
state: true
brightness: 255
light.kuche_deckenlampe:
state: true
brightness: 255
light.wohnzimmer_regal_links:
state: true
brightness: 255
xy_color:
- 0.527
- 0.447
light.kuche_links:
state: true
brightness: 255
xy_color:
- 0.537
- 0.438
light.kuche_rechts:
state: true
brightness: 255
xy_color:
- 0.557
- 0.403
light.wohnzimmer_regal_rechts:
state: true
brightness: 255
xy_color:
- 0.616
- 0.371
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 255
color_temp: 492
light.wohnzimmer_stehlampe:
state: true
brightness: 255
color_temp: 492
light.wohnzimmer_kugel:
state: true
brightness: 255
color_temp: 492
light.kuche_vorne:
state: true
brightness: 255
color_temp: 492
- name: Wohnbereich Meditation
id: wohnbereich_meditation
entities:
light.kuche_deckenlampe:
state: false
light.wohnzimmer_deckenlampe:
state: false
light.esszimmer_deckenlampe_west:
state: false
light.esszimmer_deckenlampe_mitte:
state: false
light.esszimmer_schrankleuchte:
state: false
light.kuche_links:
state: true
brightness: 255
xy_color:
- 0.5428
- 0.3887
light.kuche_rechts:
state: true
brightness: 255
xy_color:
- 0.2927
- 0.2242
light.kuche_vorne:
state: true
brightness: 255
xy_color:
- 0.6
- 0.377
light.wohnzimmer_kugel:
state: true
brightness: 255
xy_color:
- 0.3581
- 0.287
light.wohnzimmer_stehlampe:
state: true
brightness: 255
xy_color:
- 0.3581
- 0.287
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 255
xy_color:
- 0.5993
- 0.3765
light.wohnzimmer_regal_rechts:
state: true
brightness: 255
xy_color:
- 0.2925
- 0.2231
light.wohnzimmer_regal_links:
state: true
brightness: 255
xy_color:
- 0.2075
- 0.6584
cover.esszimmer_fenster_rollo:
state: open
current_position: 100
cover.kuche_fenster_rollo:
state: open
current_position: 100
cover.wohnzimmer_fenster_rollo:
state: open
current_position: 100
cover.wohnzimmer_terrassentur_rollo:
state: open
current_position: 100
- name: Wohnbereich Kuscheln
id: wohnbereich_kuscheln
entities:
light.kuche_deckenlampe:
state: false
light.wohnzimmer_deckenlampe:
state: false
light.esszimmer_deckenlampe_west:
state: false
light.esszimmer_deckenlampe_mitte:
state: false
light.esszimmer_schrankleuchte:
state: false
light.kuche_links:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4111
light.kuche_rechts:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4111
light.kuche_vorne:
state: true
brightness: 190
xy_color:
- 0.561
- 0.4042
light.wohnzimmer_kugel:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4042
light.wohnzimmer_stehlampe:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4042
light.wohnzimmer_stehlampe_oben:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4042
light.wohnzimmer_regal_rechts:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4111
light.wohnzimmer_regal_links:
state: true
brightness: 190
xy_color:
- 0.5609
- 0.4111
light.gang_bogen:
state: true
brightness: 255
xy_color:
- 0.6313
- 0.361
light.gang_licht:
state: false
cover.esszimmer_fenster_rollo:
state: closed
current_position: 0
cover.kuche_fenster_rollo:
state: closed
current_position: 0
cover.wohnzimmer_fenster_rollo:
state: closed
current_position: 0
cover.wohnzimmer_terrassentur_rollo:
state: closed
current_position: 0
- id: schlafzimmer_bettlich_dunkel
name: Schlafzimmer Bettlicht dunkel
entities:
light.bett_martin:
brightness: 5
effect: none
hs_color:
- 10.118
- 100
rgb_color:
- 255
- 43
- 0
state: 'on'
xy_color:
- 0.689
- 0.309
light.bett_rebecca:
brightness: 5
effect: none
hs_color:
- 10.118
- 100
rgb_color:
- 255
- 43
- 0
state: 'on'
xy_color:
- 0.689
- 0.309
light.schlafzimmer_deckenlampe:
state: 'off'
light.schlafzimmer_fluter:
state: 'off'
light.schlafzimmer_schrank:
state: 'off'
- name: Schlafzimmer Einschlaflicht
id: schlafzimmer_einschlaflicht
entities:
light.schlafzimmer_deckenlampe:
state: false
light.schlafzimmer_schrank:
state: false
light.bett_martin:
state: true
brightness: 70
xy_color:
- 0.502
- 0.414
light.bett_rebecca:
state: true
brightness: 70
xy_color:
- 0.502
- 0.414
light.schlafzimmer_fluter:
state: false
- name: Schlafzimmer Orange
id: schlafzimmer_orange
entities:
light.schlafzimmer_deckenlampe:
state: false
light.schlafzimmer_schrank:
state: true
brightness: 81
xy_color:
- 0.502
- 0.414
light.bett_martin:
state: true
brightness: 81
xy_color:
- 0.502
- 0.414
light.bett_rebecca:
state: true
brightness: 81
xy_color:
- 0.502
- 0.414
light.schlafzimmer_fluter:
state: true
brightness: 81
xy_color:
- 0.502
- 0.414
- name: Schlafzimmer Rot
id: schlafzimmer_rot
entities:
light.schlafzimmer_deckenlampe:
state: false
light.schlafzimmer_schrank:
state: true
brightness: 146
xy_color:
- 0.584
- 0.354
light.bett_martin:
state: true
brightness: 198
xy_color:
- 0.584
- 0.354
light.bett_rebecca:
state: true
brightness: 198
xy_color:
- 0.569
- 0.397
light.schlafzimmer_fluter:
state: true
brightness: 95
xy_color:
- 0.581
- 0.389
- name: Schlafzimmer Blau
id: schlafzimmer_blau
entities:
light.schlafzimmer_deckenlampe:
state: false
light.schlafzimmer_schrank:
state: true
brightness: 58
xy_color:
- 0.442
- 0.416
light.bett_martin:
state: true
brightness: 254
xy_color:
- 0.191
- 0.173
light.bett_rebecca:
state: true
brightness: 83
xy_color:
- 0.418
- 0.419
light.schlafzimmer_fluter:
state: true
brightness: 127
xy_color:
- 0.223
- 0.148
- name: Schlafzimmer Ganz Hell
id: schlafzimmer_ganz_hell
entities:
light.schlafzimmer_deckenlampe:
state: true
brightness: 255
light.schlafzimmer_schrank:
state: true
brightness: 254
xy_color:
- 0.459
- 0.408
light.bett_martin:
state: true
brightness: 254
xy_color:
- 0.459
- 0.408
light.bett_rebecca:
state: true
brightness: 254
xy_color:
- 0.459
- 0.408
light.schlafzimmer_fluter:
state: true
brightness: 254
xy_color:
- 0.459
- 0.408
- name: Garten Savanna
id: garten_savanna
entities:
light.garten_stehleuchte:
state: true
brightness: 205
xy_color:
- 0.465
- 0.448
light.garten_spot_beet:
state: true
brightness: 205
xy_color:
- 0.532
- 0.384
light.garten_spot_magnolie:
state: true
brightness: 205
xy_color:
- 0.465
- 0.448
light.garten_spot_birke:
state: true
brightness: 205
xy_color:
- 0.586
- 0.35