2019-06-30 19:37:32 +02:00
|
|
|
import os
|
2019-06-30 22:15:52 +02:00
|
|
|
import argparse
|
2019-06-02 14:34:08 +02:00
|
|
|
from util import DeviceInfo, add_to_group
|
2019-06-02 09:36:19 +02:00
|
|
|
from ruamel.yaml import YAML
|
|
|
|
import knx_conf as knx
|
|
|
|
|
2019-06-30 19:37:32 +02:00
|
|
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
2019-06-02 14:34:08 +02:00
|
|
|
yaml = YAML()
|
|
|
|
|
|
|
|
|
|
|
|
def add_knx_devices(devices, groups):
|
2019-07-07 17:31:38 +02:00
|
|
|
imported_csv = knx.import_ets5_csv_file(os.path.join(script_path, 'knx_data/export_project1.csv'))
|
|
|
|
imported_csv.update(knx.import_ets5_csv_file(os.path.join(script_path, 'knx_data/export_project2.csv')))
|
|
|
|
|
2019-06-02 09:36:19 +02:00
|
|
|
lights = [
|
|
|
|
# Dimmers
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo('Wohnzimmerlampe', 'Wohnzimmer Deckenlampe', 'living_area'),
|
|
|
|
DeviceInfo('EsszimmerlampeWest', 'Esszimmer Deckenlampe West', 'living_area'),
|
|
|
|
DeviceInfo('EsszimmerlampeMitte', 'Esszimmer Deckenlampe Mitte', 'living_area'),
|
|
|
|
DeviceInfo("EsszimmerWandlampe", 'Esszimmer Schrankleuchte', 'living_area'),
|
|
|
|
DeviceInfo("Küchenlampe", "Küche Deckenlampe", 'living_area'),
|
|
|
|
DeviceInfo("AussenleuchteUntenSO", "Aussen Terassenlicht", 'outside'),
|
|
|
|
DeviceInfo("Gang", "Gang Licht", 'hallway'),
|
|
|
|
DeviceInfo("Bad", "Bad Licht", 'bathroom'),
|
|
|
|
DeviceInfo("GangWindfang", "Gang Einganglicht", 'hallway'),
|
|
|
|
DeviceInfo("LichtWaschküche", "Waschküche Licht", 'hallway'),
|
2019-06-02 09:36:19 +02:00
|
|
|
# Normal lights
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo('AussenleuchteHaustüren', 'Haustür Licht', 'outside'),
|
|
|
|
DeviceInfo('AussenleuchteObenNW', 'Haustür Licht NW', 'outside'),
|
|
|
|
DeviceInfo('TreppenhausLicht', "Treppenhaus Licht", 'first_floor'),
|
|
|
|
DeviceInfo('WCLicht', "WC Licht", 'other'),
|
|
|
|
DeviceInfo('LampeVorratsraum', "Vorratsraum Licht", 'other'),
|
2019-06-02 09:36:19 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
shutters = [
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo('Wohnzimmer Fenster Rollo', 'Wohnzimmer Fenster Rollo', 'living_area'),
|
|
|
|
DeviceInfo('Terassentür Rollo', 'Wohnzimmer Terrassentür Rollo', 'living_area'),
|
|
|
|
DeviceInfo('Küchenfenster Rollo', 'Küche Fenster Rollo', 'living_area'),
|
|
|
|
DeviceInfo('Esszimmerfenster Rollo', 'Esszimmer Fenster Rollo', 'living_area'),
|
2019-06-02 09:36:19 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
switches = [
|
|
|
|
# Bells
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("KlingelOben", "Klingel Oben", 'first_floor'),
|
|
|
|
DeviceInfo("Klingel Innen", "Klingel Innentür", 'other'),
|
|
|
|
DeviceInfo("Klingel Aussen", "Klingen Außentür", 'other'),
|
2019-06-02 09:36:19 +02:00
|
|
|
# Bewegungsmelder LEDs
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("BewegungsmelderMitte LED", "Bewegungsmelder Mitte LED", 'hallway'),
|
|
|
|
DeviceInfo("BewegungsmelderWest LED", "Bewegungsmelder West LED", 'hallway'),
|
|
|
|
DeviceInfo("BewegungsmelderOst LED", "Bewegungsmelder Ost LED", 'hallway'),
|
2019-06-02 09:36:19 +02:00
|
|
|
]
|
|
|
|
scene_button_names = ['ObenLinks', 'ObenRechts', 'MitteLinks', 'MitteRechts', 'UntenLinks', 'UntenRechts']
|
|
|
|
scene_button_names = [(i, e) for i, e in enumerate(scene_button_names)]
|
2019-06-11 19:28:39 +02:00
|
|
|
switches += [DeviceInfo(f"SzeneEsszimmer{n}", f"Esszimmer Szene {i}") for i, n in scene_button_names]
|
|
|
|
switches += [DeviceInfo(f"SzeneWohnzimmer{n}", f"Wohnzimmer Szene {i}") for i, n in scene_button_names]
|
|
|
|
switches += [DeviceInfo(f"SzeneEingang{n}", f"Eingang Szene {i}") for i, n in scene_button_names[2:]]
|
|
|
|
switches += [DeviceInfo(f"SzeneTerrassentuer{n}", f"Wohnzimmer Terrassentür Szene {i}")
|
2019-06-02 09:36:19 +02:00
|
|
|
for i, n in scene_button_names[2: 4]]
|
|
|
|
|
|
|
|
power_plugs = [
|
|
|
|
# Vorratsraum
|
2019-07-07 17:31:38 +02:00
|
|
|
DeviceInfo("VorratsraumSteckdose1", "Vorratsraum Steckdose 1", 'other'),
|
|
|
|
DeviceInfo("VorratsraumSteckdose2", "Vorratsraum Steckdose 2", 'other'),
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("VorratsraumSteckdose3", "Gefrierschrank", 'other'),
|
2019-06-02 09:36:19 +02:00
|
|
|
# Waschraum
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("Trockner", "Trockner", 'other'),
|
|
|
|
DeviceInfo("Waschmaschine", "Waschmaschine", 'other'),
|
2019-06-02 09:36:19 +02:00
|
|
|
# Küche
|
2019-07-07 17:31:38 +02:00
|
|
|
DeviceInfo("KücheSteckdose1", "Küche Steckdosen rechts"),
|
|
|
|
DeviceInfo("KücheSteckdose2", "Dunstabzug"),
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("Spülmaschine", "Spülmaschine", 'living_area'),
|
|
|
|
DeviceInfo("Backofen", "Backofen", 'living_area'),
|
|
|
|
DeviceInfo("HerdP1", "Herd Phase 1", 'living_area'),
|
|
|
|
DeviceInfo("HerdP2", "Herd Phase 2", 'living_area'),
|
|
|
|
DeviceInfo("HerdP3", "Herd Phase 3", 'living_area'),
|
2019-06-02 09:36:19 +02:00
|
|
|
# Rest
|
2019-06-02 14:34:08 +02:00
|
|
|
DeviceInfo("ArbeitszimmerSteckdose", "Arbeitszimmer Steckdose", 'office_martin'),
|
|
|
|
DeviceInfo("WohnzimmerSteckdose1", "Wohnzimmer Steckdose 1", 'living_area'),
|
|
|
|
DeviceInfo("WohnzimmerSteckdose2", "Wohnzimmer Steckdose 2", 'living_area'),
|
2019-06-02 09:36:19 +02:00
|
|
|
]
|
|
|
|
|
2019-07-07 17:31:38 +02:00
|
|
|
motion_sensors = {
|
|
|
|
'sensor': [
|
|
|
|
# Brightness
|
|
|
|
{'name': 'Gang Bewegungsmelder West Helligkeit',
|
|
|
|
'address': imported_csv['BewegungsmelderWest Helligkeit'],
|
|
|
|
'type': 'illuminance'},
|
|
|
|
{'name': 'Gang Bewegungsmelder Mitte Helligkeit',
|
|
|
|
'address': imported_csv['BewegungsmelderMitte Helligkeit'],
|
|
|
|
'type': 'illuminance'},
|
|
|
|
{'name': 'Gang Bewegungsmelder Ost Helligkeit',
|
|
|
|
'address': imported_csv['BewegungsmelderOst Helligkeit'],
|
|
|
|
'type': 'illuminance'},
|
|
|
|
# Temperature
|
|
|
|
{'name': 'Esszimmer Temperatur',
|
|
|
|
'address': imported_csv['TemperaturEsszimmer'],
|
|
|
|
'type': 'temperature'},
|
|
|
|
{'name': 'Treppenhaus Oben Temperatur',
|
|
|
|
'address': imported_csv['TreppenhausObenTemperatur'],
|
|
|
|
'type': 'temperature'},
|
|
|
|
{'name': 'Eingangsbereich Temperatur',
|
|
|
|
'address': imported_csv['TemperaturGang'],
|
|
|
|
'type': 'temperature'},
|
|
|
|
{'name': 'Wohnzimmer Gang Temperatur',
|
|
|
|
'address': imported_csv['TemperaturWohnzimmerGangTuer'],
|
|
|
|
'type': 'temperature'},
|
|
|
|
{'name': 'Wohnzimmer Terassentür Temperatur',
|
|
|
|
'address': imported_csv['TemperaturWohnzimmerAussenTuer'],
|
|
|
|
'type': 'temperature'},
|
|
|
|
],
|
|
|
|
'binary_sensor': [
|
|
|
|
{'name': 'Gang Bewegungsmelder Schlafzimmer',
|
|
|
|
'address': imported_csv['BewegungsmelderWest Motion Links'],
|
|
|
|
'device_class': 'motion'},
|
|
|
|
{'name': 'Gang Bewegungsmelder Wohnzimmer',
|
|
|
|
'address': imported_csv['BewegungsmelderWest Motion Rechts'],
|
|
|
|
'device_class': 'motion'},
|
|
|
|
{'name': 'Gang Bewegungsmelder Mitte',
|
|
|
|
'address': imported_csv['BewegungsmelderMitte Motion'],
|
|
|
|
'device_class': 'motion'},
|
|
|
|
{'name': 'Gang Bewegungsmelder Ost',
|
|
|
|
'address': imported_csv['BewegungsmelderOst Motion'],
|
|
|
|
'device_class': 'motion'},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
knx.extent(devices, motion_sensors)
|
2019-06-02 09:36:19 +02:00
|
|
|
knx.extent(devices, knx.create_lights(lights, imported_csv))
|
|
|
|
knx.extent(devices, knx.create_shutters(shutters, imported_csv))
|
|
|
|
knx.extent(devices, knx.create_switches(switches, imported_csv))
|
|
|
|
knx.extent(devices, knx.create_power_plug(power_plugs, imported_csv))
|
2019-06-02 14:34:08 +02:00
|
|
|
|
2019-06-11 19:28:39 +02:00
|
|
|
for device_type, devices in [('light', lights), ('cover', shutters), ('switch', switches)]:
|
|
|
|
for device in devices:
|
|
|
|
add_to_group(groups, device.groups, device.display_name, device_type)
|
2019-06-02 14:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def add_fhem_devices(devices, groups):
|
2019-06-30 19:37:32 +02:00
|
|
|
fhem_yaml_path = os.path.join(script_path, 'fhem.yaml')
|
|
|
|
fhem_yaml = yaml.load(open(fhem_yaml_path))
|
2019-06-02 14:34:08 +02:00
|
|
|
for device_type, device_list in fhem_yaml.items():
|
|
|
|
if device_type not in devices:
|
|
|
|
devices[device_type] = []
|
|
|
|
for device in device_list:
|
|
|
|
device['platform'] = 'fhem'
|
|
|
|
if 'groups' in device:
|
2019-06-11 19:28:39 +02:00
|
|
|
add_to_group(groups, device['groups'], device['name'], device_type)
|
2019-06-02 14:34:08 +02:00
|
|
|
del device['groups']
|
|
|
|
devices[device_type].append(device)
|
|
|
|
|
|
|
|
|
2019-06-21 01:58:58 +02:00
|
|
|
def add_light_groups(groups):
|
|
|
|
light_groups = {
|
|
|
|
f"light_{group_id}": {
|
|
|
|
'name': content['name'] + " Lichter",
|
|
|
|
'entities': [e for e in content['entities'] if e.startswith('light.')],
|
|
|
|
}
|
|
|
|
for group_id, content in groups.items() if 'name' in content
|
|
|
|
}
|
|
|
|
groups.update(light_groups)
|
|
|
|
|
|
|
|
|
2019-06-30 22:15:52 +02:00
|
|
|
def create_config(target_directory, development=False):
|
2019-06-30 19:37:32 +02:00
|
|
|
groups_yaml_path = os.path.join(script_path, 'groups.yaml')
|
|
|
|
manual_config_path = os.path.join(script_path, 'manual_config.yaml')
|
|
|
|
group_dict = yaml.load(open(groups_yaml_path))
|
2019-07-07 17:31:38 +02:00
|
|
|
manual_config_dict = yaml.load(open(manual_config_path))
|
2019-06-02 14:34:08 +02:00
|
|
|
|
|
|
|
all_devices = {}
|
|
|
|
add_knx_devices(all_devices, group_dict)
|
|
|
|
add_fhem_devices(all_devices, group_dict)
|
|
|
|
|
2019-06-30 19:37:32 +02:00
|
|
|
with open(os.path.join(target_directory, 'configuration.yaml'), 'w') as output:
|
|
|
|
output.write("# Dont' edit manually! this is generated!\n\n")
|
2019-07-07 17:31:38 +02:00
|
|
|
for key in ['sensor', 'switch', 'light', 'cover']:
|
|
|
|
if key in manual_config_dict:
|
|
|
|
all_devices[key].extend(manual_config_dict[key])
|
|
|
|
del manual_config_dict[key]
|
|
|
|
yaml.dump(manual_config_dict, output)
|
2019-06-02 14:34:08 +02:00
|
|
|
yaml.dump(all_devices, output)
|
2019-06-21 01:58:58 +02:00
|
|
|
add_light_groups(group_dict)
|
2019-06-30 19:37:32 +02:00
|
|
|
|
|
|
|
with open(os.path.join(target_directory, 'groups.yaml'), 'w') as output:
|
|
|
|
output.write("# Dont' edit manually! this is generated!\n\n")
|
|
|
|
yaml.dump(group_dict, output)
|
2019-06-02 09:36:19 +02:00
|
|
|
|
2019-06-30 22:15:52 +02:00
|
|
|
with open(os.path.join(target_directory, 'secrets.yaml'), 'w') as output:
|
|
|
|
output.write("# Dont' edit manually! this is generated!\n\n")
|
|
|
|
output.write(open(os.path.join(script_path, 'secrets.yaml'), 'r').read())
|
|
|
|
output.write("\n\n")
|
|
|
|
additional_file = 'secrets_development.yaml' if development else 'secrets_deploy.yaml'
|
|
|
|
output.write(open(os.path.join(script_path, additional_file), 'r').read())
|
|
|
|
|
2019-06-02 09:36:19 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-06-30 22:15:52 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-d", "--dev", help="create config file for development", action="store_true")
|
|
|
|
args = parser.parse_args()
|
|
|
|
create_config(target_directory=os.getcwd(), development=args.dev)
|