Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT Cover - Tilt command template is ignored #63024

Closed
Webbeh opened this issue Dec 29, 2021 · 8 comments · Fixed by #63080
Closed

MQTT Cover - Tilt command template is ignored #63024

Webbeh opened this issue Dec 29, 2021 · 8 comments · Fixed by #63080
Assignees

Comments

@Webbeh
Copy link

Webbeh commented Dec 29, 2021

The problem

Trying to communicate with a MQTT cover actuator that supports JSON commands, I am having trouble with the "tilt" command.

The device supports payloads of this sort :

{
  "motion": 0
  "position": 50,
  "lamella": 50
}

Motion = 0 : stop
Motion = 1 : up
Motion = 2 : down

Position : send position in percent
Lamella : send tilt in percent

You can send one or more objects in the json, but you don't have to.

What does work :

  • Position in percent
  • Open / Close commands for position
  • Tilt in percent
  • Status for both tilt and position

Actuating the blinds up or down, and to a certain position works well. The tilt open/close commands are the issue. Whatever I do in the config, HASS seems to completely ignore the tilt_command_template option that I provide it, and keeps sending 100 for tilt up, and 0 for tilt down.

I also tried to change the value of tilt_opened_value and tilt_closed_value to the JSON that I want, but HASS complains that MQTT.Cover only supports integers.

What version of Home Assistant Core has the issue?

core-2021.12.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

MQTT Cover

Link to integration documentation on our website

https://www.home-assistant.io/integrations/cover.mqtt/#tilt_command_template

Example YAML snippet

cover:
  - platform: mqtt
    unique_id: "mqtt_dingz_livingroom_shutters_sw"
    name: "Shutters"
    device:
      manufacturer: "Dingz"
      model: "dz1f-4b"
      identifiers: "F008D1C3B068"
    device_class: "blind"
    enabled_by_default: true
    availability:
      topic: "dingz/F008D1C3B068/online"
      payload_available: "true"
      payload_not_available: "false"
    command_topic: "dingz/F008D1C3B068/dz1f-4b/command/motor/0"
    state_topic: "dingz/F008D1C3B068/dz1f-4b/state/motor/0/movement"
    position_topic: "dingz/F008D1C3B068/dz1f-4b/state/motor/0"
    set_position_topic: "dingz/F008D1C3B068/dz1f-4b/command/motor/0"
    position_template: "{{ value_json.position }}"
    set_position_template: '{"position": {{ position }} }'
    tilt_status_topic: "dingz/F008D1C3B068/dz1f-4b/state/motor/0"
    tilt_status_template: "{{ value_json.lamella }}"
    tilt_command_topic: "dingz/F008D1C3B068/dz1f-4b/command/motor/0"
    tilt_command_template: >
      {
        "lamella": {{ tilt_position }}
      }
    qos: 2
    position_open: 100
    position_closed: 0
    payload_open: '{"motion":1}'
    payload_close: '{"motion":2}'
    payload_stop: '{"motion":0}'

Anything in the logs that might be useful for us?

Nothing in the logs.

Additional information

I keep receiving "100" or "0" in MQTT.

image

The status works fine, it's just the TILT commands that don't work.

@probot-home-assistant
Copy link

mqtt documentation
mqtt source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @emontnemery, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@jbouwh
Copy link
Contributor

jbouwh commented Dec 30, 2021

It seems your tilt_command_template works fine. Did you test the service call?

afbeelding

afbeelding

The Home Assistant Community forum is the place to ash for further if needed.

@Webbeh
Copy link
Author

Webbeh commented Dec 30, 2021

Actuating the blinds up or down, and to a certain position works well. The tilt open/close commands are the issue. Whatever I do in the config, HASS seems to completely ignore the tilt_command_template option that I provide it, and keeps sending 100 for tilt up, and 0 for tilt down.

I also tried to change the value of tilt_opened_value and tilt_closed_value to the JSON that I want, but HASS complains that MQTT.Cover only supports integers.

image

Green works.
Red doesn't.

@jbouwh
Copy link
Contributor

jbouwh commented Dec 30, 2021

Right, the buttons result in different service calls, and a command_template is not applied. I am preparing a fix.

@Webbeh
Copy link
Author

Webbeh commented Dec 30, 2021

I would be okay if we could just send any kind of payload with tilt_opened_value and tilt_closed_value, if that makes the fix easier.

@jbouwh
Copy link
Contributor

jbouwh commented Dec 30, 2021

The linked PR should fix the issues you are having now.

@Webbeh
Copy link
Author

Webbeh commented Dec 30, 2021

Hmm, my HASS isn't 100% up to date, cover.py doesn't import MqttCommandTemplate.

I adapted it a little and it does the trick.

    async def async_open_cover_tilt(self, **kwargs):
        """Tilt the cover open."""
        template = self._config.get(CONF_TILT_COMMAND_TEMPLATE)
        tilt_open_position = self._config[CONF_TILT_OPEN_POSITION]
        variables = {
            "tilt_position": tilt_open_position,
            "entity_id": self.entity_id,
            "position_open": self._config.get(CONF_POSITION_OPEN),
            "position_closed": self._config.get(CONF_POSITION_CLOSED),
            "tilt_min": self._config.get(CONF_TILT_MIN),
            "tilt_max": self._config.get(CONF_TILT_MAX),
        }
        tilt_payload = tilt_open_position
        if template is not None:
            tilt_payload = template.async_render(parse_result=False, variables=variables)
        await mqtt.async_publish(
            self.hass,
            self._config.get(CONF_TILT_COMMAND_TOPIC),
            tilt_payload,
            self._config[CONF_QOS],
            self._config[CONF_RETAIN],
        )
        if self._tilt_optimistic:
            self._tilt_value = self.find_percentage_in_range(
                float(self._config[CONF_TILT_OPEN_POSITION])
            )
            self.async_write_ha_state()

    async def async_close_cover_tilt(self, **kwargs):
        """Tilt the cover closed."""
        template = self._config.get(CONF_TILT_COMMAND_TEMPLATE)
        tilt_closed_position = self._config[CONF_TILT_CLOSED_POSITION]
        variables = {
            "tilt_position": tilt_closed_position,
            "entity_id": self.entity_id,
            "position_open": self._config.get(CONF_POSITION_OPEN),
            "position_closed": self._config.get(CONF_POSITION_CLOSED),
            "tilt_min": self._config.get(CONF_TILT_MIN),
            "tilt_max": self._config.get(CONF_TILT_MAX),
        }
        tilt_payload = tilt_closed_position
        if template is not None:
            tilt_payload = template.async_render(parse_result=False, variables=variables)
        await mqtt.async_publish(
            self.hass,
            self._config.get(CONF_TILT_COMMAND_TOPIC),
            tilt_payload,
            self._config[CONF_QOS],
            self._config[CONF_RETAIN],
        )
        if self._tilt_optimistic:
            self._tilt_value = self.find_percentage_in_range(
                float(self._config[CONF_TILT_CLOSED_POSITION])
            )
            self.async_write_ha_state()

@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants