How to link a script to a device?

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
WoJWoJ
Posts: 2
Joined: Sunday 11 March 2018 17:02
Target OS: Linux
Domoticz version:
Contact:

How to link a script to a device?

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to link a script to a device?

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
WoJWoJ
Posts: 2
Joined: Sunday 11 March 2018 17:02
Target OS: Linux
Domoticz version:
Contact:

Re: How to link a script to a device?

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to link a script to a device?

Post 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 2062 times
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests