Start HA script from Domoticz

Hi Guys, I’m pretty new to Home Assistant, but have been using Domoticz for quite some time now.
I am in the process of getting familiar with HA, and I’m thinking of switching to HA in the future.

Now I don’t like the idea of a “Big Bang”, so I was thinking of combining my two systems. So I can slowly set things over to HA.

Now there is the challenge. I already have some scripts in HA, to start a Spotify playlist. So I like to start this script, under specific conditions that are configured in Domoticz. So in short: I want a Domotiz event that activates my HA script.

What would be the best way to do that? I read something about MQTT, but I’m not sure what that is and how it works. Hope you guys can help me out!

I have a feeling that MQTT is more complicated than necessary, because I don’t have the need to transfer any data at this point. All I want to do is activate a script that I made in HASS, triggered by a Domoticz event.

I’d check here, you should be able to instantiate a script via API:

For your purposes, using MQTT should be straightforward. Set up the internal broker by adding mqtt: to the top level of your configuration .yaml The documentation is here

Write an automation triggered by an automation. See here
https://home-assistant.io/docs/automation/trigger/#mqtt-trigger

The action of the automation should call your script, the example is here
https://home-assistant.io/docs/configuration/group_visibility/#the-complete-example

To test this, I would use a phone app or a command line tool like mosquitto_pub to send mqtt messages that trigger the event. You could also turn on mqtt logging to check that you are receiving messages

Then all you have to do is figure out how to send that message in Domoticz.

I set up MQTT in HASS en Domoticz. But I don’t know what kind of mqtt message I have to send to get my script started.

There is only one kind of MQTT message, it has a topic and payload, both of which are text.

What you put in them is entirely up to you, but it has to be what triggers your script.

Thanks for all your patience so far.

So I installed mosquitto_pub on my Raspbery PI running Domoticz.
On HASS I added the following to my automations.yaml:

trigger:
platform: mqtt
topic: test
action:
service: script.spotifyplaylist

I gues I have to run something like:
mosquitto_pub -h 10.0.0.24 -t test -m ???

But I am not sure what I have to type at parameter -m.

EDIT: The reply doesn’t show the spaces of my config. but I did use the right spaces.

Still sturggling with this. I did a different approach, I made a mqtt switch, this is a part of my configuration.yaml

mqtt:

switch:

  • platform: mqtt
    command_topic: “home-assistant/switch/music”

I installed mosquitto client, and run this command:
mosquitto_pub -h localhost -t ‘home-assistant/switch/music’ -m ‘ON’

But the switch doesn’t go ON.

Ok so I got a little further. I found out that by using the inernatl broker (with only adding mqtt: to the config and nothing else). you have to give username (homeassistant) and password (api password). But even with that it is not working.

For testing purpose I used the public broker (test.mosquitto.org). That does work.

Unless you copy the error messages you get in to your post, nobody can really help.

Since you have mosquitto clients installed, you can try

mosquitto_sub -v -t "#" -u username -P password

which will connect to the broker on the local machine and print out all the messages the broker receives.

Hi, I did not get any errors. I ended up with installing the broker on my other raspberry pi, the one that’s running Domoticz. Now it works fine.