Page 1 of 1

Trying to ON/OFF device through shell command in Domoticz

Posted: Sunday 17 June 2018 14:19
by marafado88
Hello,

I have recently installed for the first time Domoticz, and I am trying to turn on/off a Xiaomi Air Purifier 2, where I am already able to read and send commands through OS shell (debian 8), and now I am trying to add a switch botton on Domoticz to execute those commands on Domoticz GUI, but I am a bit lost on it.

The commands that I am trying to set for now are:

Code: Select all

python3.6 MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696' --power ON
python3.6 MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696' --power OFF
And I have add a dummy hardware and then a sensor device, where there I was able to add a switch, on action and off action options, seems like I have to add a direct path for a script in each action :?: .

How can I accomplish this without having to create a script for each command?

Thanks!

Re: Trying to ON/OFF device through shell command in Domoticz

Posted: Monday 18 June 2018 1:00
by marafado88
I have tried to add an event through GUI for when there is a change in switch state, but dont know if its well 'pointed' to GUI ON/OFF that I have created:

Code: Select all

local sensor = 'ON/OFF'

commandArray = {}

if devicechanged['sensor'] == 'On' then
    os.execute ("python3.6 MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696 --power ON")
else
    os.execute ("python3.6 MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696 --power OFF")
end

return commandArray
In GUI I have set,

http://prntscr.com/jw2uxy
http://prntscr.com/jw2us6

But no sucess after tried on/off from GUI.

I believe that this can be a simple thing but since I have never done it before, or found a more well explained tutorial, I have already run out of ideas in how to accomplish this. :( :cry:

Re: Trying to ON/OFF device through shell command in Domoticz

Posted: Monday 18 June 2018 1:34
by marafado88
Finally(!) I was able to turn it on and off :o

There was a missing ' after my xiaomi token in switch:

On action:

Code: Select all

script:///usr/local/bin/python3.6 /home/root/domoticz/scripts/python/MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696' --power ON
Off action:

Code: Select all

script:///usr/local/bin/python3.6 /home/root/domoticz/scripts/python/MyAir.py '192.168.1.81' 'e7cad3a10ea385ee2b9ce3c55f9e2696' --power OFF