Page 1 of 1

How to link a script to a device?

Posted: Sunday 11 March 2018 20:54
by WoJWoJ
Hello everyone!

I am new to Domoticz (and to home automation in general) but the platform seems to be incredible.

I connected a (previously flashed) Sonoff WiFi switch and it works great. I also wrote a Python script to publish messages on Mosquitto.

What I am trying to understand (among "hardware", "devices" and "scenes") is how to link both. I would like to run my script, which would send a message to a topic, be intercepted by domoticz, which would in turn toggle the switch.

The parts which are extremely confusing for me are:
  • how to declare in domoticz my script (as "hardware", "device"?) - or the topic the script will be publishing to
  • how to listen to the topic and act upon it by toggling the switch (which is defined as "switch"of type "light switch")
I am sure I am missing just a bit so I would be grateful for any pointer (including some kind of tutorial for dummies, if such exists)

Thanks!

Re: How to link a script to a device?

Posted: Sunday 11 March 2018 21:55
by waaren
welcome WoJWoJ,
I am not sure I completely understand what you want to achieve. But my guess is that you would be helped with

http://www.domoticz.com/DomoticzManual.pdf
especial the part about virtual devices

https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

and

https://www.domoticz.com/wiki/DzVents:_ ... _scripting

Re: How to link a script to a device?

Posted: Monday 12 March 2018 20:39
by WoJWoJ
waaren wrote: Sunday 11 March 2018 21:55 I am not sure I completely understand what you want to achieve.
Thank you for the links, after reading them I understand more what I wanted to ask.

I realized that domoticz is just one of the possible clients for MQTT and that I will probbaly use it as an intermediate to contact my devices.

For instance I have a WiFi switch which I could
  • contact directly via its built-in API
  • switch by sending a message to the MQTT broker (in my case - mosquitto), to a topic it is subscribed to
  • use domoticz's API
Since there is no polling of the switch state, I will go through the third solution so that teh status in domoticz is up to date.

Now: I also have "devices" on my own, like an internet radio based on a RPi I built. It has today an API I can query to switch it on and off. I could change my code to instead use MQTT (the radio would subscribe to a topic and run from there). I would probably like to connect it to domoticz so that I can run some scenarios (say - a light sensor senses that the sun is up and switches the radio, something I believe I can program via the LUA scripting built into domoticz).

Should I look at setting it us as a switch (possibly with a nicer icon) or is there a special way to add such new devices?

Re: How to link a script to a device?

Posted: Monday 12 March 2018 21:32
by waaren
I am by no means a specialist on this but in the case you describe I would define the radio in domoticz as a virtual device with the current API calls in the "on action" and "off action" fields of the device.
testradio.PNG
testradio.PNG (37.14 KiB) Viewed 2064 times