jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Use switching actuators as switches instead of lights #141

Closed EnricoBilla closed 1 year ago

EnricoBilla commented 1 year ago

Hi all! This closes #120 .

I added the possibility to configure a switching actuator as a switch instead of a light by defining its serial and channel in the configuration:

freeathome:
  host: !secret fah_host
  username: !secret fah_user
  password: !secret fah_password
  configure_as_switch:
   - ABB50000ABCD/ch0001
   - ABB500ABCDEF/ch0000

For now it's kind of an hack, I think it would be best having some way to retrieve this information from the sysap but I couldn't find anything. Please try it and let me know what do you think.

Note that if the configure_as_switch parameter is not defined the behaviour is the same as before.

Ruko2010 commented 8 months ago

@EnricoBilla if I see it correctly, your code was never merged. How can I use it? Do I just have to Update the files manually? If so, what happens, if an Update is rolled out? Is your code then "gone" and I have to implement it again? Thanks for the help.

EnricoBilla commented 8 months ago

@Ruko2010 Yes, you are correct. You just need to download the files from my repo, the downside is that I didn't keep it updated from this repo and probably you are going to miss some features. If there's some interest in merging this feature I'm willing to reopen this PR

Ruko2010 commented 8 months ago

Maybe we wait for a reaction from @jheling why it was not merged in the first place. Maybe he'll merge it now.

derjoerg commented 8 months ago

I can only repeat what I already written in #168 The cleaner approach would be to have the F@H-integration report all switch actuators as switches in HA and let the user create the necessary helpers (device-as-x) to correctly build their home Just my 2 cents

EnricoBilla commented 8 months ago

@derjoerg I didn't know it was a possibility to use switch-as-x when I first wrote those lines of code, moreover it was meant to solve a issue of mine. I opened this PR when I saw there was some interest.

Now if we want to build a cleaner solution I totally agree with you that the HA way of doing things is to use switch-as-x, it's important to underline that this will be a HUGE retrocompatibility issue.

derjoerg commented 8 months ago

@EnricoBilla I'm 100% on the same page as you the switch-as-x should (!!!) be the way to go, but I don't know if it is worth the effort to introduce such a breaking change

Ruko2010 commented 8 months ago

Maybe someone could fork and implement this "switch-as-x" Version 😬

EnricoBilla commented 8 months ago

@Ruko2010 done in #169 😉

constancyGmbH commented 8 months ago

ok, I'll test your code....just for curiosity. I already installed this version of the integration. Can I just deinstall it and install your integration? Do I need to add the serial numbers of the BuschJäger Actors before installing, or after? Do you know what will happen to the devices already synct with Apple Homekit?

EnricoBilla commented 8 months ago

Yes, of course you can deinstall the old one and reinstall the new one. If you stop and restart the HA instance in the meanwhile, you shouldn't have to reconfigure it in HA. As for Homekit I don't know since I've never used it.

Ruko2010 commented 8 months ago

ok thank you. I'll give it a shot.

Ruko2010 commented 8 months ago

@EnricoBilla I'll delete the integration by jheling, and installed yours, but getting the following error after installation "No Devices or Entities found" image

Ruko2010 commented 8 months ago

I'll see the following Error in the Logs:

ERROR (MainThread) [homeassistant.config_entries] Error setting up entry 192.168.10.103 for freeathome
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/freeathome/__init__.py", line 76, in async_setup_entry
    sysap.configure_as_switch = entry.data[CONF_CONFIGURE_AS_SWITCH]
                                ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'configure_as_switch'
2023-11-02 21:22:42.571 WARNING (MainThread) [custom_components.freeathome.fah.pfreeathome] Connection with SysAP lost
2023-11-02 21:22:43.665 ERROR (MainThread) [homeassistant] Error doing job: Task was destroyed but it is pending!
2023-11-02 21:24:38.170 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry 192.168.10.103 for freeathome
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/freeathome/__init__.py", line 76, in async_setup_entry
    sysap.configure_as_switch = entry.data[CONF_CONFIGURE_AS_SWITCH]
                                ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'configure_as_switch'

I added the following to my configuration.yaml of HA:

freeathome:
  host: !secret fah_host
  username: !secret fah_user
  password: !secret fah_password
  use_room_names: true
  configure_as_switch:
   - ABB284CD4351/ch0000
Ruko2010 commented 8 months ago

@EnricoBilla BTW, where can I see the Channel Number of my Actor? I know the Serial from the Busch Jäger App, but I don't know where to get the Channel from.

Ruko2010 commented 8 months ago

@EnricoBilla I got it running. I saw the problem. If I add your Repo to HACS as Custom Repo, it always adds the master branch, not the branch from the URL I specified. So I logged into the HA via SSH and copied the files from the switch-as-x branch. Now it is working. I now changed the switches to lights and it's working perfectly. Thanks a lot!

EnricoBilla commented 8 months ago

@Ruko2010 Thanks! It's nice to know it's working fine for you. Do you have any dimmable devices? If yes please test them and report back in the PR!

Ruko2010 commented 7 months ago

@EnricoBilla yes, we have some dimmable lamps that were correctly discovered as lamps in the first place without necessary changes of the type.

EnricoBilla commented 7 months ago

That's perfect, thanks!