Window mechanism (Vektiva Smarwi) MQTT help needed

Hi,

I have Vektiva Smarwi window opening mechanism which is working greatly for more than 1 year and I’m controling it via HTTP command. Problem with HTTP curl post command is that is slow, and also you do not have the best feedback status. So I decided to migrate to MQTT protocol - So, I figerout that Vektiva Smarwi also support MQTT (more in down configuration screenshots) but I do not know how to define MQTT so that it will work as normal switch. For additional security I have also Zigbee Xiaomi sensor so that I am 100% sure that window is closed/opened.

HTTP command for opening / closing:

# VEKTIVA Smarwi - 192.168.3.106 - Podstrešno okno
  - platform: command_line
    switches:
      vektiva_smarwi_switch:
        command_on: "/usr/bin/curl -X POST http://192.168.3.106/cmd/open"
        command_off: "/usr/bin/curl -X POST http://192.168.3.106/cmd/close"
        friendly_name: Podstrešno okno

image

So, I make new switch based on MQTT protocol, but it’s not working.

# VEKTIVA Smarwi - 192.168.3.106 - Podstrešno okno
  - platform: mqtt
    name: "Podstrešno okno (mqtt)"
    state_topic: "ion/mqtt/%60019449682a/status"
    command_topic: "ion/mqtt/%60019449682a/cmd"
    availability_topic: "ion/mqtt/%60019449682a"
    qos: 1
    payload_on: "open;100"
    payload_off: "close;100"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Vektiva SMARWI configuration:
image
image
image

The complete documentation for MQTT protocol is online here:
https://vektiva.gitlab.io/vektivadocs/en/api/mqtt.html

So, can anybody help me how to define switch correctly with this documentation…

I tested via Developer tools and it’s working (opening, closing) but, on switch I have problems.

image

My data for MQTT:
Device ID:
60019449682a
User:
mqtt

Command for opening:
ion/mqtt/%60019449682a/cmd -m “open;100”

Command for closing:
ion/mqtt/%60019449682a/cmd -m “close;100”

But for Developer tools I used withouth “-m” and it was working.

Thank you for you help…

So, can anybody help me to define the correct MQTT switch?

What errors do you see in the log when you try your defined switch ?

Otherwise, if you can define a binary_sensor which indicates open (on) or closed (off), you can try a template switch

  - platform: template
    switches:
      podstresno_oknok:
        value_template: "{{ is_state('binary_sensor.my_binary_sensor', 'on') }}"
        turn_on:
          - service: mqtt.publish
            data:
              payload: 'open;100'
              topic:'ion/mqtt/%60019449682a/cmd'
        turn_off:
          - service: mqtt.publish
            data:
              payload: 'close;100'
              topic: 'ion/mqtt/%60019449682a/cmd'

I do not get any errors…
Just that MQTT is not “online”. In log file there is nothing about that…
image

The problem is in switch configuration:

# VEKTIVA Smarwi - 192.168.3.106 - Podstrešno okno
  - platform: mqtt
    name: "Podstrešno okno (mqtt)"
    state_topic: "ion/mqtt/%60019449682a/status"
    command_topic: "ion/mqtt/%60019449682a/cmd"
    availability_topic: "ion/mqtt/%60019449682a"
    qos: 1
    payload_on: "open;100"
    payload_off: "close;100"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

So, I did not configure something correctly, because even icon is not correct, it should be as for switch for tasmota…
image

So, maybe I do not understand instructions on vektiva online site correctly…

Then there is something wrong with the connection between your mqtt broker and HA. How did you install your mqtt broker ?

My MQTT broker is OK, I have another 39 tasmota sensors and switches and all is working fine…
Also device is normally open and close via developer tools (screenshot)…
The only problem is that I do not know how to correctly define MQTT switch because I’m noob regarding that…

The problem with trying to do it the ‘Tasmota’ way is the state_topic, it does not return a value or json but a list of key:value strings.

OK… Yes… I was using the “Tasmota” way… So, is there any other way withouth use of binary_sensor?

This way we can do it…

  - platform: template
    switches:
      podstresno_oknok:
        value_template: "{{ is_state('binary_sensor.my_binary_sensor', 'on') }}"
        turn_on:
          - service: mqtt.publish
            data:
              payload: 'open;100'
              topic:'ion/mqtt/%60019449682a/cmd'
        turn_off:
          - service: mqtt.publish
            data:
              payload: 'close;100'
              topic: 'ion/mqtt/%60019449682a/cmd'

but rather then use some binary sensor we would read status via mqtt of device it’self…

We know, that we can get position from:
“ion/mqtt/%60019449682a/#”

open:
pos:o
closed:
pos:c

So why not to use this instead of binary sensor? How to use it? How to set as switch buttton (not lighting symbol)?

You can probably define your binary sensor as this :

  - platform: mqtt
    name:my_binary_sensor
    state_topic: 'ion/mqtt/%60019449682a/status'
    value_template: >- 
      {% if  'pos:c' in value %}   
        {{'OFF'}}
      {% else %}
        {{'ON'}}
      {% endif %}

Tested with this jinja2 template :

Imitate available variables:
{% set my_test_json = "t:swr
     s:200
     e:0
     ok:1
     ro:0
     pos:c
     fix:0
     a:0
     fw:203.2.1
     mem:19928
     up:259284714
     ip:285870602
     cid:BedroomWindow
     rssi:-63
     time:1523292002"
%}

{{ 'pos:c' in my_test_json }}


2 Likes

Great… It’s working… Thank you for providing solution… With that I can also manage that in case of any error I can add another binary sensor with window status (OK / NOT OK aka something is wrong).

My final configuration:

Binary sensor:

  - platform: mqtt
    name: Podstrešno okno (stanje)
    state_topic: 'ion/mqtt/%60019449682a/status'
    value_template: >- 
      {% if  'pos:c' in value %}   
        {{'OFF'}}
      {% else %}
        {{'ON'}}
      {% endif %}

Switch:

  - platform: template
    switches:
      vektiva_smarwi_podstresno_okno:
        friendly_name: "Podstrešno okno"
        value_template: "{{ is_state('binary_sensor.podstresno_okno_stanje', 'on') }}"
        turn_on:
          - service: mqtt.publish
            data:
              payload: 'open;100'
              topic: 'ion/mqtt/%60019449682a/cmd'
        turn_off:
          - service: mqtt.publish
            data:
              payload: 'close;100'
              topic: 'ion/mqtt/%60019449682a/cmd'

image

Also, I have backup Xiaomi sensor on window, so that I am 100% sure that sensor status is 100% correct.

image

Video which show how this is working…

I tried suggested config and it didn’t work for me
after playing with it I came up with
sensor:

- platform: mqtt
  name: window_playroom
  state_topic: 'ion/<USER>/%<DEVICE_ID>/status'
  value_template: >-
    {% if  'pos:c' in value %}
      {{'OFF'}}
    {% else %}
      {{'ON'}}
    {% endif %}

and switch:

- platform: template
  switches:
    smarwi_playroom:
      unique_id: window_playroom_switch
      friendly_name: "Окно (Детская)"
      value_template: "{{ is_state('sensor.window_playroom', 'ON') }}"
      icon_template: >-
        {% if is_state('sensor.window_playroom', 'ON') %}
          mdi:window-open
        {% else %}
          mdi:window-closed
        {% endif %}
      turn_on:
        - service: mqtt.publish
          data:
            payload: 'open;100'
            topic: 'ion/<USER>/%<DEVICE_ID>/cmd'
      turn_off:
        - service: mqtt.publish
          data:
            payload: 'close;100'
            topic: 'ion/<USER>/%<DEVICE_ID>/cmd'

And now it’s working.

I wonder if there is a way to make it percent selectable

1 Like

Found a way, there is a custom integration of smarwi available for home assistant, which supports percentage - GitHub - cvrky/vektiva_smarwi_ha

It also support proper HomeKit integration (as a window, as opposed to blinds or a switch) when using home assistant as HomeKit bridge

I also followed HACS integration way. After installation I see “Vektiva Smartwi” in Integrations, but there is no ovbious way how to configure it…

Can you give me some hint, please?

How did you configure your Vektiva device?

Just go to integrations,
click add integration,
select “Vektiva Smarwi”
and fill in IP address

I’ve created a custom Home Assistant integration for SMARWI that allows you to fully control SMARWI via a local MQTT broker. It’s much more advanced than cvrky/vektiva_smarwi_ha, easier to install and set up.

Supported features: open, close, stop, open to position, fix/release the ridge, report if the ridge is inside the device, and change finetune settings.

1 Like