How to create a custom Homematic IP entity to work properly in Apple Homekit

Hi all together,
I’m new to Home Assistant and coming from a combination of Homebridge and IoBroker. I want to replace them and make Home Assistant my central middleware for all my smart home accessories. In my home I’m using Homematic IP for the blinds (HMIPW-DRBL4), the garage door and temperature sensors, Philips Hue for lighting, Doorbird and Unify Protect for the doorbell and cameras.

I set up Home Assistant (on a NUC as operating system) with HACS and homematic_custom which is connected to my RaspberryMatic. All devices and entities from Homematic are available in Home Assistant. The covers are working in Home Assistant, but when I make them available in Homekit they do not work as expected. This is mainly because the integration does not use the COMBINED_PARAMETER of Homematic but sets the position and tilt-positions of the blinds as single values. This is very bad implemented in the DRBL4, a workaround is to use the COMBINED_PARAMETER of that Homematic device to set both similarily.

In IoBroker I found a script which does a custom mapping of the values from Homematic to Homekit and back. This works good for me but is the only reason for me to have IoBroker. The script does mainly following:

The blinds are implemented as covers, so they just have a open and close button and a position slider. They do NOT implement a second tilt slider. When the blinds are opened the COMBINDED_PARAMETER is set to L=100,L2=0. When they are closed its L=0,L2=0. The same is done respectively when the position slider is between 0 and 20 (close), or 80 and 100 (open). Only when the position is set between 21 and 79 the COMBINED_PARAMETER is L=0,L2=50, which keeps the blinds closed but opens the tilts by 50% so that light comes in. In our home we only need this three states for the blinds. In Homekit this works good.

How can I achieve this with Home Assistant. I played around with templates but I don’t come through it. Unfortunately it seems that nobody else has implemented the DRBL4 in a custom entity for that. It would be really nice if you could help me to get this working and to help me to streamline my setup to just Home Assistant.

Thanks a lot in advance!

There are two relevant services that integrations and templates can use:

Both have only one parameter (besides entity_id) to set a position.

As long as there is no HA service that accepts both position parameters (cover height and tilt) the usage of the COMBINED_PARAMETER is not relevant.

One thing i missed is that your DRBL4 channnels are only available as cover.

  1. Reconfigure these channels in CCU as blinds.
  2. Use service homematicip_local.clear_cache
  3. Restart HA

These channels should now be availabe as blinds with additional controls for the tilt.

Thanks for your replies. The problem is that the implementation of the DRBL4 blinds in Home Assistant do not use that COMBINED_PARAMETER of Homematic. When using that blinds in Homekit they are not usable because to get them working properly both values (position and tilt) need to be set. Otherwise for example when opening the blinds they went ab bit down and don’t close complete.

This is what I found out so far. The open, close and stopping is working. What I want now is that the “position” is used for the L2 value of the COMBINED_PARAMETER (at first, later I will bring in some conditions here).

My problem is that I want to use the Value of the current_position in my Template but I do not know how to achieve this. This is my code, the “set_cover_position” is not working. How can I use the position value of the entity here to set the right command to homematic?

    covers:
      jalousie_wohnzimmer:
        device_class: shutter
        friendly_name: "Jalousie Wohnzimmer"
        open_cover:
          - service: homematicip_local.set_device_value
            data:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: L=100,L2=100
        close_cover:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: L=0,L2=0
        stop_cover:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: STOP
              value: true
        set_cover_position:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: L=0,L2="{{ position }}"

Thanks a lot in advance!

Again: There is no service in HA for cover entities that accepts both parameters in one call to the use of COMBINED_PARAMETER is not relevant.

Maybe this discussion is helpful

Hello SukramJ,
thank you for your reply. That’s true and this is the reason why I want to create a custom entity that I can use in Homekit.

Can you maybe help me with the template I want to create for this special solution? How can I use the current_position in the template to set_cover_position?

There is an example in the previous posts link.
The cover entity has an attribute current_position that can be used.

{{ state_attr(‘cover.bad_sued’, ‘current_position’) }}

Do you have the second slider for tilt position now at your cover entities?

Hi,
yes, sorry I think that I wrote that a bit confusing. The Homematic IP (local) implementation in Home Assistant works fine and I also have all covers with both position and tilt sliders.

My plan is to create a second cover entity with limited possibilities and to use them in Homekit. Here I want to use the position slider (and no tilt slider in Homekit, just the position) to control different states for the cover. 0-20 % = close, 21-79% = tilt 50%, 80-100% = open.

OK, that sounds better.

So, this is where I came out right now. It works, also in Homekit, but some things are not perfect at the moment. Maybe anybody can help me here a bit?

  • How can I bring the “device_id” in something like a variable (because I have 11 covers in my home)
  • How can I change the position to the value I prefer. For example when I change it to 47% it stays at that value. It would be better to set every value between 20 and 79 to 50 %.
  • When I change it in Homekit it works, but also the position value could be "re"set to 0, 50 or 100 (even when it is between).
  - platform: template
    covers:
      jalousie_wohnzimmer:
        device_class: shutter
        friendly_name: "Jalousie Wohnzimmer"
        open_cover:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: L=100,L2=100
        close_cover:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: L=0,L2=0
        stop_cover:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: STOP
              value: true
        set_cover_position:
          - service: homematicip_local.set_device_value
            data_template:
              device_id: 123455
              channel: 6
              parameter: COMBINED_PARAMETER
              value: >
                 {% if position == none %}
                  L=0,L2=0
                 {% elif position | int > 80 %}
                  L=100,L2=100
                 {% elif position | int >=20 and position | int < 80 %}
                 {% set position = 40 | int %}
                  L=0,L2=40
                 {% else %}
                  L=0,L2=0
                 {% endif %}