jheling / freeathome

Free@Home component for Home Assistant
114 stars 41 forks source link

support for dali devices #182

Open jheling opened 8 months ago

jheling commented 8 months ago

Add extra function_id's

cweyer commented 7 months ago

First of all, a big thank you for great work here! It is really appreciated.

I downloaded and installed this branch via git as a custom component in my Home Assistant setup and ran it. Unfortunately the DALI controlled lights do not show up. I assume this is because lights are entities which are exposed by a device. For my regular lights those devices are named like Sensor/ Schaltaktor 8/8fach, REG and in turn expose the lights connected to them as entities. I was wondering if the same must be done with DALI? So the DALI controller is exposed in HA as a device which in turn exposes the lights as it's entities. Otherwise there would be no hierarchy path to the lights themselves? I hope this answer makes sense, I am pretty new to HA and haven't wrapped my head around all the concepts yet, but since all my other lights don't show up directly but through their device I was wondering if the same must be done with the DALI controller?

jheling commented 7 months ago

Yes, the dali controller should appear as a device and the controlled lights (channels) should appear as entities. I assume you don't see any errors in Settings/System/Logs?

Could you adjust the logging level in your configuration.yaml like this? :

logger:
  default: warning
  logs:
    custom_components.freeathome: info

This should show more information in the log about the available entities.

cweyer commented 7 months ago

Ah okay, since I didn't see any code related to that I assumed it was omitted.

Anyhow, this might be helpful (I renamed the integration freeathome-dev to be able to run the stable version and branch on the same system)

Looks like the return value for self.rgb_color is not an integer

2024-04-05 17:03:51.100 ERROR (MainThread) [homeassistant.components.light] Error while setting up freeathome-dev platform for light
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/freeathome-development/light.py", line 23, in async_setup_entry
async_add_devices([FreeAtHomeLight(device_object)])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/freeathome-development/light.py", line 63, in __init__
self._rgb_color = self.light_device.get_rgb_color()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/freeathome-development/fah/devices/fah_light.py", line 164, in get_rgb_color
blue = self.rgb_color & 255
~~~~~~~~~~~~~~~^~~~~
TypeError: unsupported operand type(s) for &: 'str' and 'int'
2024-04-05 17:03:56.439 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch0013/idp0007 = 0
2024-04-05 17:03:56.439 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch0013/idp000A = 65
2024-04-05 17:03:56.439 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch008B/idp0007 = 0
2024-04-05 17:03:56.440 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch008B/idp000A = 65
2024-04-05 17:03:56.440 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch00B9/idp0000 = 0
2024-04-05 17:03:56.440 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch00B9/odp0009 = 65
2024-04-05 17:03:56.440 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] FahThermostat Wohnzimmer: received datapoint 807A7F04E8CD/ch00B9/odp0009 = 65
2024-04-05 17:03:56.440 INFO (MainThread) [custom_components.freeathome-development.fah.devices.fah_thermostat] thermostat Wohnzimmer (807A7F04E8CD/ch00B9) dp odp0009 ecomode 65
2024-04-05 17:03:56.440 DEBUG (MainThread) [custom_components.freeathome-development.fah.pfreeathome] received datapoint 807A7F04E8CD/ch00B9/odp000A = 0
cweyer commented 7 months ago

Ok, so typecasting it to int worked, now it shows up. I can control on/off and brightness (with a bit strange feedback though), but not colour. The colour map is all black and selecting a colour brings up this error message:

Screenshot 2024-04-05 at 17 22 25

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2542, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2579, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 631, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/freeathome-development/light.py", line 152, in async_turn_on
    self.rgb_color = kwargs[ATTR_RGB_COLOR]
    ^^^^^^^^^^^^^^
AttributeError: property 'rgb_color' of 'FreeAtHomeLight' object has no setter```
jheling commented 7 months ago

Hello, I have made some changes to light.py. Hope it now works better.

jheling commented 7 months ago

@cweyer, Did you have time to test it with the changes i made?

cweyer commented 7 months ago

@cweyer, Did you have time to test it with the changes i made?

Unfortunately I was pretty busy in the last couple of days, but I will be able to test it some time next week, sorry for the delay.

cweyer commented 6 months ago

Sorry for getting back just now, I had a lot of work the last couple of weeks.

So I applied your patches and there seems to be a wrongly named method, it's calling is_rgb_colour but there is only a is_rgb method. Also, since this patch, it only discovers one of my 4 DALI entities.

Screenshot 2024-05-12 at 20 53 28

(Sorry for the screenshot, the web UI terminal doesn't allow me to copy text)

jheling commented 2 months ago

@cweyer . Can you try the latest changes? Another user has tested the white-tone adjustable lights and they seem to be working.

cweyer commented 2 months ago

Sure, will install the branch tomorrow evening

cweyer commented 2 months ago

I tried the latest commit from the jhe/dali branch, but it won't boot the integration:

Logger: homeassistant.config_entries
Source: config_entries.py:604
First occurred: 20:03:58 (2 occurrences)
Last logged: 20:10:53

Error setting up entry 192.168.2.160 for freeathome
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/freeathome/__init__.py", line 84, in async_setup_entry
    await sysap.find_devices()
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 954, in find_devices
    await self.xmpp.find_devices(self._use_room_names, self._switch_as_x)
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 836, in find_devices
    await self.update_devices(config, initializing=True)
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 534, in update_devices
    monitoring_device.update_datapoint(datapoint_id, value.text)
  File "/config/custom_components/freeathome/fah/devices/fah_light.py", line 195, in update_datapoint
    self.color_temp = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '12.1569'

It could be a remnant from a previous attempt, so tomorrow I will fiddle around with the registry and delete all DALI entities and see if it boots up then. Unfortunately my configuration is rather complex and removing the add-on and reinstalling it is not an option, otherwise I would have to reassign 64 devices to different rooms again.

jheling commented 2 months ago

Yes, this seems to be a white tone adjustable light and the value should be max one byte. I first thought it was a rgb value (3 bytes).