Package: dirigera
Dirigera Python ClientThis repository provides an unofficial Python client for controlling the IKEA Dirigera Smart Home Hub. Current features:light controloutlet controlair purifier controlblinds controlremote controllers(tested with STYRBAR)environment sensor(tested with VINDSTYRKA)scenemotion sensoropen/close sensorevent listenerfor hub eventsSupport for other features will be added in the future and your input in form of issues and PRs is greatly appreciated.InstallationpipinstalldirigeraQuickstartFind out the ip-address of your Dirigera (check your router)Once you installeddirigerawith pip you can run the included generate-token script. Here you can directly set the ip-address of you dirigera as parameter.generate-token<Dirigeraip-address>The script starts the auth process. When prompted, you must push the action button on the bottom of your Dirigera.After that hit ENTER and yourtokenwill be printed to the console.Example:Press the action button on Dirigera then hit ENTER ...
Your Token:
mgwB.aXqwpzV89N0aUwBhZMJjD8a.UBPyzy2InGtqgwo2MO5.xX4ug7.uBcVJquwYzLnAijF7SdYKvNxTo0uzQKahV10A-3ZQOz-UAubGP6sHWt1CJx3QmWZyE7ZcMZKgODXjSzWL1lumKgGz5dUIwFi3rhNxgK-IsBGeGVhNXPt8vGrYEcZePwPvNAIg8RqmlH27L-JZPnkAtP2wHoOdW72Djot3yJsohtEsb0p9mJvoZFSavTlTr4LDuf584vuH5fha5xoR9QhhIvvgbAP-s4EHFqENNi6vrYLHKR.sdqnv4sYw6UH-l6oiPnnRLxinoqBPOlWhlcL9doFviXQE.tZ9X8WVqyBrd0NYHlo9iorEvUbnZuD02BEJrg4NLwgh3rZtyF0Mi46HenynzBohbPn4RnuSYYCiHt5EZnWedxBtDqc7mSTm1ZtyDDone. Use this token in the hub setup.dirigera.Hub(
   token="mgwB.aXqwpzV89N0aUwBhZMJjD8a...",
   ip_address="192.1..."
)Dirigera HubSetting up the client works by providing the token and ip address.importdirigeradirigera_hub=dirigera.Hub(token="mgwB.aXqwpzV89N0aUwBhZMJjD8a...",ip_address="192.1...")DevicesAll available devices (Light, Controller, Outlet, ...) consist of the core data defined indevice.py:Core Device Dataid:strtype:strdevice_type:strcreated_at:datetime.datetimeis_reachable:boollast_seen:datetime.datetimeattributes:Attributescapabilities:Capabilitiesroom:Roomdevice_set:Listremote_links:List[str]is_hidden:Optional[bool]=NoneAttributesAll devices have attributes. Some devices have special attributes (for example Light has `is_on``). These are the core attributes each device has:custom_name:strmodel:strmanufacturer:strfirmware_version:strhardware_version:strserial_number:Optional[str]=Noneproduct_code:Optional[str]=Noneota_status:Optional[str]=Noneota_state:Optional[str]=Noneota_progress:Optional[int]=Noneota_policy:Optional[str]=Noneota_schedule_start:Optional[datetime.time]=Noneota_schedule_end:Optional[datetime.time]=NoneCapabilitiesAll devices have capabilities (for some it is just empty lists). Capabilities desrcibe what send/receive actions can be performed:can_send:List[str]can_receive:List[str]All devices have a room with the corresponging infos.Roomid:strname:strcolor:stricon:strControlling LightsTo get information about the available lights, you can use theget_lights()method:lights=dirigera_hub.get_lights()The light object has the following attributes (additional to the core attributes):startup_on_off:Optional[StartupEnum]=None# Optional attributes are not present on all lightsis_on:boollight_level:Optional[int]=Nonecolor_temperature:Optional[int]=Nonecolor_temperature_min:Optional[int]=Nonecolor_temperature_max:Optional[int]=Nonecolor_hue:Optional[int]=Nonecolor_saturation:Optional[float]=NoneAvailable methods for light are:light.set_name(name="kitchen light 1")light.set_light(lamp_on=True)light.set_light_level(light_level=90)light.set_color_temperature(color_temp=3000)light.set_light_color(hue=128,saturation=0.5)light.set_startup_behaviour(behaviour=StartupEnum.START_OFF)Controlling OutletsTo get information about the available outlets, you can use theget_outlets()method:outlets=dirigera_hub.get_outlets()The outlet object has the following attributes (additional to the core attributes):is_on:boolstartup_on_off:Optional[StartupEnum]=NoneAvailable methods for outlet are:outlet.set_name(name="kitchen socket 1")outlet.set_on(outlet_on=True)outlet.set_startup_behaviour(behaviour=StartupEnum.START_OFF)Controlling Air PurifierTo get information about the available air purifiers, you can use theget_air_purifiers()method:air_purifiers=dirigera_hub.get_air_purifiers()The air purifier object has the following attributes (additional to the core attributes):fan_mode:FanModeEnumfan_mode_sequence:strmotor_state:intchild_lock:boolstatus_light:boolmotor_runtime:intfilter_alarm_status:boolfilter_elapsed_time:intfilter_lifetime:intcurrent_p_m25:intAvailable methods for blinds are:air_purifier.set_name(name="living room purifier")air_purifier.set_fan_mode(fan_mode=FanModeEnum.AUTO)air_purifier.set_motor_state(motor_state=42)air_purifier.set_child_lock(child_lock=True)air_purifier.set_status_light(light_state=False)Controlling BlindsTo get information about the available blinds, you can use theget_blinds()method:blinds=dirigera_hub.get_blinds()The blind object has the following attributes (additional to the core attributes):blinds_current_level:Optional[int]=Noneblinds_target_level:Optional[int]=Noneblinds_state:Optional[str]=NoneAvailable methods for blinds are:blind.set_name(name="kitchen blind 1")blind.set_target_level(target_level=90)Remote ControllersCurrently only tested with the STYRBAR remote.To get information about the available controllers, you can use theget_controllers()method:controllers=dirigera_hub.get_controllers()The controller object has the following attributes (additional to the core attributes):is_on:boolbattery_percentage:Optional[int]=NoneAvailable methods for controller are:controller.set_name(name="kitchen remote 1")Environment SensorCurrently only tested with the VINDSTYRKA sensor. If you have other sensors please send me the json and I will add support or create a PR.To get the environment sensors use:sensors=dirigera_hub.get_environment_sensors()The environment sensor object has the following attributes (additional to the core attributes):current_temperature:floatcurrent_r_h:int# current humiditycurrent_p_m25:int# current particulate matter 2.5max_measured_p_m25:int# maximum measurable particulate matter 2.5min_measured_p_m25:int# minimum measurable particulate matter 2.5voc_index:int# current volatile organic compoundAvailable methods for environment sensor are:sensor.set_name(name="Bathroom Sensor")SceneTo get the scenes use:scenes=dirigera_hub.get_scenes()The scene object has the following attributes:id:strtype:strinfo:Infotriggers:List[Trigger]actions:List[Action]created_at:datetime.datetimelast_completed:datetime.datetimelast_triggered:datetime.datetimelast_undo:datetime.datetimecommands:List[str]undo_allowed_duration:intDetails to the Trigger, Action and Info class can be found inscene.pyAvailable methods for scene are:scene.trigger()scene.undo()Motion SensorTo get information about the available motion sensors, you can use theget_motion_sensors()method:motions_sensors=dirigera_hub.get_motion_sensors()The motion sensor object has the following attributes (additional to the core attributes):battery_percentage:intis_on:boollight_level:Optional[float]Available methods for outlet are:motions_sensor.set_name(name="kitchen sensor 1")Open Close SensorTo get information about the available open/close sensors, you can use theget_open_close_sensors()method:open_close_sensors=dirigera_hub.get_open_close_sensors()The open_close_sensor object has the following attributes (additional to the core attributes):is_open:boolAvailable methods for outlet are:open_close_sensor.set_name(name="window 1")Event ListenerThe event listener allows you to listen to events that are published by your Dirigera hub. This is useful if you want to automate tasks based on events such as when a light is turned on or off, or when the color temperature of a light is changed.importjsonfromtypingimportAnydefon_message(ws:Any,message:str):message_dict=json.loads(message)data=message_dict["data"]ifdata["id"]==bed_light.light_id:print(f"{message_dict['type']}event on{bed_light.custom_name}, attributes:{data['attributes']}")defon_error(ws:Any,message:str):print(message)dirigera_hub.create_event_listener(on_message=on_message,on_error=on_error)deviceStateChanged event on Bed Light, attributes: {'isOn': False}MotivationThe primary motivation for this project was to provide users with the ability to control the startup behavior of their smart home lamps when there is a power outage.The default behavior of the hub is to turn on all lights when power is restored, which can be problematic if the user is away from home or on vacation, and a small power fluctuation causes all lights to turn on and stay on. Unfortunately, the IKEA app does not offer a way to change this default behavior.Theset_startup_behaviour()function enables users to override the default behavior and choose the startup behavior that best suits their needs (START_ON = turn on light when power is back, START_OFF = light stays off when power is back).I can not guarantee that all IKEA lamps offer this functionality.ContributingContributions are welcome! If you have an idea for a new feature or a bug fix, please post and issue or submit a pull request.Setup of devFor setting up the dev environment I recommend running thesetup.shscript, which will create a venv and install therequirements.txtas well as thedev-requirements.txt.TestsTo run the tests execute therun-test.shscript or just runpytest .For linting you can run therun-pylint.sh.For types you can run therun-mypy.shTo test the different python versions you can use therun-python-verions-test.sh(this requires a running docker installation).All of these tests are also run when a PR is openend (and the test run is triggered).LicenseThe MIT License (MIT)Copyright (c) 2023 Leggin