jheling / freeathome

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

Window-Sensor #184

Closed LSchuetzi84 closed 2 months ago

LSchuetzi84 commented 7 months ago

I have several window sensors that are mounted directly on the window handle. These indicate whether the window is closed / open / tilted. These are not displayed. Example:

<attribute name="displayName">Fenster/Tür - kl. Fenster</attribute>
     <attribute name="floor">01</attribute>
     <attribute name="functionId">4b</attribute>
     <attribute name="room">01</attribute>

freeathome_dump_192.168.178.25_2024_04_17_20_38_04.xml.zip

jheling commented 7 months ago

Thank you for the dump, this will help a lot.

etiennelenhart commented 4 months ago

@jheling Are there any plans to support window sensors in the future?

jheling commented 4 months ago

@etiennelenhart . Yes, making a it a binary sensor should be easy. Only the tilt is a bit a challenge. I found some examples where is was implemented with two binary sensors. One for open /closed and one for tilted.

etiennelenhart commented 4 months ago

Oh, so there is no direct support for these kinds of sensors in Home Assistant?

FWIW I would be fine with a binary state for now, as I'm currently only using the opened state.

oliverlinsenmaier commented 3 months ago

I would also like to receive this functionality in HA -> I would also test it...

jheling commented 3 months ago

The solution turned out to be very simple. I have only implemented the binary part. You can try #198

oliverlinsenmaier commented 2 months ago

@jheling: I can confirm, that the actuators now work. But it was there before, wasn't it?! And this Issue is more about the sensors, not the actuators.

etiennelenhart commented 2 months ago

@jheling With the newest update I‘m getting a binary sensor for the window sensor‘s state, but not the window_position attribute. Is this not implemented yet?

oliverlinsenmaier commented 2 months ago

@Tho85 Can you help us adding the window position to the current main version? We only have the status "Open" or "Closed", not "Tilted".

jheling commented 2 months ago

@etiennelenhart. The code for the window_position is included but it does not seem to work. Can you change the logging for the integration to info? Maybe the format of the data that is sent by free@home is a bit different than expected. With this extended logging you should see the update messages coming free@home.

logger:
  default: warning
  logs:
    custom_components.freeathome: info
etiennelenhart commented 2 months ago

@jheling I think these should be the relevant lines (I included the DEBUG level logs for good measure):

DEBUG (MainThread) [custom_components.freeathome.fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 1
DEBUG (MainThread) [custom_components.freeathome.fah.pfreeathome] FahBinarySensor Terrassentür Wohnzimmer: received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 1
INFO (MainThread) [custom_components.freeathome.fah.devices.fah_binary_sensor] binary sensor Terrassentür Wohnzimmer (ABB7FXXXXXXX/ch0001) dp odp0000 state 1
INFO (MainThread) [custom_components.freeathome.binary_sensor] update sensor
jheling commented 2 months ago

@etiennelenhart Thank you, can you give me the sensor values for the three states? So open, tilted and closed? The current code is testing on these values:

        if self.binary_device.window_position == '0':
            attributes["window_position"] = "closed"
        elif self.binary_device.window_position == '33':
            attributes["window_position"] = "tilted"
        elif self.binary_device.window_position == '100':
            attributes["window_position"] = "open"
etiennelenhart commented 2 months ago

From what I can tell the sensor values seem to match:

# closed -> open
22:02:13.675 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 1
22:02:13.675 DEBUG [fah.pfreeathome] FahBinarySensor Terrassentür Wohnzimmer: received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 1
22:02:13.676 INFO [fah.devices.fah_binary_sensor] binary sensor Terrassentür Wohnzimmer (ABB7FXXXXXXX/ch0001) dp odp0000 state 1
22:02:13.676 INFO [binary_sensor] update sensor
22:02:14.724 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0001 = 100

# open -> tilted
22:02:26.911 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0001 = 33

# tilted -> closed
22:02:45.370 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0001 = 100
22:02:46.359 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 0
22:02:46.359 DEBUG [fah.pfreeathome] FahBinarySensor Terrassentür Wohnzimmer: received datapoint ABB7FXXXXXXX/ch0001/odp0000 = 0
22:02:46.360 INFO [fah.devices.fah_binary_sensor] binary sensor Terrassentür Wohnzimmer (ABB7FXXXXXXX/ch0001) dp odp0000 state 0
22:02:46.360 DEBUG [fah.pfreeathome] received datapoint ABB7FXXXXXXX/ch0001/odp0001 = 0
22:02:46.360 INFO [binary_sensor] update sensor

What stands out to me is the additional sensor value 1, the two consecutive datapoints for 0, and the missing update sensor calls for values 100 and 33. I guess free@home sends values for both sensor ranges simultaneously? 0 & 1 for closed & open (includes tilted) as well as 0, 100 & 33 for closed, tilted & open.

Since it looks like the values match, maybe they are not processed correctly? You can see that the actual logs indicating a received datapoint for FahBinarySensor only appear for values 1 and 0.

jheling commented 2 months ago

@etiennelenhart. I think i have found the problem. Can you add 'PID_WINDOW_DOOR_POSITION' to line 56 in the source fah_binary_sensor.py? It should look like this:

                        PID_FORCE_POSITION_BLIND,
                        PID_WINDOW_DOOR,
                        PID_WINDOW_DOOR_POSITION,
                        PID_SWITCHOVER_HEATING_COOLING,
etiennelenhart commented 2 months ago

Yes! It works. 🎉 The entity correctly shows an attribute for window_position that switches between closed, open, and tilted.

jheling commented 2 months ago

@etiennelenhart Thanks! The debug logging was very usefull.

oliverlinsenmaier commented 2 months ago

Confirmed the fix: grafik