Announcing MQTT/Android bridging app: Zanzito. Beta testers wanted!

No, I would use “Luce soggiorno” as voice cmd, then you can say:

  1. just “Luce soggiorno”: the configured activity payload is sent (in your case ‘off’)
  2. “Luce soggiorno on”: the payload “on” is sent
  3. “Luce soggiorno off”: the payload “off” is sent
  4. "Luce soggiorno " …

Then you automate HA according to the received payload…

but is not natural, I prefer to use a more natural language, and of course all the variants

accendi la luce del soggiorno
accendi luce soggiorno
accendi le luci del soggiorno
illumina il soggiorno
and so on

having the possibility to put multiple voice commands in the same activity, you could achieve that

The problem here, among others, is that what is “natural” in a language is not in another…
With vocal commands in Zanzito you have four parts:

  1. An introductory word, in the manual I suggest “Please” but it can be anything not too short
    Note that here you can say whatever you want, as long as you don’t pause too long
  2. Keyword: when spotted, the whole phrase is analyzed
    Again between the keyword and the command you can say anything you want
  3. Activity vocal command: it triggers a specific activity.
  4. Immediately after the vocal command, if “Get payload from vocal command” is selected, anything you say is sent as payload.

I guess we could have multiple vocal commands for each activity, but wouldn’t it be like emptying the ocean with a spoon? I mean, natural language recognition hasn’t been achieved neither from Apple (or Google)…

But, as usual, I’m open to suggestions…

There is someone who did something like this for tracking voice:

You would say something like, “Please turn the lights on” or “Ey dude turn the lights”

And the script would pick “turn”, “lights” and “on” and would execute the function. I am not sure if this is possible here but it is an idea at least

Here is how I attempted to control every switches in the house using 2 activities in zanzito and 1 automation in HA.

In Zanzito…

Activity #1

Name: Turn on
Topic: %devicename%/switch/turn_on
Payload: (empty)
Voice cmd: turn on
Tick Get payload from vocal command

Activity #2

Name: Turn off
Topic: %devicename%/switch/turn_off
Payload: (empty)
Voice cmd: turn off
Tick Get payload from vocal command

In HA automation…

- alias: 'MQTT Switch'
  trigger:
    platform: mqtt
    topic: myphone/switch/#
  action:
    - service_template: >
        homeassistant.{{ trigger.topic.split('/')[-1] }}
      data_template:
        entity_id: >-
          {% set payload = {{trigger.payload}} %}

          {%- if payload == 'dining' -%}
            group.dining_lights_fan

          {%- elif payload == 'kitchen lights' or payload == 'kitchen light' -%}
            group.kitchen_lights

          {%- elif payload == 'play room' or payload == 'playroom' -%}
            group.playroom

          {%- elif payload == 'living room lights' -%}
            group.livingroom_lights

          {%- elif payload == 'everything' -%}
            group.all_items

          {%- elif payload == 'staircase lights' -%}
            group.staircase_1_lights

          {%- elif payload == 'bedroom lights' -%}
            group.masterbedroom_all_lights

          {%- elif payload == 'bedroom' -%}
            group.masterbedroom_all_switches

          {%- elif payload == 'office fans' -%}
            group.office_all_fans

          {%- elif payload == 'office' -%}
            group.office_all_switches

          {% endif %}

The problem with this is I cannot have a response when it was successful (“OK”) or unsuccessful (“Sorry, device not found”).

I know it is a long shot. But thanks for looking into it.

As last elif you could trigger an input_boolean associated to another automation, that in turn would trigger a “Not found” response and reset the input_boolean…

a born programmer :wink:

1 Like

I thought about that. but what about device is successfully controlled and I want say “OK”

that is harder… Maybe have groups only for vocal commands, and trigger a response everytime they change state?

EDIT: I think you could include your original groups in other groups, is that possible with HA?

If I understand correctly, I would be switching on/off groups only right? I think that would be a lot of modification to my configuration.

Anyway, the best solution I can come up with right now is…

before {% endif %}, add…

         {%- else -%}
            script.mqtt_switch_not_found

and then add this below the first action…

    - condition: state
      entity_id: input_boolean.mqtt_switch_not_found
      state: 'off'
    - service: mqtt.publish
      data_template:
        topic: >-
          zanzito/{{ trigger.topic.split('/')[-3] }}/notification
        payload: >-
          {% set responses = [
          "OK",
          "Sure",
          "If you insist",
          "Done",
          "Alright",
          "No worries",
          "I can do that",
          "Leave it to me",
          "Consider it done",
          "As you wish",
          "By your command",
          "Affirmative",
          "No Problem"
          ] %}
          {% set rindex =  (range(0, (responses | length - 1) )|random) -%}
          {{responses[rindex]}}

then create a script…

mqtt_switch_not_found:
  sequence:
    - service: mqtt.publish
      data:
         topic: zanzito/myphone/notification
         payload: "I'm sorry. I cannot find the device named XXXXX in your house."
    - service: input_boolean.turn_on
      entity_id: input_boolean.mqtt_switch_not_found
    - delay:
        seconds: 2
    - service: input_boolean.turn_off
      entity_id: input_boolean.mqtt_switch_not_found

The problem is I cannot pass the payload to the script so that it can read out XXXXX

Maybe a new bug.

In android smartphone (in landscape mode) , when I click on ACTIVITY, then press on + … it crashes
in android box, when I click on ACTIVITY, the press on + it emits a sound and goes back. My Android box it does not work (all programs) portrait

I submitted a report at 20.36

1 Like

Yeah. @MrMep knows about it. I am also waiting for a fix.

wanted to try my android box, which is default landscape, and not sure where to change it.

EDIT
Other problem of android box, is not recognizing the MIC of the Jabra 510 ggrrr

Tomorrow I should be able to release a fix.

1 Like

Question: who is a Tasker and Zanzito user among you guys? What kind of integration would you like?
I was thinking of exposing Activities and Reports from Zanzito to Tasker, what do you think?

Thanks for your prompt responses and suggestions.

This happened with only one CA certificate in the “User” segment. I did not have any certificates installed prior to setting up Owntracks (which I did yesterday). I believe the Owntracks instructions said to install the certificate to the device and then also specify the path within Owntracks. The latter option is missing in Zanzito.

Is there a way to see from the logs which certificates are being used?

My mosquitto version is 1.4.11 which I believe is the latest.

Changing ports is not a real option, and not at all relevant for this problem.

How can i set port for home host? My primary host is cloudmqtt with 19400 port. And when i try connect in my local network connection is refused. My local mqtt broker listen on 1883 port.

Are you by any chance trying to authenticate with a client certificate or configured mosquitto to require client certificate authentication? Because this isn’t supported by Zanzito.
The error you reported from mosquitto seems related to the client (not) authenticating to the server, not the contrary (not Zanzito verifying the authenticity of the server’s certificate), but I might be wrong or it could be the byproduct of another problem.

The error in Zanzito might to be related to one of the following cases:

The CA that issued the server certificate was unknown
The server certificate wasn’t signed by a CA, but was self signed
The server configuration is missing an intermediate CA

Normally, the first two are solved by manually importing the CA certificate in Android: Zanzito doesn’t handle this, it’s a request to the system.

The third one could be of interest, it depends on how you generated the certificates, try googling a little bit. I don’t think it’s a problem in Zanzito because Zanzito actually doesn’t do anything with the certificates, it relies on the system.
Maybe Owntracks can overcome a possible problem by manually managing the certificates, but first we should understand what the problem is (this is the first time such an issue was signaled to me)

EDIT: I did some digging: by importing the CA certificate directly, Owntracks bypasses a few alerts (mainly, one of the three cases above) that instead Android issues. Even if yours is the only case so far, I added the implementation of a similar feature to my todo list, have patience.
In the meanwhile you could experiment by re-issuing your certificates with alternate methods: for example, I don’t know if you already tried the method sketched here.

In Zanzito, the port number is common to both hosts. I think you can easily setup a second listener in your local broker with the same port as your public one.