Cover Tilt Position - negative values

Hello community,
I have the issue that my window covers with Somfy motors (integrated through Homekit and Velux Gateway) is working on a range from -100 to 100 (states in HomeAssistant developer tools)

current_tilt_position: -100

The problem I have is that HomeAssistent does not accept in automation negative values.

Failed to call service cover.set_cover_tilt_position. value must be at least 0 for dictionary value @ data[‘tilt_position’]. Got None

Can I translate in the integration “number * 2 - 100” to get numbers from -100 to 100 instead of 0 to 100?

Would be really great if I could close the venetian blinds fully through HomeAssistant …

Thanks Samuel

I think the formula would be like this:

{% set value = -45 %}
{{ (value + 100) / 2 }}

This is a direct mapping of -100 to 100 onto the 0 to 100 numerical space. You can create a sensor to do this.

Just for my own reference, wondering if the numeric_state takes negative numbers,
Anyone know before I try?

Hi @AllHailJ
thanks, but the issue is not the template. Sorry for the misunderstanding.

The issue is that when I send “0” to the ‘cover.set_cover_tilt_position’ service the device needs to receive -100, but with your proposal or below the service refuses values below 0.

Any other idea?

Samuel

cover:
  - platform: template
    covers:         
      vanta_buro:
        unique_id: vanta_buro
        friendly_name: Vanta Buro
        device_class: blind
        position_template: >
          {{ state_attr('cover.vanta_buro_venetian_blinds', 'current_position')|int }}
        set_cover_position:
          service: cover.set_cover_position
          data_template:
            entity_id: cover.vanta_buro_venetian_blinds
            position: >
              {{ position }}
        tilt_template: >
          {{ state_attr('cover.vanta_buro_venetian_blinds', 'current_tilt_position')|int / 2 + 100 }}  
        set_cover_tilt_position:
          service: cover.set_cover_tilt_position
          data_template:
            entity_id: cover.vanta_buro_venetian_blinds
            tilt_position: >
              {{ tilt * 2 - 100 }} 

Hi @Demusman ,
Numeric Helpers take negative numbers. What was your thought?

Regards,
Samuel

It may depend on the Integration. My thinking (based on how MQTT covers works) is that somewhere along the way, the integration needs to tell HA what the min tilt position (-100) and max tilt position (+100) are and HA translates this to a percentage 0 to 100%, and when the service call is made, it inverse translates this percentage to an absolute value (between -100 and +100).

Are you saying that when a call is made to the service with tilt position of 0 (%) and this does not move the tilt to -100? If not then it is probably worth reporting as a bug against that integration.

You could create a helper that represents the % closed 0-100 as an input_number (helper) in HA. Then with the use of the template feature, you set the number to send to Somfy.

See templating here: Template - Home Assistant

#--------------------------------------------------------------------------------------------------
# Take an input number which represents % closed and map it to Somfy number Space
#--------------------------------------------------------------------------------------------------
template:
  - sensor:
    - name: "Closed Percent for Somfy"
      unique_id: "Closed Percent for Somfy"
      state: >
        {% set closed = states('input_number.percent_closed') | int(0) %}
        {{ closed * 2 - 100}}

Your entity would be sensor.closed_percent_for_somfy

can you take a screenshot of the attributes in developer tools → states page for the entity in question?

@petro

Here a sample of the current state:

Hi @AllHailJ
the issue is not presenting the good number in HomeAssistant, but sending a negative value to the service which get refused.

All make sense to me except that the Somfy is reporting and requiring negative values. I assume the issue is maybe with HomeKit integration.

Regards,
Samuel

I was curious and took a glance at the homekit integration code, and for tilt, I see the following comments for both updates from Homekit and sending to Homekit:

        # HomeKit sends values between -90 and 90.                                     
        # We'll have to normalize to [0,100] 

I’m not 100% sure, but the code seems to have tilt value operate within HA as values between 0 and 100 so it converts this to -90 and +90 when operating directly with Homekit. So again at a glance, since HA is showing a current_tilt_position that is negative, it would appear that Homekit, in this case via VeluxGateway and Somfy may actually operate on values that break this -90/+90 assumption. It would be hard to tell for sure without debug logs but I don’t see a debug log statement in the tilt position update part of the code.

Anyway, I would raise the issue on GitHub just to see what the developers may think about this.

This is a great hint. I’ll try to debug and maybe raise an issue in GitHub.
THANKS !!!

It seams to be the issue with the homekit integration:

When controlling tilt on the Velux, I see the proper values:

2024-04-07 10:31:26.563 DEBUG (MainThread) [aiohomekit.controller.abstract] callback ev:{(15, 14): {'value': 90}}
2024-04-07 10:31:26.563 DEBUG (MainThread) [homeassistant.components.homekit_controller.connection] Called async_set_available_state with True for 94:B9:D5:7C:56:A0
2024-04-07 10:31:32.762 DEBUG (MainThread) [aiohomekit.controller.abstract] callback ev:{(2, 13): {'value': 60.0}}
2024-04-07 10:31:32.762 DEBUG (MainThread) [homeassistant.components.homekit_controller.connection] Called async_set_available_state with True for 94:B9:D5:7C:56:A0
2024-04-07 10:31:32.765 DEBUG (MainThread) [aiohomekit.controller.abstract] callback ev:{(15, 14): {'value': -90}}

When sending tilt from HomeAssistant 100 => 90:

2024-04-07 10:33:58.063 DEBUG (MainThread) [aiohomekit.controller.ip.connection] 192.168.0.164: raw request: b'PUT /characteristics HTTP/1.1\r\nHost: 192.168.0.164\r\nContent-Length: 52\r\nContent-Type: application/hap+json\r\n\r\n{"characteristics":[{"aid":15,"iid":14,"value":90}]}'

When sending tilt from HomeAssistant 0 => 0 instead of -90:

2024-04-07 10:34:01.711 DEBUG (MainThread) [aiohomekit.controller.ip.connection] 192.168.0.164: raw request: b'PUT /characteristics HTTP/1.1\r\nHost: 192.168.0.164\r\nContent-Length: 51\r\nContent-Type: application/hap+json\r\n\r\n{"characteristics":[{"aid":15,"iid":14,"value":0}]}'

Will open a defect on GitHub.

Thanks again.